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