| 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 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 return CpuCoresNumberRange::RANGE_NA; | 320 return CpuCoresNumberRange::RANGE_NA; |
| 321 } | 321 } |
| 322 | 322 |
| 323 const ResourceReporter::TaskRecord* ResourceReporter::SampleTaskByCpu() const { | 323 const ResourceReporter::TaskRecord* ResourceReporter::SampleTaskByCpu() const { |
| 324 // Perform a weighted random sampling taking the tasks' CPU usage as their | 324 // Perform a weighted random sampling taking the tasks' CPU usage as their |
| 325 // weights to randomly select one of them to be reported by Rappor. The higher | 325 // weights to randomly select one of them to be reported by Rappor. The higher |
| 326 // the CPU usage, the higher the chance that the task will be selected. | 326 // the CPU usage, the higher the chance that the task will be selected. |
| 327 // See https://en.wikipedia.org/wiki/Reservoir_sampling. | 327 // See https://en.wikipedia.org/wiki/Reservoir_sampling. |
| 328 TaskRecord* sampled_task = nullptr; | 328 TaskRecord* sampled_task = nullptr; |
| 329 double cpu_weights_sum = 0; | 329 double cpu_weights_sum = 0; |
| 330 for (const auto& task_data : task_records_by_cpu_) { | 330 for (auto* task_data : task_records_by_cpu_) { |
| 331 if ((base::RandDouble() * (cpu_weights_sum + task_data->cpu_percent)) >= | 331 if ((base::RandDouble() * (cpu_weights_sum + task_data->cpu_percent)) >= |
| 332 cpu_weights_sum) { | 332 cpu_weights_sum) { |
| 333 sampled_task = task_data; | 333 sampled_task = task_data; |
| 334 } | 334 } |
| 335 cpu_weights_sum += task_data->cpu_percent; | 335 cpu_weights_sum += task_data->cpu_percent; |
| 336 } | 336 } |
| 337 | 337 |
| 338 return sampled_task; | 338 return sampled_task; |
| 339 } | 339 } |
| 340 | 340 |
| 341 const ResourceReporter::TaskRecord* | 341 const ResourceReporter::TaskRecord* |
| 342 ResourceReporter::SampleTaskByMemory() const { | 342 ResourceReporter::SampleTaskByMemory() const { |
| 343 // Perform a weighted random sampling taking the tasks' memory usage as their | 343 // Perform a weighted random sampling taking the tasks' memory usage as their |
| 344 // weights to randomly select one of them to be reported by Rappor. The higher | 344 // weights to randomly select one of them to be reported by Rappor. The higher |
| 345 // the memory usage, the higher the chance that the task will be selected. | 345 // the memory usage, the higher the chance that the task will be selected. |
| 346 // See https://en.wikipedia.org/wiki/Reservoir_sampling. | 346 // See https://en.wikipedia.org/wiki/Reservoir_sampling. |
| 347 TaskRecord* sampled_task = nullptr; | 347 TaskRecord* sampled_task = nullptr; |
| 348 int64_t memory_weights_sum = 0; | 348 int64_t memory_weights_sum = 0; |
| 349 for (const auto& task_data : task_records_by_memory_) { | 349 for (auto* task_data : task_records_by_memory_) { |
| 350 if ((base::RandDouble() * (memory_weights_sum + task_data->memory_bytes)) >= | 350 if ((base::RandDouble() * (memory_weights_sum + task_data->memory_bytes)) >= |
| 351 memory_weights_sum) { | 351 memory_weights_sum) { |
| 352 sampled_task = task_data; | 352 sampled_task = task_data; |
| 353 } | 353 } |
| 354 memory_weights_sum += task_data->memory_bytes; | 354 memory_weights_sum += task_data->memory_bytes; |
| 355 } | 355 } |
| 356 | 356 |
| 357 return sampled_task; | 357 return sampled_task; |
| 358 } | 358 } |
| 359 | 359 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 374 UMA_HISTOGRAM_ENUMERATION( | 374 UMA_HISTOGRAM_ENUMERATION( |
| 375 "ResourceReporter.GpuProcess.CpuUsage", | 375 "ResourceReporter.GpuProcess.CpuUsage", |
| 376 GET_ENUM_VAL(GetCpuUsageRange(last_gpu_process_cpu_)), | 376 GET_ENUM_VAL(GetCpuUsageRange(last_gpu_process_cpu_)), |
| 377 GET_ENUM_VAL(CpuUsageRange::NUM_RANGES)); | 377 GET_ENUM_VAL(CpuUsageRange::NUM_RANGES)); |
| 378 UMA_HISTOGRAM_ENUMERATION( | 378 UMA_HISTOGRAM_ENUMERATION( |
| 379 "ResourceReporter.GpuProcess.MemoryUsage", | 379 "ResourceReporter.GpuProcess.MemoryUsage", |
| 380 GET_ENUM_VAL(GetMemoryUsageRange(last_gpu_process_memory_)), | 380 GET_ENUM_VAL(GetMemoryUsageRange(last_gpu_process_memory_)), |
| 381 GET_ENUM_VAL(MemoryUsageRange::NUM_RANGES)); | 381 GET_ENUM_VAL(MemoryUsageRange::NUM_RANGES)); |
| 382 | 382 |
| 383 // For the rest of tasks, report them using Rappor. | 383 // For the rest of tasks, report them using Rappor. |
| 384 auto rappor_service = g_browser_process->rappor_service(); | 384 auto* rappor_service = g_browser_process->rappor_service(); |
| 385 if (!rappor_service) | 385 if (!rappor_service) |
| 386 return; | 386 return; |
| 387 | 387 |
| 388 // We only record Rappor samples only if it's the first ever critical memory | 388 // We only record Rappor samples only if it's the first ever critical memory |
| 389 // pressure event we receive, or it has been more than | 389 // pressure event we receive, or it has been more than |
| 390 // |kMinimumTimeBetweenReportsInMs| since the last time we recorded samples. | 390 // |kMinimumTimeBetweenReportsInMs| since the last time we recorded samples. |
| 391 if (!have_seen_first_memory_pressure_event_) { | 391 if (!have_seen_first_memory_pressure_event_) { |
| 392 have_seen_first_memory_pressure_event_ = true; | 392 have_seen_first_memory_pressure_event_ = true; |
| 393 } else if ((base::TimeTicks::Now() - last_memory_pressure_event_time_) < | 393 } else if ((base::TimeTicks::Now() - last_memory_pressure_event_time_) < |
| 394 base::TimeDelta::FromMilliseconds(kMinimumTimeBetweenReportsInMs)) { | 394 base::TimeDelta::FromMilliseconds(kMinimumTimeBetweenReportsInMs)) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 423 kRapporUsageRangeFlagsField, | 423 kRapporUsageRangeFlagsField, |
| 424 GET_ENUM_VAL(GetMemoryUsageRange(sampled_memory_task->memory_bytes)), | 424 GET_ENUM_VAL(GetMemoryUsageRange(sampled_memory_task->memory_bytes)), |
| 425 GET_ENUM_VAL(MemoryUsageRange::NUM_RANGES)); | 425 GET_ENUM_VAL(MemoryUsageRange::NUM_RANGES)); |
| 426 rappor_service->RecordSampleObj(kMemoryRapporMetric, | 426 rappor_service->RecordSampleObj(kMemoryRapporMetric, |
| 427 std::move(memory_sample)); | 427 std::move(memory_sample)); |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 | 431 |
| 432 } // namespace chromeos | 432 } // namespace chromeos |
| OLD | NEW |