OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_metrics.h" | 5 #include "content/browser/service_worker/service_worker_metrics.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "content/browser/service_worker/embedded_worker_status.h" |
13 #include "content/common/service_worker/service_worker_types.h" | 14 #include "content/common/service_worker/service_worker_types.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
16 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 std::string StartSituationToSuffix( | 23 std::string StartSituationToSuffix( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 case ServiceWorkerMetrics::EventType::UNKNOWN: | 66 case ServiceWorkerMetrics::EventType::UNKNOWN: |
66 return "_UNKNOWN"; | 67 return "_UNKNOWN"; |
67 case ServiceWorkerMetrics::EventType::FOREIGN_FETCH: | 68 case ServiceWorkerMetrics::EventType::FOREIGN_FETCH: |
68 return "_FOREIGN_FETCH"; | 69 return "_FOREIGN_FETCH"; |
69 case ServiceWorkerMetrics::EventType::NUM_TYPES: | 70 case ServiceWorkerMetrics::EventType::NUM_TYPES: |
70 NOTREACHED() << static_cast<int>(event_type); | 71 NOTREACHED() << static_cast<int>(event_type); |
71 } | 72 } |
72 return "_UNKNOWN"; | 73 return "_UNKNOWN"; |
73 } | 74 } |
74 | 75 |
| 76 std::string GetWorkerPreparationSuffix( |
| 77 EmbeddedWorkerStatus initial_worker_status, |
| 78 ServiceWorkerMetrics::StartSituation start_situation) { |
| 79 switch (initial_worker_status) { |
| 80 case EmbeddedWorkerStatus::STOPPED: { |
| 81 switch (start_situation) { |
| 82 case ServiceWorkerMetrics::StartSituation::DURING_STARTUP: |
| 83 return "_StartWorkerDuringStartup"; |
| 84 case ServiceWorkerMetrics::StartSituation::NEW_PROCESS: |
| 85 return "_StartWorkerNewProcess"; |
| 86 case ServiceWorkerMetrics::StartSituation::EXISTING_PROCESS: |
| 87 return "_StartWorkerExistingProcess"; |
| 88 default: |
| 89 NOTREACHED() << static_cast<int>(start_situation); |
| 90 } |
| 91 } |
| 92 case EmbeddedWorkerStatus::STARTING: |
| 93 return "_StartingWorker"; |
| 94 case EmbeddedWorkerStatus::RUNNING: |
| 95 return "_RunningWorker"; |
| 96 case EmbeddedWorkerStatus::STOPPING: |
| 97 return "_StoppingWorker"; |
| 98 } |
| 99 NOTREACHED(); |
| 100 return "_UNKNOWN"; |
| 101 } |
| 102 |
75 // Use this for histograms with dynamically generated names, which | 103 // Use this for histograms with dynamically generated names, which |
76 // otherwise can't use the UMA_HISTOGRAM macro without code duplication. | 104 // otherwise can't use the UMA_HISTOGRAM macro without code duplication. |
77 void RecordSuffixedTimeHistogram(const std::string& name, | 105 void RecordSuffixedTimeHistogram(const std::string& name, |
78 const std::string& suffix, | 106 const std::string& suffix, |
79 base::TimeDelta sample) { | 107 base::TimeDelta sample) { |
80 const std::string name_with_suffix = name + suffix; | 108 const std::string name_with_suffix = name + suffix; |
81 // This unrolls UMA_HISTOGRAM_MEDIUM_TIMES. | 109 // This unrolls UMA_HISTOGRAM_MEDIUM_TIMES. |
82 base::HistogramBase* histogram_pointer = base::Histogram::FactoryTimeGet( | 110 base::HistogramBase* histogram_pointer = base::Histogram::FactoryTimeGet( |
83 name_with_suffix, base::TimeDelta::FromMilliseconds(10), | 111 name_with_suffix, base::TimeDelta::FromMilliseconds(10), |
84 base::TimeDelta::FromMinutes(3), 50, | 112 base::TimeDelta::FromMinutes(3), 50, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 time); | 309 time); |
282 RecordSuffixedTimeHistogram( | 310 RecordSuffixedTimeHistogram( |
283 "ServiceWorker.StartWorker.Time", | 311 "ServiceWorker.StartWorker.Time", |
284 StartSituationToSuffix(start_situation) + EventTypeToSuffix(purpose), | 312 StartSituationToSuffix(start_situation) + EventTypeToSuffix(purpose), |
285 time); | 313 time); |
286 } else { | 314 } else { |
287 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartNewWorker.Time", time); | 315 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartNewWorker.Time", time); |
288 } | 316 } |
289 } | 317 } |
290 | 318 |
| 319 void ServiceWorkerMetrics::RecordActivatedWorkerPreparationTimeForMainFrame( |
| 320 base::TimeDelta time, |
| 321 EmbeddedWorkerStatus initial_worker_status, |
| 322 StartSituation start_situation) { |
| 323 std::string name = |
| 324 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time"; |
| 325 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); |
| 326 RecordSuffixedTimeHistogram( |
| 327 name, GetWorkerPreparationSuffix(initial_worker_status, start_situation), |
| 328 time); |
| 329 } |
| 330 |
291 void ServiceWorkerMetrics::RecordWorkerStopped(StopStatus status) { | 331 void ServiceWorkerMetrics::RecordWorkerStopped(StopStatus status) { |
292 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.WorkerStopped", | 332 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.WorkerStopped", |
293 static_cast<int>(status), | 333 static_cast<int>(status), |
294 static_cast<int>(StopStatus::NUM_TYPES)); | 334 static_cast<int>(StopStatus::NUM_TYPES)); |
295 } | 335 } |
296 | 336 |
297 void ServiceWorkerMetrics::RecordStopWorkerTime(base::TimeDelta time) { | 337 void ServiceWorkerMetrics::RecordStopWorkerTime(base::TimeDelta time) { |
298 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StopWorker.Time", time); | 338 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StopWorker.Time", time); |
299 } | 339 } |
300 | 340 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 } else if (failure_count == 2) { | 609 } else if (failure_count == 2) { |
570 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_2", | 610 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_2", |
571 status, SERVICE_WORKER_ERROR_MAX_VALUE); | 611 status, SERVICE_WORKER_ERROR_MAX_VALUE); |
572 } else if (failure_count == 3) { | 612 } else if (failure_count == 3) { |
573 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_3", | 613 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_3", |
574 status, SERVICE_WORKER_ERROR_MAX_VALUE); | 614 status, SERVICE_WORKER_ERROR_MAX_VALUE); |
575 } | 615 } |
576 } | 616 } |
577 | 617 |
578 } // namespace content | 618 } // namespace content |
OLD | NEW |