Skip to content

Commit 39e5c18

Browse files
timorocallahan
authored andcommitted
Add command "absolute-time" to get value of monotonic clock
This can help with correlating an rr recording with a perf recording for example.
1 parent de03888 commit 39e5c18

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/DebuggerExtensionCommand.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "DebuggerExtensionCommand.h"
44

55
#include "ReplayTask.h"
6+
#include "TraceFrame.h"
67
#include "log.h"
78

89
using namespace std;
@@ -25,6 +26,17 @@ static SimpleDebuggerExtensionCommand elapsed_time(
2526
return string("Elapsed Time (s): ") + to_string(elapsed_time);
2627
});
2728

29+
static SimpleDebuggerExtensionCommand absolute_time(
30+
"absolute-time",
31+
"Print absolute time (in seconds) from the monotonic clock in the"
32+
" 'record' timeline.",
33+
[](GdbServer&, Task* t, const vector<string>&) {
34+
auto replay_t = static_cast<ReplayTask*>(t);
35+
auto elapsed_time = replay_t->current_trace_frame().monotonic_time();
36+
37+
return string("Absolute Time (s): ") + to_string(elapsed_time);
38+
});
39+
2840
static SimpleDebuggerExtensionCommand when(
2941
"when", "Print the number of the last completely replayed rr event.",
3042
[](GdbServer&, Task* t, const vector<string>&) {

src/test/elapsed_time.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
import time
2+
13
from util import *
24
import re
35

6+
# Get monotonic timer value from right now
7+
monotonic_start = time.monotonic()
8+
9+
send_gdb("absolute-time")
10+
expect_gdb(re.compile(r'(?<=Absolute Time \(s\): )[0-9.]+'))
11+
absolute_time_start = float(last_match().group(0))
12+
13+
if absolute_time_start > monotonic_start:
14+
failed("ERROR ... The reported monotonic time at the start was after the test script started")
15+
if absolute_time_start < monotonic_start - 300:
16+
failed("ERROR ... The reported monotonic time at the start was over five minutes before the test script started")
17+
18+
send_gdb('elapsed-time')
19+
20+
expect_gdb(re.compile(r'(?<=Elapsed Time \(s\): )[0-9.]+'))
21+
elapsed_start = float(last_match().group(0))
22+
423
# Test that the elapsed-time GDB command returns a time >= 1.0 at a breakpoint
524
# after sleep(1);
625

@@ -18,4 +37,14 @@
1837
failed('ERROR ... The reported elapsed time after sleeping for ' +
1938
f'{sleep_time} (s) was {elapsed_time}')
2039

40+
send_gdb("absolute-time")
41+
expect_gdb(re.compile(r'(?<=Absolute Time \(s\): )[0-9.]+'))
42+
absolute_time_end = float(last_match().group(0))
43+
44+
sleep_time_absolute = absolute_time_end - absolute_time_start
45+
sleep_time_relative = elapsed_time - elapsed_start
46+
47+
if abs(sleep_time_absolute - sleep_time_relative) > 0.0001:
48+
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}" )
49+
2150
ok()

0 commit comments

Comments
 (0)