| 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/memory_coordinator_client_registry.h" | 12 #include "base/memory/memory_coordinator_client_registry.h" |
| 13 #include "base/memory/memory_pressure_monitor.h" | 13 #include "base/memory/memory_pressure_monitor.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/task_manager/task_manager_interface.h" | 20 #include "chrome/browser/task_manager/task_manager_interface.h" |
| 21 #include "components/rappor/rappor_service.h" | 21 #include "components/rappor/rappor_service_impl.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 | 23 |
| 24 namespace chromeos { | 24 namespace chromeos { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 #define GET_ENUM_VAL(enum_entry) static_cast<int>(enum_entry) | 28 #define GET_ENUM_VAL(enum_entry) static_cast<int>(enum_entry) |
| 29 | 29 |
| 30 // At a critical memory pressure event, we only care about a single complete | 30 // At a critical memory pressure event, we only care about a single complete |
| 31 // refresh from the task manager (with background calculations). So we request | 31 // refresh from the task manager (with background calculations). So we request |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 task_manager_to_observe_(nullptr), | 218 task_manager_to_observe_(nullptr), |
| 219 system_cpu_cores_range_(GetCurrentSystemCpuCoresRange()), | 219 system_cpu_cores_range_(GetCurrentSystemCpuCoresRange()), |
| 220 last_browser_process_cpu_(0.0), | 220 last_browser_process_cpu_(0.0), |
| 221 last_gpu_process_cpu_(0.0), | 221 last_gpu_process_cpu_(0.0), |
| 222 last_browser_process_memory_(0), | 222 last_browser_process_memory_(0), |
| 223 last_gpu_process_memory_(0), | 223 last_gpu_process_memory_(0), |
| 224 is_monitoring_(false) {} | 224 is_monitoring_(false) {} |
| 225 | 225 |
| 226 // static | 226 // static |
| 227 std::unique_ptr<rappor::Sample> ResourceReporter::CreateRapporSample( | 227 std::unique_ptr<rappor::Sample> ResourceReporter::CreateRapporSample( |
| 228 rappor::RapporService* rappor_service, | 228 rappor::RapporServiceImpl* rappor_service, |
| 229 const ResourceReporter::TaskRecord& task_record) { | 229 const ResourceReporter::TaskRecord& task_record) { |
| 230 std::unique_ptr<rappor::Sample> sample( | 230 std::unique_ptr<rappor::Sample> sample( |
| 231 rappor_service->CreateSample(rappor::UMA_RAPPOR_TYPE)); | 231 rappor_service->CreateSample(rappor::UMA_RAPPOR_TYPE)); |
| 232 sample->SetStringField(kRapporTaskStringField, | 232 sample->SetStringField(kRapporTaskStringField, |
| 233 task_record.task_name_for_rappor); | 233 task_record.task_name_for_rappor); |
| 234 sample->SetFlagsField(kRapporPriorityFlagsField, | 234 sample->SetFlagsField(kRapporPriorityFlagsField, |
| 235 task_record.is_background ? | 235 task_record.is_background ? |
| 236 GET_ENUM_VAL(TaskProcessPriority::BACKGROUND) : | 236 GET_ENUM_VAL(TaskProcessPriority::BACKGROUND) : |
| 237 GET_ENUM_VAL(TaskProcessPriority::FOREGROUND), | 237 GET_ENUM_VAL(TaskProcessPriority::FOREGROUND), |
| 238 GET_ENUM_VAL(TaskProcessPriority::NUM_PRIORITIES)); | 238 GET_ENUM_VAL(TaskProcessPriority::NUM_PRIORITIES)); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 if (sampled_cpu_task) { | 365 if (sampled_cpu_task) { |
| 366 std::unique_ptr<rappor::Sample> cpu_sample( | 366 std::unique_ptr<rappor::Sample> cpu_sample( |
| 367 CreateRapporSample(rappor_service, *sampled_cpu_task)); | 367 CreateRapporSample(rappor_service, *sampled_cpu_task)); |
| 368 cpu_sample->SetFlagsField(kRapporNumCoresRangeFlagsField, | 368 cpu_sample->SetFlagsField(kRapporNumCoresRangeFlagsField, |
| 369 GET_ENUM_VAL(system_cpu_cores_range_), | 369 GET_ENUM_VAL(system_cpu_cores_range_), |
| 370 GET_ENUM_VAL(CpuCoresNumberRange::NUM_RANGES)); | 370 GET_ENUM_VAL(CpuCoresNumberRange::NUM_RANGES)); |
| 371 cpu_sample->SetFlagsField( | 371 cpu_sample->SetFlagsField( |
| 372 kRapporUsageRangeFlagsField, | 372 kRapporUsageRangeFlagsField, |
| 373 GET_ENUM_VAL(GetCpuUsageRange(sampled_cpu_task->cpu_percent)), | 373 GET_ENUM_VAL(GetCpuUsageRange(sampled_cpu_task->cpu_percent)), |
| 374 GET_ENUM_VAL(CpuUsageRange::NUM_RANGES)); | 374 GET_ENUM_VAL(CpuUsageRange::NUM_RANGES)); |
| 375 rappor_service->RecordSampleObj(kCpuRapporMetric, std::move(cpu_sample)); | 375 rappor_service->RecordSample(kCpuRapporMetric, std::move(cpu_sample)); |
| 376 } | 376 } |
| 377 | 377 |
| 378 // Use weighted random sampling to select a task to report in the memory | 378 // Use weighted random sampling to select a task to report in the memory |
| 379 // metric. | 379 // metric. |
| 380 const TaskRecord* sampled_memory_task = SampleTaskByMemory(); | 380 const TaskRecord* sampled_memory_task = SampleTaskByMemory(); |
| 381 if (sampled_memory_task) { | 381 if (sampled_memory_task) { |
| 382 std::unique_ptr<rappor::Sample> memory_sample( | 382 std::unique_ptr<rappor::Sample> memory_sample( |
| 383 CreateRapporSample(rappor_service, *sampled_memory_task)); | 383 CreateRapporSample(rappor_service, *sampled_memory_task)); |
| 384 memory_sample->SetFlagsField( | 384 memory_sample->SetFlagsField( |
| 385 kRapporUsageRangeFlagsField, | 385 kRapporUsageRangeFlagsField, |
| 386 GET_ENUM_VAL(GetMemoryUsageRange(sampled_memory_task->memory_bytes)), | 386 GET_ENUM_VAL(GetMemoryUsageRange(sampled_memory_task->memory_bytes)), |
| 387 GET_ENUM_VAL(MemoryUsageRange::NUM_RANGES)); | 387 GET_ENUM_VAL(MemoryUsageRange::NUM_RANGES)); |
| 388 rappor_service->RecordSampleObj(kMemoryRapporMetric, | 388 rappor_service->RecordSample(kMemoryRapporMetric, std::move(memory_sample)); |
| 389 std::move(memory_sample)); | |
| 390 } | 389 } |
| 391 } | 390 } |
| 392 | 391 |
| 393 void ResourceReporter::OnMemoryPressure( | 392 void ResourceReporter::OnMemoryPressure( |
| 394 MemoryPressureLevel memory_pressure_level) { | 393 MemoryPressureLevel memory_pressure_level) { |
| 395 if (memory_pressure_level == | 394 if (memory_pressure_level == |
| 396 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 395 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 397 StartRecordingCurrentState(); | 396 StartRecordingCurrentState(); |
| 398 } else { | 397 } else { |
| 399 StopRecordingCurrentState(); | 398 StopRecordingCurrentState(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 break; | 442 break; |
| 444 case base::MemoryState::SUSPENDED: | 443 case base::MemoryState::SUSPENDED: |
| 445 // Note: Not supported at present. Fall through. | 444 // Note: Not supported at present. Fall through. |
| 446 case base::MemoryState::UNKNOWN: | 445 case base::MemoryState::UNKNOWN: |
| 447 NOTREACHED(); | 446 NOTREACHED(); |
| 448 break; | 447 break; |
| 449 } | 448 } |
| 450 } | 449 } |
| 451 | 450 |
| 452 } // namespace chromeos | 451 } // namespace chromeos |
| OLD | NEW |