diff options
author | Tom Tromey <tromey@adacore.com> | 2019-04-11 11:26:02 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2019-06-06 08:53:56 -0600 |
commit | 3847a7bfbf6340372962c07f31187ff87b4f492c (patch) | |
tree | f6a4ea2e9ef30d4ccd0d913378475b0e5ef2b3fb /gdb/maint.c | |
parent | 237df8fe1863bb47fcf71ce125cd962666173aaa (diff) | |
download | binutils-3847a7bfbf6340372962c07f31187ff87b4f492c.zip binutils-3847a7bfbf6340372962c07f31187ff87b4f492c.tar.gz binutils-3847a7bfbf6340372962c07f31187ff87b4f492c.tar.bz2 |
Add timestamps to "maint time" output
Currently "maint time" will print the amount of time a command took.
Sometimes, though, it's useful to have a timestamp as well -- for
example if one is correlating a gdb log with some other log.
This patch adds a timestamp to the start and end of each command when
this setting is in effect.
This also removes a "//" comment and changes scoped_command_stats to
use DISABLE_COPY_AND_ASSIGN; two minor things I noticed while working
on the patch.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-06-06 Tom Tromey <tromey@adacore.com>
* maint.h (class scoped_command_stats): Use
DISABLE_COPY_AND_ASSIGN.
<print_time>: New method.
* maint.c (scoped_command_stats, ~scoped_command_stats): Call
print_time.
(scoped_command_stats::print_time): New method.
gdb/testsuite/ChangeLog
2019-06-06 Tom Tromey <tromey@adacore.com>
* gdb.base/maint.exp: Expect command started/finished output.
Diffstat (limited to 'gdb/maint.c')
-rw-r--r-- | gdb/maint.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gdb/maint.c b/gdb/maint.c index 328d602..aaabb35 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -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. */ |