From aa9222d7d3b1b91afc72954f853ee0c1831b1d40 Mon Sep 17 00:00:00 2001 From: Timo Paulssen Date: Tue, 21 Jul 2026 01:50:08 +0200 Subject: [PATCH] Add command "absolute-time" to get value of monotonic clock This can help with correlating an rr recording with a perf recording for example. --- src/DebuggerExtensionCommand.cc | 12 ++++++++++++ src/test/elapsed_time.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/DebuggerExtensionCommand.cc b/src/DebuggerExtensionCommand.cc index ef2ecc552d3..ad8d95c5c28 100644 --- a/src/DebuggerExtensionCommand.cc +++ b/src/DebuggerExtensionCommand.cc @@ -3,6 +3,7 @@ #include "DebuggerExtensionCommand.h" #include "ReplayTask.h" +#include "TraceFrame.h" #include "log.h" using namespace std; @@ -25,6 +26,17 @@ static SimpleDebuggerExtensionCommand elapsed_time( return string("Elapsed Time (s): ") + to_string(elapsed_time); }); +static SimpleDebuggerExtensionCommand absolute_time( + "absolute-time", + "Print absolute time (in seconds) from the monotonic clock in the" + " 'record' timeline.", + [](GdbServer&, Task* t, const vector&) { + auto replay_t = static_cast(t); + auto elapsed_time = replay_t->current_trace_frame().monotonic_time(); + + return string("Absolute Time (s): ") + to_string(elapsed_time); + }); + static SimpleDebuggerExtensionCommand when( "when", "Print the number of the last completely replayed rr event.", [](GdbServer&, Task* t, const vector&) { diff --git a/src/test/elapsed_time.py b/src/test/elapsed_time.py index 92ac609d017..6be3d2be746 100644 --- a/src/test/elapsed_time.py +++ b/src/test/elapsed_time.py @@ -1,6 +1,25 @@ +import time + from util import * import re +# Get monotonic timer value from right now +monotonic_start = time.monotonic() + +send_gdb("absolute-time") +expect_gdb(re.compile(r'(?<=Absolute Time \(s\): )[0-9.]+')) +absolute_time_start = float(last_match().group(0)) + +if absolute_time_start > monotonic_start: + failed("ERROR ... The reported monotonic time at the start was after the test script started") +if absolute_time_start < monotonic_start - 300: + failed("ERROR ... The reported monotonic time at the start was over five minutes before the test script started") + +send_gdb('elapsed-time') + +expect_gdb(re.compile(r'(?<=Elapsed Time \(s\): )[0-9.]+')) +elapsed_start = float(last_match().group(0)) + # Test that the elapsed-time GDB command returns a time >= 1.0 at a breakpoint # after sleep(1); @@ -18,4 +37,14 @@ failed('ERROR ... The reported elapsed time after sleeping for ' + f'{sleep_time} (s) was {elapsed_time}') +send_gdb("absolute-time") +expect_gdb(re.compile(r'(?<=Absolute Time \(s\): )[0-9.]+')) +absolute_time_end = float(last_match().group(0)) + +sleep_time_absolute = absolute_time_end - absolute_time_start +sleep_time_relative = elapsed_time - elapsed_start + +if abs(sleep_time_absolute - sleep_time_relative) > 0.0001: + failed(f"ERROR ... The sleep time reported by absolute-time vs elapsed-time was too far apart (should be as equal as double allows): {sleep_time_absolute} - {sleep_time_relative} = {sleep_time_absolute - sleep_time_relative}" ) + ok()