Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2805)

Unified Diff: chrome/browser/task_manager/sampling/shared_sampler_win.cc

Issue 2573183002: Add process start time and CPU time columns to task manager (Closed)
Patch Set: Fix nits Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/task_manager/sampling/shared_sampler_win.cc
diff --git a/chrome/browser/task_manager/sampling/shared_sampler_win.cc b/chrome/browser/task_manager/sampling/shared_sampler_win.cc
index e54e2f8295795c7be25563d0f41d3d330498eecf..14de1de58ed96533da949c8ed1969edd5763d743 100644
--- a/chrome/browser/task_manager/sampling/shared_sampler_win.cc
+++ b/chrome/browser/task_manager/sampling/shared_sampler_win.cc
@@ -220,6 +220,8 @@ struct ProcessData {
ProcessData(ProcessData&&) = default;
int64_t physical_bytes;
+ int64_t start_time;
+ int64_t cpu_time;
std::vector<ThreadData> threads;
private:
@@ -313,7 +315,8 @@ SharedSampler::SharedSampler(
SharedSampler::~SharedSampler() {}
int64_t SharedSampler::GetSupportedFlags() const {
- return REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY;
+ return REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY |
+ REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME;
}
SharedSampler::Callbacks::Callbacks() {}
@@ -323,12 +326,16 @@ SharedSampler::Callbacks::~Callbacks() {}
SharedSampler::Callbacks::Callbacks(Callbacks&& other) {
on_idle_wakeups = std::move(other.on_idle_wakeups);
on_physical_memory = std::move(other.on_physical_memory);
+ on_start_time = std::move(other.on_start_time);
+ on_cpu_time = std::move(other.on_cpu_time);
brucedawson 2016/12/19 21:51:05 Why is std::move being used here? It offers no val
}
void SharedSampler::RegisterCallbacks(
base::ProcessId process_id,
const OnIdleWakeupsCallback& on_idle_wakeups,
- const OnPhysicalMemoryCallback& on_physical_memory) {
+ const OnPhysicalMemoryCallback& on_physical_memory,
+ const OnStartTimeCallback& on_start_time,
+ const OnCpuTimeCallback& on_cpu_time) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (process_id == 0)
@@ -337,6 +344,8 @@ void SharedSampler::RegisterCallbacks(
Callbacks callbacks;
callbacks.on_idle_wakeups = on_idle_wakeups;
callbacks.on_physical_memory = on_physical_memory;
+ callbacks.on_start_time = on_start_time;
+ callbacks.on_cpu_time = on_cpu_time;
bool result = callbacks_map_.insert(
std::make_pair(process_id, std::move(callbacks))).second;
DCHECK(result);
@@ -487,6 +496,11 @@ std::unique_ptr<ProcessDataSnapshot> SharedSampler::CaptureSnapshot() {
process_data.physical_bytes =
static_cast<int64_t>(pi->WorkingSetPrivateSize);
+ process_data.start_time = static_cast<int64_t>(pi->CreateTime);
brucedawson 2016/12/19 21:51:05 What happens if you use uint64_t for start_time an
chengx 2016/12/20 00:51:12 Done.
+
+ process_data.cpu_time =
+ static_cast<int64_t>(pi->KernelTime + pi->UserTime);
+
// Iterate over threads and store each thread's ID and number of context
// switches.
for (ULONG thread_index = 0; thread_index < pi->NumberOfThreads;
@@ -564,6 +578,8 @@ void SharedSampler::MakeResultsFromTwoSnapshots(
result.idle_wakeups_per_second =
static_cast<int>(round(idle_wakeups_delta / time_delta));
result.physical_bytes = process.physical_bytes;
+ result.start_time = process.start_time;
+ result.cpu_time = process.cpu_time;
results->push_back(result);
}
}
@@ -577,6 +593,8 @@ void SharedSampler::MakeResultsFromSnapshot(const ProcessDataSnapshot& snapshot,
// ProcessMetrics::CalculateIdleWakeupsPerSecond implementation.
result.idle_wakeups_per_second = 0;
result.physical_bytes = pair.second.physical_bytes;
+ result.start_time = pair.second.start_time;
+ result.cpu_time = pair.second.cpu_time;
results->push_back(result);
}
}
@@ -594,6 +612,8 @@ void SharedSampler::OnRefreshDone(
// Task manager will use this to display 'N/A'.
int idle_wakeups_per_second = -1;
int64_t physical_bytes = -1;
+ int64_t start_time = -1;
+ int64_t cpu_time = -1;
// Match refresh result by |process_id|.
// This relies on refresh results being ordered by Process ID.
@@ -608,6 +628,8 @@ void SharedSampler::OnRefreshDone(
// Data matched in |refresh_results|.
idle_wakeups_per_second = result.idle_wakeups_per_second;
physical_bytes = result.physical_bytes;
+ start_time = result.start_time;
+ cpu_time = result.cpu_time;
++result_index;
break;
}
@@ -629,6 +651,18 @@ void SharedSampler::OnRefreshDone(
DCHECK(callback_entry.second.on_physical_memory);
callback_entry.second.on_physical_memory.Run(physical_bytes);
}
+
+ if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_START_TIME,
+ refresh_flags_)) {
+ DCHECK(callback_entry.second.on_start_time);
+ callback_entry.second.on_start_time.Run(start_time);
+ }
+
+ if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_CPU_TIME,
+ refresh_flags_)) {
+ DCHECK(callback_entry.second.on_cpu_time);
+ callback_entry.second.on_cpu_time.Run(cpu_time);
+ }
}
// Reset refresh_results_ to trigger RefreshOnWorkerThread next time Refresh

Powered by Google App Engine
This is Rietveld 408576698