Commit 7bbcac65 authored by Jesse McKenna's avatar Jesse McKenna Committed by Commit Bot

IdleWakeups: count processes created and destroyed

This change makes IdleWakeups count the cumulative number of processes
created and destroyed with the target executable name during the
monitoring period, and display these counts in its final summary.

This enables the measurement of process turnover resulting from
operations of interest, which would otherwise not be reflected in
total process count (as a destroyed process and created process that
both occur in between polls would cancel each other out and go
undetected). Note that it is still possible to miss a process if its
lifetime is so short that it is created and destroyed entirely
between samples.

Counting is done by comparing the previous snapshot's set of process
IDs with the target executable name against the new snapshot's.

The accuracy of the counts added by this change was verified by
comparing against those collected by an ETW trace (System Activity >
Processes) over the same period. In this comparison, IdleWakeups
identified all created and destroyed Chrome processes apart from a
utility process with a lifetime of only 0.08 seconds between samples.

Change-Id: I93d674377906f6bd543da2c7b65792bb811fd91b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2342251
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796426}
parent b4bf03c5
......@@ -54,7 +54,19 @@ T GetMedian(ResultVector* results, T (*getter)(const Result&)) {
}
}
// This class holds the app state and constains a number of utilities for
// Count newly created processes: those in |processes| but not
// |previous_processes|.
size_t GetNumProcessesCreated(const ProcessDataMap& previous_processes,
const ProcessDataMap& processes) {
size_t num_processes_created = 0;
for (auto& process : processes) {
if (previous_processes.find(process.first) == previous_processes.end())
num_processes_created++;
}
return num_processes_created;
}
// This class holds the app state and contains a number of utilities for
// collecting and diffing snapshots of data, handling processes, etc.
class IdleWakeups {
public:
......@@ -279,11 +291,15 @@ int wmain(int argc, wchar_t* argv[]) {
system_information_sampler.TakeSnapshot();
the_app.OpenProcesses(*previous_snapshot);
const size_t initial_number_of_processes =
previous_snapshot->processes.size();
size_t final_number_of_processes = initial_number_of_processes;
ULONG cumulative_idle_wakeups_per_sec = 0;
double cumulative_cpu_usage = 0.0;
ULONGLONG cumulative_working_set = 0;
double cumulative_energy = 0.0;
size_t cumulative_processes_created = 0;
ResultVector results;
......@@ -300,6 +316,10 @@ int wmain(int argc, wchar_t* argv[]) {
std::unique_ptr<ProcessDataSnapshot> snapshot =
system_information_sampler.TakeSnapshot();
size_t number_of_processes = snapshot->processes.size();
final_number_of_processes = number_of_processes;
cumulative_processes_created += GetNumProcessesCreated(
previous_snapshot->processes, snapshot->processes);
Result result = the_app.DiffSnapshots(*previous_snapshot, *snapshot);
previous_snapshot = std::move(snapshot);
......@@ -345,5 +365,10 @@ int wmain(int argc, wchar_t* argv[]) {
median_result.idle_wakeups_per_sec, median_result.cpu_usage, '%',
median_result.working_set / 1024.0, median_result.power);
printf("\nProcesses created: %zu\n", cumulative_processes_created);
printf("Processes destroyed: %zu\n", initial_number_of_processes +
cumulative_processes_created -
final_number_of_processes);
return 0;
}
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