Chromium Code Reviews| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 case ServiceWorkerMetrics::EventType::NAVIGATION_HINT_LINK_TAP_DOWN: | 79 case ServiceWorkerMetrics::EventType::NAVIGATION_HINT_LINK_TAP_DOWN: |
| 80 return "_NAVIGATION_HINT_LINK_TAP_DOWN"; | 80 return "_NAVIGATION_HINT_LINK_TAP_DOWN"; |
| 81 case ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST: | 81 case ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST: |
| 82 return "_EXTERNAL_REQUEST"; | 82 return "_EXTERNAL_REQUEST"; |
| 83 case ServiceWorkerMetrics::EventType::NUM_TYPES: | 83 case ServiceWorkerMetrics::EventType::NUM_TYPES: |
| 84 NOTREACHED() << static_cast<int>(event_type); | 84 NOTREACHED() << static_cast<int>(event_type); |
| 85 } | 85 } |
| 86 return "_UNKNOWN"; | 86 return "_UNKNOWN"; |
| 87 } | 87 } |
| 88 | 88 |
| 89 std::string GetWorkerPreparationSuffix( | 89 ServiceWorkerMetrics::WorkerPreparationType GetWorkerPreparationType( |
| 90 EmbeddedWorkerStatus initial_worker_status, | 90 EmbeddedWorkerStatus initial_worker_status, |
| 91 ServiceWorkerMetrics::StartSituation start_situation) { | 91 ServiceWorkerMetrics::StartSituation start_situation) { |
| 92 using Situation = ServiceWorkerMetrics::StartSituation; | |
| 93 using Preparation = ServiceWorkerMetrics::WorkerPreparationType; | |
| 92 switch (initial_worker_status) { | 94 switch (initial_worker_status) { |
| 93 case EmbeddedWorkerStatus::STOPPED: { | 95 case EmbeddedWorkerStatus::STOPPED: { |
| 94 switch (start_situation) { | 96 switch (start_situation) { |
| 95 case ServiceWorkerMetrics::StartSituation::DURING_STARTUP: | 97 case Situation::DURING_STARTUP: |
| 96 return "_StartWorkerDuringStartup"; | 98 return Preparation::START_DURING_STARTUP; |
| 97 case ServiceWorkerMetrics::StartSituation::NEW_PROCESS: | 99 case Situation::NEW_PROCESS: |
| 98 return "_StartWorkerNewProcess"; | 100 return Preparation::START_IN_NEW_PROCESS; |
| 99 case ServiceWorkerMetrics::StartSituation::EXISTING_PROCESS: | 101 case Situation::EXISTING_PROCESS: |
| 100 return "_StartWorkerExistingProcess"; | 102 return Preparation::START_IN_EXISTING_PROCESS; |
| 101 default: | 103 case Situation::UNKNOWN: |
| 102 NOTREACHED() << static_cast<int>(start_situation); | 104 break; |
| 103 } | 105 } |
| 106 break; | |
| 104 } | 107 } |
| 105 case EmbeddedWorkerStatus::STARTING: | 108 case EmbeddedWorkerStatus::STARTING: |
| 109 return Preparation::STARTING; | |
| 110 case EmbeddedWorkerStatus::RUNNING: | |
| 111 return Preparation::RUNNING; | |
| 112 case EmbeddedWorkerStatus::STOPPING: | |
| 113 return Preparation::STOPPING; | |
| 114 } | |
| 115 NOTREACHED() << static_cast<int>(initial_worker_status); | |
| 116 return Preparation::UNKNOWN; | |
| 117 } | |
| 118 | |
| 119 std::string GetWorkerPreparationSuffix( | |
| 120 ServiceWorkerMetrics::WorkerPreparationType status) { | |
| 121 using Preparation = ServiceWorkerMetrics::WorkerPreparationType; | |
| 122 switch (status) { | |
| 123 case Preparation::UNKNOWN: | |
| 124 case Preparation::NUM_TYPES: | |
| 125 break; | |
| 126 case Preparation::START_DURING_STARTUP: | |
| 127 return "_StartWorkerDuringStartup"; | |
| 128 case Preparation::START_IN_NEW_PROCESS: | |
| 129 return "_StartWorkerNewProcess"; | |
| 130 case Preparation::START_IN_EXISTING_PROCESS: | |
| 131 return "_StartWorkerExistingProcess"; | |
| 132 case Preparation::STARTING: | |
| 106 return "_StartingWorker"; | 133 return "_StartingWorker"; |
| 107 case EmbeddedWorkerStatus::RUNNING: | 134 case Preparation::RUNNING: |
| 108 return "_RunningWorker"; | 135 return "_RunningWorker"; |
| 109 case EmbeddedWorkerStatus::STOPPING: | 136 case Preparation::STOPPING: |
| 110 return "_StoppingWorker"; | 137 return "_StoppingWorker"; |
| 111 } | 138 } |
| 112 NOTREACHED(); | 139 NOTREACHED(); |
| 113 return "_UNKNOWN"; | 140 return "_UNKNOWN"; |
| 114 } | 141 } |
| 115 | 142 |
| 116 std::string GetSiteSuffix(ServiceWorkerMetrics::Site site) { | 143 std::string GetSiteSuffix(ServiceWorkerMetrics::Site site) { |
| 117 switch (site) { | 144 switch (site) { |
| 118 case ServiceWorkerMetrics::Site::OTHER: | 145 case ServiceWorkerMetrics::Site::OTHER: |
| 119 case ServiceWorkerMetrics::Site::WITH_FETCH_HANDLER: | 146 case ServiceWorkerMetrics::Site::WITH_FETCH_HANDLER: |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.Timeout.StartPurpose", | 402 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.Timeout.StartPurpose", |
| 376 static_cast<int>(purpose), | 403 static_cast<int>(purpose), |
| 377 static_cast<int>(EventType::NUM_TYPES)); | 404 static_cast<int>(EventType::NUM_TYPES)); |
| 378 } | 405 } |
| 379 } | 406 } |
| 380 | 407 |
| 381 void ServiceWorkerMetrics::RecordStartWorkerTime(base::TimeDelta time, | 408 void ServiceWorkerMetrics::RecordStartWorkerTime(base::TimeDelta time, |
| 382 bool is_installed, | 409 bool is_installed, |
| 383 StartSituation start_situation, | 410 StartSituation start_situation, |
| 384 EventType purpose) { | 411 EventType purpose) { |
| 412 const std::string name = "ServiceWorker.StartWorker.Time"; | |
| 385 if (is_installed) { | 413 if (is_installed) { |
| 386 std::string name = "ServiceWorker.StartWorker.Time"; | |
| 387 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); | 414 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); |
| 388 RecordSuffixedMediumTimeHistogram( | 415 RecordSuffixedMediumTimeHistogram( |
| 389 name, StartSituationToSuffix(start_situation), time); | 416 name, StartSituationToSuffix(start_situation), time); |
| 390 RecordSuffixedMediumTimeHistogram( | 417 RecordSuffixedMediumTimeHistogram( |
| 391 "ServiceWorker.StartWorker.Time", | 418 name, |
| 392 StartSituationToSuffix(start_situation) + EventTypeToSuffix(purpose), | 419 StartSituationToSuffix(start_situation) + EventTypeToSuffix(purpose), |
| 393 time); | 420 time); |
| 394 } else { | 421 } else { |
| 395 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartNewWorker.Time", time); | 422 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); |
|
falken
2017/01/19 02:01:45
Oh, this was wrong!
| |
| 396 } | 423 } |
| 397 } | 424 } |
| 398 | 425 |
| 399 void ServiceWorkerMetrics::RecordActivatedWorkerPreparationTimeForMainFrame( | 426 void ServiceWorkerMetrics::RecordActivatedWorkerPreparationForMainFrame( |
| 400 base::TimeDelta time, | 427 base::TimeDelta time, |
| 401 EmbeddedWorkerStatus initial_worker_status, | 428 EmbeddedWorkerStatus initial_worker_status, |
| 402 StartSituation start_situation) { | 429 StartSituation start_situation, |
| 403 std::string name = | 430 bool did_navigation_preload) { |
| 431 // Record the worker preparation type. | |
| 432 WorkerPreparationType preparation = | |
| 433 GetWorkerPreparationType(initial_worker_status, start_situation); | |
| 434 const std::string kTypeName = | |
| 435 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Type"; | |
| 436 UMA_HISTOGRAM_ENUMERATION(kTypeName, static_cast<int>(preparation), | |
| 437 static_cast<int>(WorkerPreparationType::NUM_TYPES)); | |
| 438 if (did_navigation_preload) { | |
| 439 UMA_HISTOGRAM_ENUMERATION( | |
| 440 kTypeName + "_NavigationPreloadEnabled", static_cast<int>(preparation), | |
|
rkaplow
2017/01/19 01:37:53
this isn't quite right, we don't allow the MACRO u
falken
2017/01/19 01:43:03
Ah, I thought this was OK as long as the input is
rkaplow
2017/01/19 01:52:10
yeah - since you don't need it to be computed best
falken
2017/01/19 02:01:45
Done.
| |
| 441 static_cast<int>(WorkerPreparationType::NUM_TYPES)); | |
| 442 } | |
| 443 | |
| 444 // Record the preparation time. | |
| 445 const std::string kTimeName = | |
| 404 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time"; | 446 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time"; |
| 405 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); | 447 UMA_HISTOGRAM_MEDIUM_TIMES(kTimeName, time); |
| 448 | |
| 449 // Record the preparation time using the worker preparation suffix. | |
| 406 RecordSuffixedMediumTimeHistogram( | 450 RecordSuffixedMediumTimeHistogram( |
| 407 name, GetWorkerPreparationSuffix(initial_worker_status, start_situation), | 451 kTimeName, GetWorkerPreparationSuffix(preparation), time); |
| 408 time); | 452 |
| 453 // Record the preparation time using the navigation preload suffix. | |
| 454 if (did_navigation_preload) { | |
| 455 UMA_HISTOGRAM_MEDIUM_TIMES(kTimeName + "_NavigationPreloadEnabled", time); | |
| 456 // We're mostly interested in when the worker needed to start up. To avoid | |
| 457 // using too much memory, just log the the common case of startup in an | |
| 458 // existing process. | |
| 459 if (preparation == WorkerPreparationType::START_IN_EXISTING_PROCESS) { | |
| 460 UMA_HISTOGRAM_MEDIUM_TIMES(kTimeName + | |
| 461 GetWorkerPreparationSuffix(preparation) + | |
| 462 "_NavigationPreloadEnabled", | |
| 463 time); | |
| 464 } | |
| 465 } | |
| 409 } | 466 } |
| 410 | 467 |
| 411 void ServiceWorkerMetrics::RecordWorkerStopped(StopStatus status) { | 468 void ServiceWorkerMetrics::RecordWorkerStopped(StopStatus status) { |
| 412 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.WorkerStopped", | 469 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.WorkerStopped", |
| 413 static_cast<int>(status), | 470 static_cast<int>(status), |
| 414 static_cast<int>(StopStatus::NUM_TYPES)); | 471 static_cast<int>(StopStatus::NUM_TYPES)); |
| 415 } | 472 } |
| 416 | 473 |
| 417 void ServiceWorkerMetrics::RecordStopWorkerTime(base::TimeDelta time) { | 474 void ServiceWorkerMetrics::RecordStopWorkerTime(base::TimeDelta time) { |
| 418 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StopWorker.Time", time); | 475 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StopWorker.Time", time); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 } else { | 851 } else { |
| 795 UMA_HISTOGRAM_ENUMERATION( | 852 UMA_HISTOGRAM_ENUMERATION( |
| 796 "ServiceWorker.ContextRequestHandlerStatus.NewWorker." | 853 "ServiceWorker.ContextRequestHandlerStatus.NewWorker." |
| 797 "ImportedScript", | 854 "ImportedScript", |
| 798 value, max); | 855 value, max); |
| 799 } | 856 } |
| 800 } | 857 } |
| 801 } | 858 } |
| 802 | 859 |
| 803 } // namespace content | 860 } // namespace content |
| OLD | NEW |