// timer.cc -- helper class for time accounting
-// Copyright 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2009-2019 Free Software Foundation, Inc.
// Written by Rafael Avila de Espindola <espindola@google.com>.
// This file is part of gold.
#include "gold.h"
+#include <unistd.h>
+
#ifdef HAVE_TIMES
#include <sys/times.h>
#endif
this->start_time_.sys = 0;
}
-// Start couting the time.
+// Start counting the time.
void
-Timer::start ()
+Timer::start()
{
this->get_time(&this->start_time_);
}
+// Record the time used by pass N (0 <= N <= 2).
+void
+Timer::stamp(int n)
+{
+ gold_assert(n >= 0 && n <= 2);
+ TimeStats& thispass = this->pass_times_[n];
+ this->get_time(&thispass);
+}
+
#if HAVE_SYSCONF && defined _SC_CLK_TCK
# define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
#else
# endif
#endif
-// times returns statistics in clock_t units. This variable will hold the
-// conversion factor to seconds. We use a variable that is initialize once
+// times returns statistics in clock_t units. This variable will hold the
+// conversion factor to seconds. We use a variable that is initialized once
// because sysconf can be slow.
static long ticks_per_sec;
class Timer_init
};
Timer_init timer_init;
-// Write the current time infortamion.
+// Write the current time information.
void
-Timer::get_time (TimeStats *now)
+Timer::get_time(TimeStats *now)
{
#ifdef HAVE_TIMES
tms t;
// Return the stats since start was called.
Timer::TimeStats
-Timer::get_elapsed_time ()
+Timer::get_elapsed_time()
{
TimeStats now;
this->get_time(&now);
return delta;
}
+// Return the stats for pass N (0 <= N <= 2).
+Timer::TimeStats
+Timer::get_pass_time(int n)
+{
+ gold_assert(n >= 0 && n <= 2);
+ TimeStats thispass = this->pass_times_[n];
+ TimeStats& lastpass = n > 0 ? this->pass_times_[n-1] : this->start_time_;
+ thispass.wall -= lastpass.wall;
+ thispass.user -= lastpass.user;
+ thispass.sys -= lastpass.sys;
+ return thispass;
+}
+
}