Skip to content

Commit

Permalink
Fix instruction count for start_measuring_time
Browse files Browse the repository at this point in the history
Currently perf_tests::start_measuring_time (and the corresponding
stop call) doesn't correctly measure the instruction count.
It always reports 0 instructions if any of these methods is used
in a perf test.

To fix this, we capture the linux_perf_event pointer in
the time_measurement class.
  • Loading branch information
travisdowns authored and avikivity committed Sep 6, 2022
1 parent aea45c9 commit 67c7df0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions include/seastar/testing/perf_tests.hh
Original file line number Diff line number Diff line change
Expand Up @@ -167,43 +167,48 @@ class time_measurement {
perf_stats _start_stats;
perf_stats _total_stats;

linux_perf_event* _instructions_retired_counter = nullptr;

public:
[[gnu::always_inline]] [[gnu::hot]]
void start_run(linux_perf_event* instructions_retired_counter = nullptr) {
_instructions_retired_counter = instructions_retired_counter;
_total_time = { };
_total_stats = {};
auto t = clock_type::now();
_run_start_time = t;
_start_time = t;
_start_stats = perf_stats::snapshot(instructions_retired_counter);
_start_stats = perf_stats::snapshot(_instructions_retired_counter);
}

[[gnu::always_inline]] [[gnu::hot]]
performance_test::run_result stop_run(linux_perf_event* instructions_retired_counter = nullptr) {
performance_test::run_result stop_run() {
auto t = clock_type::now();
performance_test::run_result ret;
if (_start_time == _run_start_time) {
ret.duration = t - _start_time;
auto stats = perf_stats::snapshot(instructions_retired_counter);
auto stats = perf_stats::snapshot(_instructions_retired_counter);
ret.stats = stats - _start_stats;
} else {
ret.duration = _total_time;
ret.stats = _total_stats;
}
_instructions_retired_counter = nullptr;
return ret;
}

[[gnu::always_inline]] [[gnu::hot]]
void start_iteration(linux_perf_event* instructions_retired_counter = nullptr) {
void start_iteration() {
_start_time = clock_type::now();
_start_stats = perf_stats::snapshot(instructions_retired_counter);
_start_stats = perf_stats::snapshot(_instructions_retired_counter);
}

[[gnu::always_inline]] [[gnu::hot]]
void stop_iteration(linux_perf_event* instructions_retired_counter = nullptr) {
void stop_iteration() {
auto t = clock_type::now();
_total_time += t - _start_time;
auto stats = perf_stats::snapshot(instructions_retired_counter);
perf_stats stats;
stats = perf_stats::snapshot(_instructions_retired_counter);
_total_stats += stats - _start_stats;
}
};
Expand Down Expand Up @@ -270,8 +275,8 @@ protected:
this->next_iteration(n);
});
})();
}).then([this] {
return measure_time.stop_run(&_instructions_retired_counter);
}).then([] {
return measure_time.stop_run();
}).finally([this] {
_instructions_retired_counter.disable();
});
Expand All @@ -287,7 +292,7 @@ protected:
this->next_iteration(run_test(dependency...));
})();
}
auto ret = measure_time.stop_run(&_instructions_retired_counter);
auto ret = measure_time.stop_run();
_instructions_retired_counter.disable();
return make_ready_future<run_result>(std::move(ret));
})();
Expand Down

0 comments on commit 67c7df0

Please sign in to comment.