* gold.cc: Include timer.h.
authorCary Coutant <ccoutant@google.com>
Tue, 18 Oct 2011 00:06:10 +0000 (00:06 +0000)
committerCary Coutant <ccoutant@google.com>
Tue, 18 Oct 2011 00:06:10 +0000 (00:06 +0000)
(queue_middle_tasks): Stamp time.
(queue_final_tasks): Likewise.
* main.cc (main): Store timer in parameters.  Print timers
for each pass.
* parameters.cc (Parameters::Parameters): Initialize timer_.
(Parameters::set_timer): New function.
(set_parameters_timer): New function.
* parameters.h (Parameters::set_timer): New function.
(Parameters::timer): New function.
(Parameters::timer_): New data member.
(set_parameters_timer): New function.
* timer.cc (Timer::stamp): New function.
(Timer::get_pass_time): New function.
* timer.h (Timer::stamp): New function.
(Timer::get_pass_time): New function.
(Timer::pass_times_): New data member.

gold/ChangeLog
gold/gold.cc
gold/main.cc
gold/parameters.cc
gold/parameters.h
gold/timer.cc
gold/timer.h

index 391f015d4f71b6a41d16dc8e034422e41b97cc77..f5ef533813def5cdfc2ed345423dc810a4afd367 100644 (file)
@@ -1,3 +1,23 @@
+2011-10-17  Cary Coutant  <ccoutant@google.com>
+
+       * gold.cc: Include timer.h.
+       (queue_middle_tasks): Stamp time.
+       (queue_final_tasks): Likewise.
+       * main.cc (main): Store timer in parameters.  Print timers
+       for each pass.
+       * parameters.cc (Parameters::Parameters): Initialize timer_.
+       (Parameters::set_timer): New function.
+       (set_parameters_timer): New function.
+       * parameters.h (Parameters::set_timer): New function.
+       (Parameters::timer): New function.
+       (Parameters::timer_): New data member.
+       (set_parameters_timer): New function.
+       * timer.cc (Timer::stamp): New function.
+       (Timer::get_pass_time): New function.
+       * timer.h (Timer::stamp): New function.
+       (Timer::get_pass_time): New function.
+       (Timer::pass_times_): New data member.
+
 2011-10-17  Cary Coutant  <ccoutant@google.com>
 
        * readsyms.cc (Read_symbols::run): Don't queue an unblocker
index 2700bdb5ef67a61bf156b7698f92e994b4dee1da..f455ec8a4121142dfade4c8ca677f88423e675ec 100644 (file)
@@ -45,6 +45,7 @@
 #include "gc.h"
 #include "icf.h"
 #include "incremental.h"
