Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/DebuggerExtensionCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "DebuggerExtensionCommand.h"

#include "ReplayTask.h"
#include "TraceFrame.h"
#include "log.h"

using namespace std;
Expand All @@ -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<string>&) {
auto replay_t = static_cast<ReplayTask*>(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<string>&) {
Expand Down
29 changes: 29 additions & 0 deletions src/test/elapsed_time.py
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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()
Loading