Commit 074118b6 authored by Jesse McKenna's avatar Jesse McKenna Committed by Commit Bot

IdleWakeups: optionally exit with target process

This change adds command-line option --stop-on-exit to IdleWakeups.
This makes IdleWakeups automatically stop measurement when the target
process closes, rather than needing to be stopped via Ctrl-C.

If the target process is not running when IdleWakeups starts, it runs
like normal until the target process is detected and then goes away,
at which point it stops.

Change-Id: Iaa11d79e13250c8887d7aacfbfde5d0696d76b08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464442Reviewed-by: default avatarAlex Gough <ajgo@chromium.org>
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Cr-Commit-Position: refs/heads/master@{#817043}
parent 25125321
......@@ -27,8 +27,11 @@ median values over the entire measurement interval.
By default, CPU usage is normalized to one CPU core, with 100% meaning one CPU
core is fully utilized.
To view CPU time in seconds rather than by percentage, use command-line option
`--cpu-seconds`.
[Intel Power Gadget](https://software.intel.com/en-us/articles/intel-power-gadget-20)
is required to allow IdleWakeups tool to query power usage.
Optional command-line flags:
* `--cpu-seconds`: display CPU time in seconds rather than by percentage.
* `--stop-on-exit`: stop measurement automatically when target process exits.
\ No newline at end of file
......@@ -289,17 +289,21 @@ int wmain(int argc, wchar_t* argv[]) {
PowerSampler power_sampler;
IdleWakeups the_app;
// Parse command line for target process name and optional --cpu-seconds flag.
// Parse command line for target process name and optional --cpu-seconds and
// --stop-on-exit flags.
wchar_t* target_process_name = nullptr;
bool cpu_usage_in_seconds = false;
bool stop_on_exit = false;
for (int i = 1; i < argc; i++) {
if (wcscmp(argv[i], L"--cpu-seconds") == 0)
cpu_usage_in_seconds = true;
else if (wcscmp(argv[i], L"--stop-on-exit") == 0)
stop_on_exit = true;
else if (!target_process_name)
target_process_name = argv[i];
// Stop parsing if all possible args have been found.
if (cpu_usage_in_seconds && target_process_name)
if (cpu_usage_in_seconds && stop_on_exit && target_process_name)
break;
}
const char cpu_usage_unit = cpu_usage_in_seconds ? 's' : '%';
......@@ -330,6 +334,7 @@ int wmain(int argc, wchar_t* argv[]) {
PrintHeader();
bool target_process_seen = false;
for (;;) {
if (WaitForSingleObject(ctrl_c_pressed, sleep_time_sec * 1000) ==
WAIT_OBJECT_0)
......@@ -362,8 +367,11 @@ int wmain(int argc, wchar_t* argv[]) {
cumulative_working_set += result.working_set;
cumulative_energy += result.power;
results.push_back(result);
target_process_seen = true;
} else {
num_idle_snapshots++;
if (stop_on_exit && target_process_seen)
break;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment