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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector.cc

Issue 884063003: Updated device reporting code to report multiple samples of free RAM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <limits> 8 #include <limits>
9 #include <sys/statvfs.h> 9 #include <sys/statvfs.h>
10 10
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 std::string day_key = base::Int64ToString(TimestampToDayKey(start)); 346 std::string day_key = base::Int64ToString(TimestampToDayKey(start));
347 int previous_activity = 0; 347 int previous_activity = 0;
348 activity_times->GetInteger(day_key, &previous_activity); 348 activity_times->GetInteger(day_key, &previous_activity);
349 activity_times->SetInteger(day_key, previous_activity + activity); 349 activity_times->SetInteger(day_key, previous_activity + activity);
350 start = midnight; 350 start = midnight;
351 } 351 }
352 } 352 }
353 353
354 void DeviceStatusCollector::ClearCachedHardwareStatus() { 354 void DeviceStatusCollector::ClearCachedHardwareStatus() {
355 volume_info_.clear(); 355 volume_info_.clear();
356 cpu_usage_percent_.clear(); 356 resource_usage_.clear();
357 } 357 }
358 358
359 void DeviceStatusCollector::IdleStateCallback(ui::IdleState state) { 359 void DeviceStatusCollector::IdleStateCallback(ui::IdleState state) {
360 // Do nothing if device activity reporting is disabled. 360 // Do nothing if device activity reporting is disabled.
361 if (!report_activity_times_) 361 if (!report_activity_times_)
362 return; 362 return;
363 363
364 Time now = GetCurrentTime(); 364 Time now = GetCurrentTime();
365 365
366 if (state == ui::IDLE_STATE_ACTIVE) { 366 if (state == ui::IDLE_STATE_ACTIVE) {
(...skipping 28 matching lines...) Expand all
395 } 395 }
396 396
397 // Call out to the blocking pool to measure disk usage. 397 // Call out to the blocking pool to measure disk usage.
398 base::PostTaskAndReplyWithResult( 398 base::PostTaskAndReplyWithResult(
399 content::BrowserThread::GetBlockingPool(), 399 content::BrowserThread::GetBlockingPool(),
400 FROM_HERE, 400 FROM_HERE,
401 base::Bind(volume_info_fetcher_, mount_points), 401 base::Bind(volume_info_fetcher_, mount_points),
402 base::Bind(&DeviceStatusCollector::ReceiveVolumeInfo, 402 base::Bind(&DeviceStatusCollector::ReceiveVolumeInfo,
403 weak_factory_.GetWeakPtr())); 403 weak_factory_.GetWeakPtr()));
404 404
405 SampleCPUUsage(); 405 SampleResourceUsage();
406 } 406 }
407 407
408 void DeviceStatusCollector::SampleCPUUsage() { 408 void DeviceStatusCollector::SampleResourceUsage() {
409 // Walk the process list and measure CPU utilization. 409 // Walk the process list and measure CPU utilization.
410 double total_usage = 0; 410 double total_usage = 0;
411 std::vector<double> per_process_usage = GetPerProcessCPUUsage(); 411 std::vector<double> per_process_usage = GetPerProcessCPUUsage();
412 for (double cpu_usage : per_process_usage) { 412 for (double cpu_usage : per_process_usage) {
413 total_usage += cpu_usage; 413 total_usage += cpu_usage;
414 } 414 }
415 cpu_usage_percent_.push_back(total_usage); 415
416 ResourceUsage usage = { total_usage,
417 base::SysInfo::AmountOfAvailablePhysicalMemory() };
418
419 resource_usage_.push_back(usage);
416 420
417 // If our cache of samples is full, throw out old samples to make room for new 421 // If our cache of samples is full, throw out old samples to make room for new
418 // sample. 422 // sample.
419 if (cpu_usage_percent_.size() > kMaxCPUSamples) 423 if (resource_usage_.size() > kMaxResourceUsageSamples)
420 cpu_usage_percent_.pop_front(); 424 resource_usage_.pop_front();
Mattias Nissler (ping if slow) 2015/01/29 08:19:41 Hm, this seems odd from a reporting perspective. T
Andrew T Wilson (Slow) 2015/01/29 09:02:58 Yes, the goal isn't to give a smooth set of discre
421 } 425 }
422 426
423 std::vector<double> DeviceStatusCollector::GetPerProcessCPUUsage() { 427 std::vector<double> DeviceStatusCollector::GetPerProcessCPUUsage() {
424 std::vector<double> cpu_usage; 428 std::vector<double> cpu_usage;
425 base::ProcessIterator process_iter(nullptr); 429 base::ProcessIterator process_iter(nullptr);
426 430
427 const int num_processors = base::SysInfo::NumberOfProcessors(); 431 const int num_processors = base::SysInfo::NumberOfProcessors();
428 while (const base::ProcessEntry* process_entry = 432 while (const base::ProcessEntry* process_entry =
429 process_iter.NextProcessEntry()) { 433 process_iter.NextProcessEntry()) {
430 base::ProcessHandle process; 434 base::ProcessHandle process;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 651 }
648 652
649 void DeviceStatusCollector::GetHardwareStatus( 653 void DeviceStatusCollector::GetHardwareStatus(
650 em::DeviceStatusReportRequest* status) { 654 em::DeviceStatusReportRequest* status) {
651 // Add volume info. 655 // Add volume info.
652 status->clear_volume_info(); 656 status->clear_volume_info();
653 for (const em::VolumeInfo& info : volume_info_) { 657 for (const em::VolumeInfo& info : volume_info_) {
654 *status->add_volume_info() = info; 658 *status->add_volume_info() = info;
655 } 659 }
656 660
657 status->set_system_ram_free(base::SysInfo::AmountOfAvailablePhysicalMemory());
658 status->set_system_ram_total(base::SysInfo::AmountOfPhysicalMemory()); 661 status->set_system_ram_total(base::SysInfo::AmountOfPhysicalMemory());
659 662 status->clear_system_ram_free();
660 status->clear_cpu_utilization_pct(); 663 status->clear_cpu_utilization_pct();
661 for (const int cpu_usage : cpu_usage_percent_) { 664 for (const ResourceUsage& usage : resource_usage_) {
662 status->add_cpu_utilization_pct(cpu_usage); 665 status->add_cpu_utilization_pct(usage.cpu_usage_percent);
666 status->add_system_ram_free(usage.bytes_of_ram_free);
663 } 667 }
664 } 668 }
665 669
666 bool DeviceStatusCollector::GetDeviceStatus( 670 bool DeviceStatusCollector::GetDeviceStatus(
667 em::DeviceStatusReportRequest* status) { 671 em::DeviceStatusReportRequest* status) {
668 if (report_activity_times_) 672 if (report_activity_times_)
669 GetActivityTimes(status); 673 GetActivityTimes(status);
670 674
671 if (report_version_info_) 675 if (report_version_info_)
672 GetVersionInfo(status); 676 GetVersionInfo(status);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 ScheduleGeolocationUpdateRequest(); 770 ScheduleGeolocationUpdateRequest();
767 } 771 }
768 772
769 void DeviceStatusCollector::ReceiveVolumeInfo( 773 void DeviceStatusCollector::ReceiveVolumeInfo(
770 const std::vector<em::VolumeInfo>& info) { 774 const std::vector<em::VolumeInfo>& info) {
771 if (report_hardware_status_) 775 if (report_hardware_status_)
772 volume_info_ = info; 776 volume_info_ = info;
773 } 777 }
774 778
775 } // namespace policy 779 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698