Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "services/resource_coordinator/coordination_unit/process_coordination_u nit_impl.h" | |
| 6 | |
| 7 #include "base/process/process_handle.h" | |
| 8 #include "base/process/process_metrics.h" | |
| 9 #include "base/time/time.h" | |
| 10 | |
| 11 #if defined(OS_MACOSX) | |
| 12 #include "services/service_manager/public/cpp/standalone_service/mach_broker.h" | |
| 13 #endif | |
| 14 | |
| 15 namespace service_manager { | |
| 16 | |
|
oystein (OOO til 10th of July)
2017/05/18 21:24:32
nit: some redundant empty lines+comment here still
| |
| 17 class ServiceContextRef; | |
| 18 | |
| 19 } // namespace service_manager | |
| 20 | |
| 21 namespace resource_coordinator { | |
| 22 | |
| 23 struct CoordinationUnitID; | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 const int kCPUProfilingIntervalInSeconds = 5; | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 ProcessCoordinationUnitImpl::ProcessCoordinationUnitImpl( | |
| 32 const CoordinationUnitID& id, | |
| 33 std::unique_ptr<service_manager::ServiceContextRef> service_ref) | |
| 34 : CoordinationUnitImpl(id, std::move(service_ref)), cpu_usage_(-1.0) { | |
| 35 // ProcessCoordinationUnit ids should correspond to its pid | |
| 36 base::ProcessHandle pid = id.id; | |
| 37 | |
| 38 #if defined(OS_MACOSX) | |
| 39 process_metrics_ = base::ProcessMetrics::CreateProcessMetrics( | |
| 40 pid, service_manager::MachBroker::GetInstance()->port_provider()); | |
| 41 #else | |
| 42 process_metrics_ = base::ProcessMetrics::CreateProcessMetrics(pid); | |
| 43 #endif | |
| 44 | |
| 45 repeating_timer_.Start(FROM_HERE, base::TimeDelta(), this, | |
| 46 &ProcessCoordinationUnitImpl::MeasureProcessCPUUsage); | |
| 47 } | |
| 48 | |
| 49 ProcessCoordinationUnitImpl::~ProcessCoordinationUnitImpl() {} | |
|
oystein (OOO til 10th of July)
2017/05/18 21:24:32
nit: = default
| |
| 50 | |
| 51 void ProcessCoordinationUnitImpl::MeasureProcessCPUUsage() { | |
| 52 cpu_usage_ = process_metrics_->GetPlatformIndependentCPUUsage(); | |
| 53 | |
| 54 repeating_timer_.Start( | |
| 55 FROM_HERE, base::TimeDelta::FromSeconds(kCPUProfilingIntervalInSeconds), | |
| 56 this, &ProcessCoordinationUnitImpl::MeasureProcessCPUUsage); | |
| 57 } | |
| 58 | |
| 59 double ProcessCoordinationUnitImpl::GetCPUUsageForTesting() { | |
| 60 return cpu_usage_; | |
| 61 } | |
| 62 | |
| 63 } // namespace resource_coordinator | |
| OLD | NEW |