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/17 23:06:06
nit: ditch empty lines here
matthalp
2017/05/18 16:13:46
Done.
| |
17 class ServiceContextRef; | |
18 | |
19 } // namespace service_manager | |
oystein (OOO til 10th of July)
2017/05/17 23:06:06
nit: ditto for ditching comment; no need when ther
matthalp
2017/05/18 16:13:46
Done.
| |
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 ScheduleProcessCPUProfiling(base::TimeDelta()); | |
46 } | |
47 | |
48 ProcessCoordinationUnitImpl::~ProcessCoordinationUnitImpl() {} | |
49 | |
50 void ProcessCoordinationUnitImpl::ScheduleProcessCPUProfiling( | |
oystein (OOO til 10th of July)
2017/05/17 23:06:06
I would just ditch this function and just start th
matthalp
2017/05/18 16:13:46
Done.
| |
51 base::TimeDelta delay) { | |
52 repeating_timer_.Start(FROM_HERE, delay, this, | |
53 &ProcessCoordinationUnitImpl::MeasureProcessCPUUsage); | |
54 } | |
55 | |
56 void ProcessCoordinationUnitImpl::MeasureProcessCPUUsage() { | |
57 cpu_usage_ = process_metrics_->GetPlatformIndependentCPUUsage(); | |
58 | |
59 ScheduleProcessCPUProfiling( | |
60 base::TimeDelta::FromSeconds(kCPUProfilingIntervalInSeconds)); | |
61 } | |
62 | |
63 double ProcessCoordinationUnitImpl::GetCPUUsageForTesting() { | |
64 return cpu_usage_; | |
65 } | |
66 | |
67 } // namespace resource_coordinator | |
OLD | NEW |