Add timestamps to "maint time" output
[deliverable/binutils-gdb.git] / gdb / maint.c
index 328d6026a341c95798d295f786812b279e7e3c98..aaabb3522497550e057f1141164890eeca7c14cd 100644 (file)
@@ -794,6 +794,8 @@ scoped_command_stats::~scoped_command_stats ()
 
   if (m_time_enabled && per_command_time)
     {
+      print_time (_("command finished"));
+
       using namespace std::chrono;
 
       run_time_clock::duration cmd_time
@@ -867,6 +869,9 @@ scoped_command_stats::scoped_command_stats (bool msg_type)
       m_start_cpu_time = run_time_clock::now ();
       m_start_wall_time = steady_clock::now ();
       m_time_enabled = 1;
+
+      if (per_command_time)
+       print_time (_("command started"));
     }
   else
     m_time_enabled = 0;
@@ -888,6 +893,26 @@ scoped_command_stats::scoped_command_stats (bool msg_type)
   reset_prompt_for_continue_wait_time ();
 }
 
+/* See maint.h.  */
+
+void
+scoped_command_stats::print_time (const char *msg)
+{
+  using namespace std::chrono;
+
+  auto now = system_clock::now ();
+  auto ticks = now.time_since_epoch ().count () / (1000 * 1000);
+  auto millis = ticks % 1000;
+
+  std::time_t as_time = system_clock::to_time_t (now);
+  struct tm *tm = localtime (&as_time);
+
+  char out[100];
+  strftime (out, sizeof (out), "%F %H:%M:%S", tm);
+
+  printf_unfiltered ("%s.%03d - %s\n", out, (int) millis, msg);
+}
+
 /* Handle unknown "mt set per-command" arguments.
    In this case have "mt set per-command on|off" affect every setting.  */
 
This page took 0.023538 seconds and 4 git commands to generate.