This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Report wall time in addition to cpu time.


Hi.

It is often useful to see both cpu and wall time in the output of
"maint time 1".

I will check this in in a couple of days if there are no objections.

2011-09-19  Doug Evans  <dje@google.com>

	* utils.c (cmd_stats): Rename start_time to start_cpu_time.
	New member start_wall_time.
	(report_command_stats): Report wall time in addition to cpu time.
	(make_command_stats_cleanup): Record current wall time.

Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.261
diff -u -p -r1.261 utils.c
--- utils.c	9 Sep 2011 19:41:14 -0000	1.261
+++ utils.c	19 Sep 2011 19:34:12 -0000
@@ -641,7 +641,8 @@ static int display_space;
 struct cmd_stats 
 {
   int msg_type;
-  long start_time;
+  struct timeval start_wall_time;
+  long start_cpu_time;
   long start_space;
 };
 
@@ -673,12 +674,26 @@ report_command_stats (void *arg)
 
   if (display_time)
     {
-      long cmd_time = get_run_time () - start_stats->start_time;
+      long cmd_time = get_run_time () - start_stats->start_cpu_time;
+      struct timeval now_wall_time, delta_wall_time;
+
+      gettimeofday (&now_wall_time, NULL);
+      delta_wall_time.tv_sec =
+	now_wall_time.tv_sec - start_stats->start_wall_time.tv_sec;
+      delta_wall_time.tv_usec =
+	now_wall_time.tv_usec - start_stats->start_wall_time.tv_usec;
+      /* Carry(/borrow)?  */
+      if (delta_wall_time.tv_sec < 0)
+	{
+	  delta_wall_time.tv_sec -= 1;
+	  delta_wall_time.tv_usec += 1000000;
+	}
 
       printf_unfiltered (msg_type == 0
-			 ? _("Startup time: %ld.%06ld\n")
-			 : _("Command execution time: %ld.%06ld\n"),
-			 cmd_time / 1000000, cmd_time % 1000000);
+			 ? _("Startup time: %ld.%06ld (cpu), %ld.%06ld (wall)\n")
+			 : _("Command execution time: %ld.%06ld (cpu), %ld.%06ld (wall)\n"),
+			 cmd_time / 1000000, cmd_time % 1000000,
+			 delta_wall_time.tv_sec, delta_wall_time.tv_usec);
     }
 
   if (display_space)
@@ -714,7 +729,8 @@ make_command_stats_cleanup (int msg_type
 #endif
 
   new_stat->msg_type = msg_type;
-  new_stat->start_time = get_run_time ();
+  gettimeofday (&new_stat->start_wall_time, NULL);
+  new_stat->start_cpu_time = get_run_time ();
 
   return make_cleanup_dtor (report_command_stats, new_stat, xfree);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]