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

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: Add TODO comment for a bug, which will be addressed in another CL. 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..10415c61d5b34415b403fef98d39a6473147376b 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;
+ uint64_t start_time;
+ uint64_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);
}
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,10 @@ std::unique_ptr<ProcessDataSnapshot> SharedSampler::CaptureSnapshot() {
process_data.physical_bytes =
static_cast<int64_t>(pi->WorkingSetPrivateSize);
+ process_data.start_time = (uint64_t)pi->CreateTime;
brucedawson 2016/12/21 02:13:40 Should remove those casts - ULONGLONG and uint64_t
chengx 2016/12/21 22:05:54 Done.
+
+ process_data.cpu_time = (uint64_t)(pi->KernelTime + pi->UserTime);
brucedawson 2016/12/21 02:13:40 Ditto.
chengx 2016/12/21 22:05:54 Done.
+
// 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 +577,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 +592,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 +611,8 @@ void SharedSampler::OnRefreshDone(
// Task manager will use this to display 'N/A'.
stanisc 2016/12/21 19:17:52 Could you replace 'N/A' with '-'?
chengx 2016/12/21 22:05:54 Done.
int idle_wakeups_per_second = -1;
int64_t physical_bytes = -1;
+ uint64_t start_time = 0;
+ uint64_t cpu_time = 0;
// Match refresh result by |process_id|.
// This relies on refresh results being ordered by Process ID.
@@ -608,6 +627,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 +650,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