Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: content/browser/service_worker/service_worker_metrics.cc

Issue 2641813002: Add UMA for service worker navigation preload. (Closed)
Patch Set: patch for landing Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 case ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST: 81 case ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST:
82 return "_EXTERNAL_REQUEST"; 82 return "_EXTERNAL_REQUEST";
83 case ServiceWorkerMetrics::EventType::PAYMENT_REQUEST: 83 case ServiceWorkerMetrics::EventType::PAYMENT_REQUEST:
84 return "_PAYMENT_REQUEST"; 84 return "_PAYMENT_REQUEST";
85 case ServiceWorkerMetrics::EventType::NUM_TYPES: 85 case ServiceWorkerMetrics::EventType::NUM_TYPES:
86 NOTREACHED() << static_cast<int>(event_type); 86 NOTREACHED() << static_cast<int>(event_type);
87 } 87 }
88 return "_UNKNOWN"; 88 return "_UNKNOWN";
89 } 89 }
90 90
91 std::string GetWorkerPreparationSuffix( 91 ServiceWorkerMetrics::WorkerPreparationType GetWorkerPreparationType(
92 EmbeddedWorkerStatus initial_worker_status, 92 EmbeddedWorkerStatus initial_worker_status,
93 ServiceWorkerMetrics::StartSituation start_situation) { 93 ServiceWorkerMetrics::StartSituation start_situation) {
94 using Situation = ServiceWorkerMetrics::StartSituation;
95 using Preparation = ServiceWorkerMetrics::WorkerPreparationType;
94 switch (initial_worker_status) { 96 switch (initial_worker_status) {
95 case EmbeddedWorkerStatus::STOPPED: { 97 case EmbeddedWorkerStatus::STOPPED: {
96 switch (start_situation) { 98 switch (start_situation) {
97 case ServiceWorkerMetrics::StartSituation::DURING_STARTUP: 99 case Situation::DURING_STARTUP:
98 return "_StartWorkerDuringStartup"; 100 return Preparation::START_DURING_STARTUP;
99 case ServiceWorkerMetrics::StartSituation::NEW_PROCESS: 101 case Situation::NEW_PROCESS:
100 return "_StartWorkerNewProcess"; 102 return Preparation::START_IN_NEW_PROCESS;
101 case ServiceWorkerMetrics::StartSituation::EXISTING_PROCESS: 103 case Situation::EXISTING_PROCESS:
102 return "_StartWorkerExistingProcess"; 104 return Preparation::START_IN_EXISTING_PROCESS;
103 default: 105 case Situation::UNKNOWN:
104 NOTREACHED() << static_cast<int>(start_situation); 106 break;
105 } 107 }
108 break;
106 } 109 }
107 case EmbeddedWorkerStatus::STARTING: 110 case EmbeddedWorkerStatus::STARTING:
111 return Preparation::STARTING;
112 case EmbeddedWorkerStatus::RUNNING:
113 return Preparation::RUNNING;
114 case EmbeddedWorkerStatus::STOPPING:
115 return Preparation::STOPPING;
116 }
117 NOTREACHED() << static_cast<int>(initial_worker_status);
118 return Preparation::UNKNOWN;
119 }
120
121 std::string GetWorkerPreparationSuffix(
122 ServiceWorkerMetrics::WorkerPreparationType status) {
123 using Preparation = ServiceWorkerMetrics::WorkerPreparationType;
124 switch (status) {
125 case Preparation::UNKNOWN:
126 case Preparation::NUM_TYPES:
127 break;
128 case Preparation::START_DURING_STARTUP:
129 return "_StartWorkerDuringStartup";
130 case Preparation::START_IN_NEW_PROCESS:
131 return "_StartWorkerNewProcess";
132 case Preparation::START_IN_EXISTING_PROCESS:
133 return "_StartWorkerExistingProcess";
134 case Preparation::STARTING:
108 return "_StartingWorker"; 135 return "_StartingWorker";
109 case EmbeddedWorkerStatus::RUNNING: 136 case Preparation::RUNNING:
110 return "_RunningWorker"; 137 return "_RunningWorker";
111 case EmbeddedWorkerStatus::STOPPING: 138 case Preparation::STOPPING:
112 return "_StoppingWorker"; 139 return "_StoppingWorker";
113 } 140 }
114 NOTREACHED(); 141 NOTREACHED();
115 return "_UNKNOWN"; 142 return "_UNKNOWN";
116 } 143 }
117 144
118 std::string GetSiteSuffix(ServiceWorkerMetrics::Site site) { 145 std::string GetSiteSuffix(ServiceWorkerMetrics::Site site) {
119 switch (site) { 146 switch (site) {
120 case ServiceWorkerMetrics::Site::OTHER: 147 case ServiceWorkerMetrics::Site::OTHER:
121 case ServiceWorkerMetrics::Site::WITH_FETCH_HANDLER: 148 case ServiceWorkerMetrics::Site::WITH_FETCH_HANDLER:
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 static_cast<int>(purpose), 407 static_cast<int>(purpose),
381 static_cast<int>(EventType::NUM_TYPES)); 408 static_cast<int>(EventType::NUM_TYPES));
382 } 409 }
383 } 410 }
384 411
385 void ServiceWorkerMetrics::RecordStartWorkerTime(base::TimeDelta time, 412 void ServiceWorkerMetrics::RecordStartWorkerTime(base::TimeDelta time,
386 bool is_installed, 413 bool is_installed,
387 StartSituation start_situation, 414 StartSituation start_situation,
388 EventType purpose) { 415 EventType purpose) {
389 if (is_installed) { 416 if (is_installed) {
390 std::string name = "ServiceWorker.StartWorker.Time"; 417 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartWorker.Time", time);
391 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); 418 RecordSuffixedMediumTimeHistogram("ServiceWorker.StartWorker.Time",
392 RecordSuffixedMediumTimeHistogram( 419 StartSituationToSuffix(start_situation),
393 name, StartSituationToSuffix(start_situation), time); 420 time);
394 RecordSuffixedMediumTimeHistogram( 421 RecordSuffixedMediumTimeHistogram(
395 "ServiceWorker.StartWorker.Time", 422 "ServiceWorker.StartWorker.Time",
396 StartSituationToSuffix(start_situation) + EventTypeToSuffix(purpose), 423 StartSituationToSuffix(start_situation) + EventTypeToSuffix(purpose),
397 time); 424 time);
398 } else { 425 } else {
399 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartNewWorker.Time", time); 426 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartNewWorker.Time", time);
400 } 427 }
401 } 428 }
402 429
403 void ServiceWorkerMetrics::RecordActivatedWorkerPreparationTimeForMainFrame( 430 void ServiceWorkerMetrics::RecordActivatedWorkerPreparationForMainFrame(
404 base::TimeDelta time, 431 base::TimeDelta time,
405 EmbeddedWorkerStatus initial_worker_status, 432 EmbeddedWorkerStatus initial_worker_status,
406 StartSituation start_situation) { 433 StartSituation start_situation,
407 std::string name = 434 bool did_navigation_preload) {
408 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time"; 435 // Record the worker preparation type.
409 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); 436 WorkerPreparationType preparation =
437 GetWorkerPreparationType(initial_worker_status, start_situation);
438 UMA_HISTOGRAM_ENUMERATION(
439 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Type",
440 static_cast<int>(preparation),
441 static_cast<int>(WorkerPreparationType::NUM_TYPES));
442 if (did_navigation_preload) {
443 UMA_HISTOGRAM_ENUMERATION(
444 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Type_"
445 "NavigationPreloadEnabled",
446 static_cast<int>(preparation),
447 static_cast<int>(WorkerPreparationType::NUM_TYPES));
448 }
449
450 // Record the preparation time.
451 UMA_HISTOGRAM_MEDIUM_TIMES(
452 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time", time);
453
454 // Record the preparation time using the worker preparation suffix.
410 RecordSuffixedMediumTimeHistogram( 455 RecordSuffixedMediumTimeHistogram(
411 name, GetWorkerPreparationSuffix(initial_worker_status, start_situation), 456 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time",
412 time); 457 GetWorkerPreparationSuffix(preparation), time);
458
459 // Record the preparation time using the navigation preload suffix.
460 if (did_navigation_preload) {
461 UMA_HISTOGRAM_MEDIUM_TIMES(
462 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time_"
463 "NavigationPreloadEnabled",
464 time);
465 // We're mostly interested in when the worker needed to start up. To avoid
466 // using too much memory, just log the the common case of startup in an
467 // existing process.
468 if (preparation == WorkerPreparationType::START_IN_EXISTING_PROCESS) {
469 UMA_HISTOGRAM_MEDIUM_TIMES(
470 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time_"
471 "StartWorkerExistingProcess_NavigationPreloadEnabled",
472 time);
473 }
474 }
413 } 475 }
414 476
415 void ServiceWorkerMetrics::RecordWorkerStopped(StopStatus status) { 477 void ServiceWorkerMetrics::RecordWorkerStopped(StopStatus status) {
416 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.WorkerStopped", 478 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.WorkerStopped",
417 static_cast<int>(status), 479 static_cast<int>(status),
418 static_cast<int>(StopStatus::NUM_TYPES)); 480 static_cast<int>(StopStatus::NUM_TYPES));
419 } 481 }
420 482
421 void ServiceWorkerMetrics::RecordStopWorkerTime(base::TimeDelta time) { 483 void ServiceWorkerMetrics::RecordStopWorkerTime(base::TimeDelta time) {
422 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StopWorker.Time", time); 484 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StopWorker.Time", time);
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 } else { 864 } else {
803 UMA_HISTOGRAM_ENUMERATION( 865 UMA_HISTOGRAM_ENUMERATION(
804 "ServiceWorker.ContextRequestHandlerStatus.NewWorker." 866 "ServiceWorker.ContextRequestHandlerStatus.NewWorker."
805 "ImportedScript", 867 "ImportedScript",
806 value, max); 868 value, max);
807 } 869 }
808 } 870 }
809 } 871 }
810 872
811 } // namespace content 873 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698