+#include "timer.h"
 
 namespace gold
 {
@@ -487,6 +488,10 @@ queue_middle_tasks(const General_options& options,
                   Workqueue* workqueue,
                   Mapfile* mapfile)
 {
+  Timer* timer = parameters->timer();
+  if (timer != NULL)
+    timer->stamp(0);
+
   // Add any symbols named with -u options to the symbol table.
   symtab->add_undefined_symbols_from_command_line(layout);
 
@@ -786,6 +791,10 @@ queue_final_tasks(const General_options& options,
                  Workqueue* workqueue,
                  Output_file* of)
 {
+  Timer* timer = parameters->timer();
+  if (timer != NULL)
+    timer->stamp(1);
+
   int thread_count = options.thread_count_final();
   if (thread_count == 0)
     thread_count = std::max(2, input_objects->number_of_input_objects());
index f6e7609eefb3bbd1119a0b88c8f5721e144416ad..048454186f8393e84baab1576c40669da2d06c77 100644 (file)
@@ -165,7 +165,10 @@ main(int argc, char** argv)
 
   Timer timer;
   if (command_line.options().stats())
-    timer.start();
+    {
+      timer.start();
+      set_parameters_timer(&timer);
+    }
 
   // Store some options in the globally accessible parameters.
   set_parameters_options(&command_line.options());
@@ -252,7 +255,32 @@ main(int argc, char** argv)
 
   if (command_line.options().stats())
     {
-      Timer::TimeStats elapsed = timer.get_elapsed_time();
+      timer.stamp(2);
+      Timer::TimeStats elapsed = timer.get_pass_time(0);
+      fprintf(stderr,
+             _("%s: initial tasks run time: " \
+               "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)\n"),
+              program_name,
+              elapsed.user / 1000, (elapsed.user % 1000) * 1000,
+              elapsed.sys / 1000, (elapsed.sys % 1000) * 1000,
+              elapsed.wall / 1000, (elapsed.wall % 1000) * 1000);
+      elapsed = timer.get_pass_time(1);
+      fprintf(stderr,
+             _("%s: middle tasks run time: " \
+               "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)\n"),
+              program_name,
+              elapsed.user / 1000, (elapsed.user % 1000) * 1000,
+              elapsed.sys / 1000, (elapsed.sys % 1000) * 1000,
+              elapsed.wall / 1000, (elapsed.wall % 1000) * 1000);
+      elapsed = timer.get_pass_time(2);
+      fprintf(stderr,
+             _("%s: final tasks run time: " \
+               "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)\n"),
+              program_name,
+              elapsed.user / 1000, (elapsed.user % 1000) * 1000,
+              elapsed.sys / 1000, (elapsed.sys % 1000) * 1000,
+              elapsed.wall / 1000, (elapsed.wall % 1000) * 1000);
+      elapsed = timer.get_elapsed_time();
       fprintf(stderr,
              _("%s: total run time: " \
                "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)\n"),
index c14bd1e8266072bcfafc2e5d6af2e6447a2fb685..7fc5730ee732134382ed61a8afa6f73855dddcc4 100644 (file)
@@ -64,7 +64,7 @@ Set_parameters_target_once set_parameters_target_once(&static_parameters);
 // Class Parameters.
 
 Parameters::Parameters()
-   : errors_(NULL), options_(NULL), target_(NULL),
+   : errors_(NULL), timer_(NULL), options_(NULL), target_(NULL),
      doing_static_link_valid_(false), doing_static_link_(false),
      debug_(0), incremental_mode_(General_options::INCREMENTAL_OFF),
      set_parameters_target_once_(&set_parameters_target_once)
@@ -78,6 +78,13 @@ Parameters::set_errors(Errors* errors)
   this->errors_ = errors;
 }
 
+void
+Parameters::set_timer(Timer* timer)
+{
+  gold_assert(this->timer_ == NULL);
+  this->timer_ = timer;
+}
+
 void
 Parameters::set_options(const General_options* options)
 {
@@ -269,6 +276,10 @@ void
 set_parameters_errors(Errors* errors)
 { static_parameters.set_errors(errors); }
 
+void
+set_parameters_timer(Timer* timer)
+{ static_parameters.set_timer(timer); }
+
 void
 set_parameters_options(const General_options* options)
 { static_parameters.set_options(options); }
index 09b0516b782576edc745773a6a2c91ac1784da49..10de2ae7fa4f828a00acf872b80e21c610b88c19 100644 (file)
@@ -28,6 +28,7 @@ namespace gold
 
 class General_options;
 class Errors;
+class Timer;
 class Target;
 template<int size, bool big_endian>
 class Sized_target;
@@ -56,6 +57,9 @@ class Parameters
   void
   set_errors(Errors* errors);
 
+  void
+  set_timer(Timer* timer);
+
   void
   set_options(const General_options* options);
 
@@ -70,6 +74,11 @@ class Parameters
   errors() const
   { return this->errors_; }
 
+  // Return the timer object.
+  Timer*
+  timer() const
+  { return this->timer_; }
+
   // Whether the options are valid.  This should not normally be
   // called, but it is needed by gold_exit.
   bool
@@ -177,6 +186,7 @@ class Parameters
   friend class Set_parameters_target_once;
 
   Errors* errors_;
+  Timer* timer_;
   const General_options* options_;
   Target* target_;
   bool doing_static_link_valid_;
@@ -195,6 +205,9 @@ extern const Parameters* parameters;
 extern void
 set_parameters_errors(Errors* errors);
 
+extern void
+set_parameters_timer(Timer* timer);
+
 extern void
 set_parameters_options(const General_options* options);
 
index d9b8874a59c3cff4c8538d8fc1449d68512abd62..1423663281a5cc92365aaab5129080ffc44a7ccb 100644 (file)
@@ -49,6 +49,15 @@ 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
@@ -106,4 +115,17 @@ Timer::get_elapsed_time()
   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;
+}
+
 }
index 50b55e49dd0802b5238b191cc06b8570b99a6942..4f986ca11e2c45f0823ef0e4eda48378590633fb 100644 (file)
@@ -48,10 +48,18 @@ class Timer
   TimeStats
   get_elapsed_time();
 
+  // Return the stats for pass N (0 <= N <= 2).
+  TimeStats
+  get_pass_time(int n);
+
   // Start counting the time.
   void
   start();
 
+  // Record the time used by pass N (0 <= N <= 2).
+  void
+  stamp(int n);
+
  private:
   // This class cannot be copied.
   Timer(const Timer&);
@@ -63,6 +71,9 @@ class Timer
 
   // The time of the last call to start.
   TimeStats start_time_;
+
+  // Times for each pass.
+  TimeStats pass_times_[3];
 };
 
 }
This page took 0.035362 seconds and 4 git commands to generate.