Skip to content

Commit

Permalink
Change power sampler to wait to receive another sample before quitting
Browse files Browse the repository at this point in the history
Change-Id: Ib8922b99884c1e8d848e8941e81dcd8b63b7f74e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4041289
Reviewed-by: Olivier Li <[email protected]>
Commit-Queue: Alex Attar <[email protected]>
Reviewed-by: Francois Pierre Doray <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1100697}
  • Loading branch information
alxattxr authored and Chromium LUCI CQ committed Feb 2, 2023
1 parent f25c4c5 commit 5c84d86
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions tools/mac/power/power_sampler/power_sampler_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,27 @@ int main(int argc, char** argv) {
sigaction(SIGINT, &new_action, NULL);

base::RepeatingTimer quit_timer;
quit_timer.Start(FROM_HERE, base::Seconds(1),
BindRepeating(
[](base::OnceClosure quit_closure) {
if (should_quit_.load())
std::move(quit_closure).Run();
},
run_loop.QuitClosure()));
quit_timer.Start(
FROM_HERE, base::Seconds(1),
BindRepeating(
[](base::RepeatingTimer* quit_timer) {
if (should_quit_.load()) {
std::cerr << "The application is waiting for the last-sample"
<< std::endl;
quit_timer->Stop();
}
},
base::Unretained(&quit_timer)));

auto sample_closure = BindRepeating(
[](power_sampler::SamplingController* controller,
base::OnceClosure quit_closure) {
if (controller->OnSamplingEvent())
base::OnceClosure quit_closure, base::RepeatingTimer* quit_timer) {
if (controller->OnSamplingEvent() || !quit_timer->IsRunning()) {
std::move(quit_closure).Run();
}
},
base::Unretained(&controller), run_loop.QuitClosure());
base::Unretained(&controller), run_loop.QuitClosure(),
base::Unretained(&quit_timer));

controller.StartSession();

Expand All @@ -376,8 +382,6 @@ int main(int argc, char** argv) {

run_loop.Run();

quit_timer.Stop();

controller.EndSession();

return kStatusSuccess;
Expand Down

0 comments on commit 5c84d86

Please sign in to comment.