| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/resource_reporter/resource_reporter.h" | 5 #include "chrome/browser/chromeos/resource_reporter/resource_reporter.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/task_management/task_manager_interface.h" | 17 #include "chrome/browser/task_management/task_manager_interface.h" |
| 17 #include "components/rappor/rappor_service.h" | 18 #include "components/rappor/rappor_service.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 | 22 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 last_gpu_process_cpu_ = cpu_usage; | 197 last_gpu_process_cpu_ = cpu_usage; |
| 197 last_gpu_process_memory_ = memory_usage >= 0 ? memory_usage : 0; | 198 last_gpu_process_memory_ = memory_usage >= 0 ? memory_usage : 0; |
| 198 break; | 199 break; |
| 199 | 200 |
| 200 default: | 201 default: |
| 201 // Other tasks types will be reported using Rappor. | 202 // Other tasks types will be reported using Rappor. |
| 202 TaskRecord* task_data = nullptr; | 203 TaskRecord* task_data = nullptr; |
| 203 auto itr = task_records_.find(id); | 204 auto itr = task_records_.find(id); |
| 204 if (itr == task_records_.end()) { | 205 if (itr == task_records_.end()) { |
| 205 task_data = new TaskRecord(id); | 206 task_data = new TaskRecord(id); |
| 206 task_records_[id] = make_scoped_ptr(task_data); | 207 task_records_[id] = base::WrapUnique(task_data); |
| 207 } else { | 208 } else { |
| 208 task_data = itr->second.get(); | 209 task_data = itr->second.get(); |
| 209 } | 210 } |
| 210 | 211 |
| 211 DCHECK_EQ(task_data->id, id); | 212 DCHECK_EQ(task_data->id, id); |
| 212 task_data->task_name_for_rappor = | 213 task_data->task_name_for_rappor = |
| 213 observed_task_manager()->GetTaskNameForRappor(id); | 214 observed_task_manager()->GetTaskNameForRappor(id); |
| 214 task_data->cpu_percent = cpu_usage; | 215 task_data->cpu_percent = cpu_usage; |
| 215 task_data->memory_bytes = memory_usage; | 216 task_data->memory_bytes = memory_usage; |
| 216 task_data->is_background = | 217 task_data->is_background = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 245 | 246 |
| 246 ResourceReporter::ResourceReporter() | 247 ResourceReporter::ResourceReporter() |
| 247 : TaskManagerObserver(base::TimeDelta::FromSeconds(kRefreshIntervalSeconds), | 248 : TaskManagerObserver(base::TimeDelta::FromSeconds(kRefreshIntervalSeconds), |
| 248 task_management::REFRESH_TYPE_CPU | | 249 task_management::REFRESH_TYPE_CPU | |
| 249 task_management::REFRESH_TYPE_MEMORY | | 250 task_management::REFRESH_TYPE_MEMORY | |
| 250 task_management::REFRESH_TYPE_PRIORITY), | 251 task_management::REFRESH_TYPE_PRIORITY), |
| 251 system_cpu_cores_range_(GetCurrentSystemCpuCoresRange()) { | 252 system_cpu_cores_range_(GetCurrentSystemCpuCoresRange()) { |
| 252 } | 253 } |
| 253 | 254 |
| 254 // static | 255 // static |
| 255 scoped_ptr<rappor::Sample> ResourceReporter::CreateRapporSample( | 256 std::unique_ptr<rappor::Sample> ResourceReporter::CreateRapporSample( |
| 256 rappor::RapporService* rappor_service, | 257 rappor::RapporService* rappor_service, |
| 257 const ResourceReporter::TaskRecord& task_record) { | 258 const ResourceReporter::TaskRecord& task_record) { |
| 258 scoped_ptr<rappor::Sample> sample(rappor_service->CreateSample( | 259 std::unique_ptr<rappor::Sample> sample( |
| 259 rappor::UMA_RAPPOR_TYPE)); | 260 rappor_service->CreateSample(rappor::UMA_RAPPOR_TYPE)); |
| 260 sample->SetStringField(kRapporTaskStringField, | 261 sample->SetStringField(kRapporTaskStringField, |
| 261 task_record.task_name_for_rappor); | 262 task_record.task_name_for_rappor); |
| 262 sample->SetFlagsField(kRapporPriorityFlagsField, | 263 sample->SetFlagsField(kRapporPriorityFlagsField, |
| 263 task_record.is_background ? | 264 task_record.is_background ? |
| 264 GET_ENUM_VAL(TaskProcessPriority::BACKGROUND) : | 265 GET_ENUM_VAL(TaskProcessPriority::BACKGROUND) : |
| 265 GET_ENUM_VAL(TaskProcessPriority::FOREGROUND), | 266 GET_ENUM_VAL(TaskProcessPriority::FOREGROUND), |
| 266 GET_ENUM_VAL(TaskProcessPriority::NUM_PRIORITIES)); | 267 GET_ENUM_VAL(TaskProcessPriority::NUM_PRIORITIES)); |
| 267 return sample; | 268 return sample; |
| 268 } | 269 } |
| 269 | 270 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 base::TimeDelta::FromMilliseconds(kMinimumTimeBetweenReportsInMs)) { | 394 base::TimeDelta::FromMilliseconds(kMinimumTimeBetweenReportsInMs)) { |
| 394 return; | 395 return; |
| 395 } | 396 } |
| 396 | 397 |
| 397 last_memory_pressure_event_time_ = base::TimeTicks::Now(); | 398 last_memory_pressure_event_time_ = base::TimeTicks::Now(); |
| 398 | 399 |
| 399 // Use weighted random sampling to select a task to report in the CPU | 400 // Use weighted random sampling to select a task to report in the CPU |
| 400 // metric. | 401 // metric. |
| 401 const TaskRecord* sampled_cpu_task = SampleTaskByCpu(); | 402 const TaskRecord* sampled_cpu_task = SampleTaskByCpu(); |
| 402 if (sampled_cpu_task) { | 403 if (sampled_cpu_task) { |
| 403 scoped_ptr<rappor::Sample> cpu_sample( | 404 std::unique_ptr<rappor::Sample> cpu_sample( |
| 404 CreateRapporSample(rappor_service, *sampled_cpu_task)); | 405 CreateRapporSample(rappor_service, *sampled_cpu_task)); |
| 405 cpu_sample->SetFlagsField(kRapporNumCoresRangeFlagsField, | 406 cpu_sample->SetFlagsField(kRapporNumCoresRangeFlagsField, |
| 406 GET_ENUM_VAL(system_cpu_cores_range_), | 407 GET_ENUM_VAL(system_cpu_cores_range_), |
| 407 GET_ENUM_VAL(CpuCoresNumberRange::NUM_RANGES)); | 408 GET_ENUM_VAL(CpuCoresNumberRange::NUM_RANGES)); |
| 408 cpu_sample->SetFlagsField( | 409 cpu_sample->SetFlagsField( |
| 409 kRapporUsageRangeFlagsField, | 410 kRapporUsageRangeFlagsField, |
| 410 GET_ENUM_VAL(GetCpuUsageRange(sampled_cpu_task->cpu_percent)), | 411 GET_ENUM_VAL(GetCpuUsageRange(sampled_cpu_task->cpu_percent)), |
| 411 GET_ENUM_VAL(CpuUsageRange::NUM_RANGES)); | 412 GET_ENUM_VAL(CpuUsageRange::NUM_RANGES)); |
| 412 rappor_service->RecordSampleObj(kCpuRapporMetric, std::move(cpu_sample)); | 413 rappor_service->RecordSampleObj(kCpuRapporMetric, std::move(cpu_sample)); |
| 413 } | 414 } |
| 414 | 415 |
| 415 // Use weighted random sampling to select a task to report in the memory | 416 // Use weighted random sampling to select a task to report in the memory |
| 416 // metric. | 417 // metric. |
| 417 const TaskRecord* sampled_memory_task = SampleTaskByMemory(); | 418 const TaskRecord* sampled_memory_task = SampleTaskByMemory(); |
| 418 if (sampled_memory_task) { | 419 if (sampled_memory_task) { |
| 419 scoped_ptr<rappor::Sample> memory_sample( | 420 std::unique_ptr<rappor::Sample> memory_sample( |
| 420 CreateRapporSample(rappor_service, *sampled_memory_task)); | 421 CreateRapporSample(rappor_service, *sampled_memory_task)); |
| 421 memory_sample->SetFlagsField( | 422 memory_sample->SetFlagsField( |
| 422 kRapporUsageRangeFlagsField, | 423 kRapporUsageRangeFlagsField, |
| 423 GET_ENUM_VAL(GetMemoryUsageRange(sampled_memory_task->memory_bytes)), | 424 GET_ENUM_VAL(GetMemoryUsageRange(sampled_memory_task->memory_bytes)), |
| 424 GET_ENUM_VAL(MemoryUsageRange::NUM_RANGES)); | 425 GET_ENUM_VAL(MemoryUsageRange::NUM_RANGES)); |
| 425 rappor_service->RecordSampleObj(kMemoryRapporMetric, | 426 rappor_service->RecordSampleObj(kMemoryRapporMetric, |
| 426 std::move(memory_sample)); | 427 std::move(memory_sample)); |
| 427 } | 428 } |
| 428 } | 429 } |
| 429 } | 430 } |
| 430 | 431 |
| 431 } // namespace chromeos | 432 } // namespace chromeos |
| OLD | NEW |