OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/arc/metrics/arc_metrics_service.h" | 5 #include "components/arc/metrics/arc_metrics_service.h" |
6 | 6 |
7 #include <string> | |
8 | |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
10 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
11 #include "chromeos/dbus/session_manager_client.h" | 13 #include "chromeos/dbus/session_manager_client.h" |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 const int kRequestProcessListPeriodInMinutes = 5; | 17 const int kRequestProcessListPeriodInMinutes = 5; |
16 const char kArcProcessNamePrefix[] = "org.chromium.arc."; | 18 const char kArcProcessNamePrefix[] = "org.chromium.arc."; |
17 const char kGmsProcessNamePrefix[] = "com.google.android.gms"; | 19 const char kGmsProcessNamePrefix[] = "com.google.android.gms"; |
18 const char kBootProgressEnableScreen[] = "boot_progress_enable_screen"; | 20 const char kBootProgressEnableScreen[] = "boot_progress_enable_screen"; |
19 | 21 |
20 } // namespace | 22 } // namespace |
21 | 23 |
22 namespace arc { | 24 namespace arc { |
23 | 25 |
24 ArcMetricsService::ArcMetricsService(ArcBridgeService* bridge_service) | 26 ArcMetricsService::ArcMetricsService(ArcBridgeService* bridge_service) |
25 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { | 27 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { |
26 arc_bridge_service()->AddObserver(this); | 28 arc_bridge_service()->metrics()->AddObserver(this); |
29 arc_bridge_service()->process()->AddObserver(this); | |
27 oom_kills_monitor_.Start(); | 30 oom_kills_monitor_.Start(); |
28 } | 31 } |
29 | 32 |
30 ArcMetricsService::~ArcMetricsService() { | 33 ArcMetricsService::~ArcMetricsService() { |
31 DCHECK(CalledOnValidThread()); | 34 DCHECK(CalledOnValidThread()); |
32 arc_bridge_service()->RemoveObserver(this); | 35 arc_bridge_service()->process()->RemoveObserver(this); |
36 arc_bridge_service()->metrics()->RemoveObserver(this); | |
33 } | 37 } |
34 | 38 |
35 bool ArcMetricsService::CalledOnValidThread() { | 39 bool ArcMetricsService::CalledOnValidThread() { |
36 // Make sure access to the Chrome clipboard is happening in the UI thread. | 40 // Make sure access to the Chrome clipboard is happening in the UI thread. |
37 return thread_checker_.CalledOnValidThread(); | 41 return thread_checker_.CalledOnValidThread(); |
38 } | 42 } |
39 | 43 |
40 void ArcMetricsService::OnMetricsInstanceReady() { | 44 void ArcMetricsService::OnInstanceReady(mojom::MetricsInstance*, |
45 uint32_t version) { | |
41 VLOG(2) << "Start metrics service."; | 46 VLOG(2) << "Start metrics service."; |
42 // Retrieve ARC start time from session manager. | 47 // Retrieve ARC start time from session manager. |
43 chromeos::SessionManagerClient* session_manager_client = | 48 chromeos::SessionManagerClient* session_manager_client = |
44 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 49 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
45 session_manager_client->GetArcStartTime( | 50 session_manager_client->GetArcStartTime( |
46 base::Bind(&ArcMetricsService::OnArcStartTimeRetrieved, | 51 base::Bind(&ArcMetricsService::OnArcStartTimeRetrieved, |
47 weak_ptr_factory_.GetWeakPtr())); | 52 weak_ptr_factory_.GetWeakPtr())); |
48 } | 53 } |
49 | 54 |
50 void ArcMetricsService::OnMetricsInstanceClosed() { | 55 void ArcMetricsService::OnInstanceClosed(mojom::MetricsInstance*) { |
51 VLOG(2) << "Close metrics service."; | 56 VLOG(2) << "Close metrics service."; |
52 DCHECK(CalledOnValidThread()); | 57 DCHECK(CalledOnValidThread()); |
53 if (binding_.is_bound()) | 58 if (binding_.is_bound()) |
54 binding_.Unbind(); | 59 binding_.Unbind(); |
55 } | 60 } |
56 | 61 |
57 void ArcMetricsService::OnProcessInstanceReady() { | 62 void ArcMetricsService::OnInstanceReady(mojom::ProcessInstance*, |
63 uint32_t version) { | |
58 VLOG(2) << "Start updating process list."; | 64 VLOG(2) << "Start updating process list."; |
59 timer_.Start( | 65 timer_.Start(FROM_HERE, |
60 FROM_HERE, | 66 base::TimeDelta::FromMinutes(kRequestProcessListPeriodInMinutes), |
61 base::TimeDelta::FromMinutes(kRequestProcessListPeriodInMinutes), | 67 this, &ArcMetricsService::RequestProcessList); |
62 this, | |
63 &ArcMetricsService::RequestProcessList); | |
64 } | 68 } |
65 | 69 |
66 void ArcMetricsService::OnProcessInstanceClosed() { | 70 void ArcMetricsService::OnInstanceClosed(mojom::ProcessInstance*) { |
67 VLOG(2) << "Stop updating process list."; | 71 VLOG(2) << "Stop updating process list."; |
68 timer_.Stop(); | 72 timer_.Stop(); |
69 } | 73 } |
70 | 74 |
71 void ArcMetricsService::RequestProcessList() { | 75 void ArcMetricsService::RequestProcessList() { |
72 mojom::ProcessInstance* process_instance = | 76 mojom::ProcessInstance* process_instance = |
73 arc_bridge_service()->process_instance(); | 77 arc_bridge_service()->process()->instance(); |
74 if (!process_instance) { | 78 if (!process_instance) { |
75 LOG(ERROR) << "No process instance found before RequestProcessList"; | 79 LOG(ERROR) << "No process instance found before RequestProcessList"; |
76 return; | 80 return; |
77 } | 81 } |
78 | 82 |
79 VLOG(2) << "RequestProcessList"; | 83 VLOG(2) << "RequestProcessList"; |
80 process_instance->RequestProcessList( | 84 process_instance->RequestProcessList(base::Bind( |
81 base::Bind(&ArcMetricsService::ParseProcessList, | 85 &ArcMetricsService::ParseProcessList, weak_ptr_factory_.GetWeakPtr())); |
82 weak_ptr_factory_.GetWeakPtr())); | |
83 } | 86 } |
84 | 87 |
85 void ArcMetricsService::ParseProcessList( | 88 void ArcMetricsService::ParseProcessList( |
86 mojo::Array<arc::mojom::RunningAppProcessInfoPtr> processes) { | 89 mojo::Array<arc::mojom::RunningAppProcessInfoPtr> processes) { |
87 int running_app_count = 0; | 90 int running_app_count = 0; |
88 for (const auto& process : processes) { | 91 for (const auto& process : processes) { |
89 const mojo::String& process_name = process->process_name; | 92 const mojo::String& process_name = process->process_name; |
90 const mojom::ProcessState& process_state = process->process_state; | 93 const mojom::ProcessState& process_state = process->process_state; |
91 | 94 |
92 // Processes like the ARC launcher and intent helper are always running | 95 // Processes like the ARC launcher and intent helper are always running |
93 // and not counted as apps running by users. With the same reasoning, | 96 // and not counted as apps running by users. With the same reasoning, |
94 // GMS (Google Play Services) and its related processes are skipped as | 97 // GMS (Google Play Services) and its related processes are skipped as |
95 // well. The process_state check below filters out system processes, | 98 // well. The process_state check below filters out system processes, |
96 // services, apps that are cached because they've run before. | 99 // services, apps that are cached because they've run before. |
97 if (base::StartsWith(process_name.get(), kArcProcessNamePrefix, | 100 if (base::StartsWith(process_name.get(), kArcProcessNamePrefix, |
98 base::CompareCase::SENSITIVE) || | 101 base::CompareCase::SENSITIVE) || |
99 base::StartsWith(process_name.get(), kGmsProcessNamePrefix, | 102 base::StartsWith(process_name.get(), kGmsProcessNamePrefix, |
100 base::CompareCase::SENSITIVE) || | 103 base::CompareCase::SENSITIVE) || |
101 process_state != mojom::ProcessState::TOP) { | 104 process_state != mojom::ProcessState::TOP) { |
102 VLOG(2) << "Skipped " << process_name << " " << process_state; | 105 VLOG(2) << "Skipped " << process_name << " " << process_state; |
103 } else { | 106 } else { |
104 ++running_app_count; | 107 ++running_app_count; |
105 } | 108 } |
106 } | 109 } |
107 | 110 |
108 UMA_HISTOGRAM_COUNTS_100("Arc.AppCount", running_app_count); | 111 UMA_HISTOGRAM_COUNTS_100("Arc.AppCount", running_app_count); |
109 } | 112 } |
110 | 113 |
111 void ArcMetricsService::OnArcStartTimeRetrieved( | 114 void ArcMetricsService::OnArcStartTimeRetrieved( |
112 bool success, base::TimeTicks arc_start_time) { | 115 bool success, |
116 base::TimeTicks arc_start_time) { | |
113 DCHECK(CalledOnValidThread()); | 117 DCHECK(CalledOnValidThread()); |
114 if (!success) { | 118 if (!success) { |
115 LOG(ERROR) << "Failed to retrieve ARC start timeticks."; | 119 LOG(ERROR) << "Failed to retrieve ARC start timeticks."; |
116 return; | 120 return; |
117 } | 121 } |
118 | 122 |
119 // The binding of host interface is deferred until the ARC start time is | 123 // The binding of host interface is deferred until the ARC start time is |
120 // retrieved here because it prevents race condition of the ARC start | 124 // retrieved here because it prevents race condition of the ARC start |
121 // time availability in ReportBootProgress(). | 125 // time availability in ReportBootProgress(). |
122 if (!binding_.is_bound()) { | 126 if (!binding_.is_bound()) { |
hidehiko
2016/07/11 05:24:53
(This is off topic so I'm ok to address this separ
Luis Héctor Chávez
2016/07/11 17:13:34
OnArcStartTimeRetrieved already waits for MetricIn
| |
123 mojom::MetricsHostPtr host_ptr; | 127 mojom::MetricsHostPtr host_ptr; |
124 binding_.Bind(mojo::GetProxy(&host_ptr)); | 128 binding_.Bind(mojo::GetProxy(&host_ptr)); |
125 arc_bridge_service()->metrics_instance()->Init(std::move(host_ptr)); | 129 arc_bridge_service()->metrics()->instance()->Init(std::move(host_ptr)); |
126 } | 130 } |
127 arc_start_time_ = arc_start_time; | 131 arc_start_time_ = arc_start_time; |
128 VLOG(2) << "ARC start @" << arc_start_time_; | 132 VLOG(2) << "ARC start @" << arc_start_time_; |
129 } | 133 } |
130 | 134 |
131 void ArcMetricsService::ReportBootProgress( | 135 void ArcMetricsService::ReportBootProgress( |
132 mojo::Array<arc::mojom::BootProgressEventPtr> events) { | 136 mojo::Array<arc::mojom::BootProgressEventPtr> events) { |
133 DCHECK(CalledOnValidThread()); | 137 DCHECK(CalledOnValidThread()); |
134 int64_t arc_start_time_in_ms = | 138 int64_t arc_start_time_in_ms = |
135 (arc_start_time_ - base::TimeTicks()).InMilliseconds(); | 139 (arc_start_time_ - base::TimeTicks()).InMilliseconds(); |
136 for (const auto& event : events) { | 140 for (const auto& event : events) { |
137 VLOG(2) << "Report boot progress event:" | 141 VLOG(2) << "Report boot progress event:" << event->event << "@" |
138 << event->event << "@" << event->uptimeMillis; | 142 << event->uptimeMillis; |
139 std::string title = "Arc." + event->event.get(); | 143 std::string title = "Arc." + event->event.get(); |
140 base::TimeDelta elapsed_time = base::TimeDelta::FromMilliseconds( | 144 base::TimeDelta elapsed_time = base::TimeDelta::FromMilliseconds( |
141 event->uptimeMillis - arc_start_time_in_ms); | 145 event->uptimeMillis - arc_start_time_in_ms); |
142 // Note: This leaks memory, which is expected behavior. | 146 // Note: This leaks memory, which is expected behavior. |
143 base::HistogramBase* histogram = | 147 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( |
144 base::Histogram::FactoryTimeGet( | 148 title, base::TimeDelta::FromMilliseconds(1), |
145 title, | 149 base::TimeDelta::FromSeconds(30), 50, |
146 base::TimeDelta::FromMilliseconds(1), | 150 base::HistogramBase::kUmaTargetedHistogramFlag); |
147 base::TimeDelta::FromSeconds(30), | |
148 50, | |
149 base::HistogramBase::kUmaTargetedHistogramFlag); | |
150 histogram->AddTime(elapsed_time); | 151 histogram->AddTime(elapsed_time); |
151 if (event->event.get().compare(kBootProgressEnableScreen) == 0) | 152 if (event->event.get().compare(kBootProgressEnableScreen) == 0) |
152 UMA_HISTOGRAM_CUSTOM_TIMES("Arc.AndroidBootTime", | 153 UMA_HISTOGRAM_CUSTOM_TIMES("Arc.AndroidBootTime", elapsed_time, |
153 elapsed_time, | |
154 base::TimeDelta::FromMilliseconds(1), | 154 base::TimeDelta::FromMilliseconds(1), |
155 base::TimeDelta::FromSeconds(30), | 155 base::TimeDelta::FromSeconds(30), 50); |
156 50); | |
157 } | 156 } |
158 } | 157 } |
159 | 158 |
160 } // namespace arc | 159 } // namespace arc |
OLD | NEW |