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

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

Issue 2218943002: Introduce ServiceWorker.EventDispatchingDelay UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated mpearson@'s comment Created 4 years, 4 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"
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 "base/time/time.h"
13 #include "content/browser/service_worker/embedded_worker_status.h" 14 #include "content/browser/service_worker/embedded_worker_status.h"
14 #include "content/common/service_worker/service_worker_types.h" 15 #include "content/common/service_worker/service_worker_types.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/content_browser_client.h" 17 #include "content/public/browser/content_browser_client.h"
17 #include "content/public/common/content_client.h" 18 #include "content/public/common/content_client.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 namespace { 22 namespace {
22 23
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return "_StartingWorker"; 104 return "_StartingWorker";
104 case EmbeddedWorkerStatus::RUNNING: 105 case EmbeddedWorkerStatus::RUNNING:
105 return "_RunningWorker"; 106 return "_RunningWorker";
106 case EmbeddedWorkerStatus::STOPPING: 107 case EmbeddedWorkerStatus::STOPPING:
107 return "_StoppingWorker"; 108 return "_StoppingWorker";
108 } 109 }
109 NOTREACHED(); 110 NOTREACHED();
110 return "_UNKNOWN"; 111 return "_UNKNOWN";
111 } 112 }
112 113
114 std::string GetSiteSuffix(ServiceWorkerMetrics::Site site) {
115 switch (site) {
116 case ServiceWorkerMetrics::Site::OTHER:
117 case ServiceWorkerMetrics::Site::WITH_FETCH_HANDLER:
118 case ServiceWorkerMetrics::Site::WITHOUT_FETCH_HANDLER:
119 return "";
120 case ServiceWorkerMetrics::Site::NEW_TAB_PAGE:
121 return ".ntp";
122 case ServiceWorkerMetrics::Site::PLUS:
123 return ".plus";
124 case ServiceWorkerMetrics::Site::INBOX:
125 return ".inbox";
126 case ServiceWorkerMetrics::Site::DOCS:
127 return ".docs";
128 case ServiceWorkerMetrics::Site::NUM_TYPES:
129 NOTREACHED() << static_cast<int>(site);
130 }
131 NOTREACHED();
132 return "";
133 }
134
113 // Use this for histograms with dynamically generated names, which 135 // Use this for histograms with dynamically generated names, which
114 // otherwise can't use the UMA_HISTOGRAM macro without code duplication. 136 // otherwise can't use the UMA_HISTOGRAM macro without code duplication.
115 void RecordSuffixedTimeHistogram(const std::string& name, 137 void RecordSuffixedTimeHistogram(const std::string& name,
116 const std::string& suffix, 138 const std::string& suffix,
117 base::TimeDelta sample) { 139 base::TimeDelta sample) {
118 const std::string name_with_suffix = name + suffix; 140 const std::string name_with_suffix = name + suffix;
141 // This unrolls UMA_HISTOGRAM_TIMES.
142 base::HistogramBase* histogram_pointer = base::Histogram::FactoryTimeGet(
143 name_with_suffix, base::TimeDelta::FromMilliseconds(1),
144 base::TimeDelta::FromSeconds(10), 50,
145 base::HistogramBase::kUmaTargetedHistogramFlag);
146 histogram_pointer->AddTime(sample);
147 }
148
149 // Use this for histograms with dynamically generated names, which
150 // otherwise can't use the UMA_MEDIUM_HISTOGRAM macro without code duplication.
151 void RecordSuffixedMediumTimeHistogram(const std::string& name,
152 const std::string& suffix,
153 base::TimeDelta sample) {
154 const std::string name_with_suffix = name + suffix;
119 // This unrolls UMA_HISTOGRAM_MEDIUM_TIMES. 155 // This unrolls UMA_HISTOGRAM_MEDIUM_TIMES.
120 base::HistogramBase* histogram_pointer = base::Histogram::FactoryTimeGet( 156 base::HistogramBase* histogram_pointer = base::Histogram::FactoryTimeGet(
121 name_with_suffix, base::TimeDelta::FromMilliseconds(10), 157 name_with_suffix, base::TimeDelta::FromMilliseconds(10),
122 base::TimeDelta::FromMinutes(3), 50, 158 base::TimeDelta::FromMinutes(3), 50,
123 base::HistogramBase::kUmaTargetedHistogramFlag); 159 base::HistogramBase::kUmaTargetedHistogramFlag);
124 histogram_pointer->AddTime(sample); 160 histogram_pointer->AddTime(sample);
125 } 161 }
126 162
127 // Use this for histograms with dynamically generated names, which 163 // Use this for histograms with dynamically generated names, which
128 // otherwise can't use the UMA_HISTOGRAM macro without code duplication. 164 // otherwise can't use the UMA_HISTOGRAM macro without code duplication.
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 359 }
324 } 360 }
325 361
326 void ServiceWorkerMetrics::RecordStartWorkerTime(base::TimeDelta time, 362 void ServiceWorkerMetrics::RecordStartWorkerTime(base::TimeDelta time,
327 bool is_installed, 363 bool is_installed,
328 StartSituation start_situation, 364 StartSituation start_situation,
329 EventType purpose) { 365 EventType purpose) {
330 if (is_installed) { 366 if (is_installed) {
331 std::string name = "ServiceWorker.StartWorker.Time"; 367 std::string name = "ServiceWorker.StartWorker.Time";
332 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); 368 UMA_HISTOGRAM_MEDIUM_TIMES(name, time);
333 RecordSuffixedTimeHistogram(name, StartSituationToSuffix(start_situation), 369 RecordSuffixedMediumTimeHistogram(
334 time); 370 name, StartSituationToSuffix(start_situation), time);
335 RecordSuffixedTimeHistogram( 371 RecordSuffixedMediumTimeHistogram(
336 "ServiceWorker.StartWorker.Time", 372 "ServiceWorker.StartWorker.Time",
337 StartSituationToSuffix(start_situation) + EventTypeToSuffix(purpose), 373 StartSituationToSuffix(start_situation) + EventTypeToSuffix(purpose),
338 time); 374 time);
339 } else { 375 } else {
340 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartNewWorker.Time", time); 376 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartNewWorker.Time", time);
341 } 377 }
342 } 378 }
343 379
344 void ServiceWorkerMetrics::RecordActivatedWorkerPreparationTimeForMainFrame( 380 void ServiceWorkerMetrics::RecordActivatedWorkerPreparationTimeForMainFrame(
345 base::TimeDelta time, 381 base::TimeDelta time,
346 EmbeddedWorkerStatus initial_worker_status, 382 EmbeddedWorkerStatus initial_worker_status,
347 StartSituation start_situation) { 383 StartSituation start_situation) {
348 std::string name = 384 std::string name =
349 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time"; 385 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time";
350 UMA_HISTOGRAM_MEDIUM_TIMES(name, time); 386 UMA_HISTOGRAM_MEDIUM_TIMES(name, time);
351 RecordSuffixedTimeHistogram( 387 RecordSuffixedMediumTimeHistogram(
352 name, GetWorkerPreparationSuffix(initial_worker_status, start_situation), 388 name, GetWorkerPreparationSuffix(initial_worker_status, start_situation),
353 time); 389 time);
354 } 390 }
355 391
356 void ServiceWorkerMetrics::RecordWorkerStopped(StopStatus status) { 392 void ServiceWorkerMetrics::RecordWorkerStopped(StopStatus status) {
357 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.WorkerStopped", 393 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.WorkerStopped",
358 static_cast<int>(status), 394 static_cast<int>(status),
359 static_cast<int>(StopStatus::NUM_TYPES)); 395 static_cast<int>(StopStatus::NUM_TYPES));
360 } 396 }
361 397
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 UMA_HISTOGRAM_ENUMERATION( 456 UMA_HISTOGRAM_ENUMERATION(
421 "ServiceWorker.EventHandledRatioType.ForeignFetch", type, 457 "ServiceWorker.EventHandledRatioType.ForeignFetch", type,
422 NUM_EVENT_HANDLED_RATIO_TYPE); 458 NUM_EVENT_HANDLED_RATIO_TYPE);
423 break; 459 break;
424 default: 460 default:
425 // Do nothing. 461 // Do nothing.
426 break; 462 break;
427 } 463 }
428 } 464 }
429 465
466 void ServiceWorkerMetrics::RecordEventDispatchingDelay(EventType event_type,
467 base::TimeDelta time,
468 Site site_for_metrics) {
469 const std::string name = "ServiceWorker.EventDispatchingDelay";
470 UMA_HISTOGRAM_TIMES(name, time);
471 const std::string event_type_suffix = EventTypeToSuffix(event_type);
472 const std::string site_suffix = GetSiteSuffix(site_for_metrics);
473 RecordSuffixedTimeHistogram(name, event_type_suffix + site_suffix, time);
474 }
475
430 void ServiceWorkerMetrics::RecordNavigationHintPrecision( 476 void ServiceWorkerMetrics::RecordNavigationHintPrecision(
431 EventType start_worker_purpose, 477 EventType start_worker_purpose,
432 bool frame_fetch_event_fired) { 478 bool frame_fetch_event_fired) {
433 DCHECK(IsNavigationHintEvent(start_worker_purpose)); 479 DCHECK(IsNavigationHintEvent(start_worker_purpose));
434 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.NavigationHintPrecision", 480 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.NavigationHintPrecision",
435 frame_fetch_event_fired); 481 frame_fetch_event_fired);
436 switch (start_worker_purpose) { 482 switch (start_worker_purpose) {
437 case EventType::NAVIGATION_HINT_LINK_MOUSE_DOWN: 483 case EventType::NAVIGATION_HINT_LINK_MOUSE_DOWN:
438 UMA_HISTOGRAM_BOOLEAN( 484 UMA_HISTOGRAM_BOOLEAN(
439 "ServiceWorker.NavigationHintPrecision.LINK_MOUSE_DOWN", 485 "ServiceWorker.NavigationHintPrecision.LINK_MOUSE_DOWN",
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 void ServiceWorkerMetrics::RecordProcessCreated(bool is_new_process) { 627 void ServiceWorkerMetrics::RecordProcessCreated(bool is_new_process) {
582 UMA_HISTOGRAM_BOOLEAN("EmbeddedWorkerInstance.ProcessCreated", 628 UMA_HISTOGRAM_BOOLEAN("EmbeddedWorkerInstance.ProcessCreated",
583 is_new_process); 629 is_new_process);
584 } 630 }
585 631
586 void ServiceWorkerMetrics::RecordTimeToSendStartWorker( 632 void ServiceWorkerMetrics::RecordTimeToSendStartWorker(
587 base::TimeDelta duration, 633 base::TimeDelta duration,
588 StartSituation situation) { 634 StartSituation situation) {
589 std::string name = "EmbeddedWorkerInstance.Start.TimeToSendStartWorker"; 635 std::string name = "EmbeddedWorkerInstance.Start.TimeToSendStartWorker";
590 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration); 636 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration);
591 RecordSuffixedTimeHistogram(name, StartSituationToSuffix(situation), 637 RecordSuffixedMediumTimeHistogram(name, StartSituationToSuffix(situation),
592 duration); 638 duration);
593 } 639 }
594 640
595 void ServiceWorkerMetrics::RecordTimeToURLJob(base::TimeDelta duration, 641 void ServiceWorkerMetrics::RecordTimeToURLJob(base::TimeDelta duration,
596 StartSituation situation) { 642 StartSituation situation) {
597 std::string name = "EmbeddedWorkerInstance.Start.TimeToURLJob"; 643 std::string name = "EmbeddedWorkerInstance.Start.TimeToURLJob";
598 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration); 644 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration);
599 RecordSuffixedTimeHistogram(name, StartSituationToSuffix(situation), 645 RecordSuffixedMediumTimeHistogram(name, StartSituationToSuffix(situation),
600 duration); 646 duration);
601 } 647 }
602 648
603 void ServiceWorkerMetrics::RecordTimeToLoad(base::TimeDelta duration, 649 void ServiceWorkerMetrics::RecordTimeToLoad(base::TimeDelta duration,
604 LoadSource source, 650 LoadSource source,
605 StartSituation situation) { 651 StartSituation situation) {
606 std::string name; 652 std::string name;
607 switch (source) { 653 switch (source) {
608 case LoadSource::NETWORK: 654 case LoadSource::NETWORK:
609 name = "EmbeddedWorkerInstance.Start.TimeToLoad.Network"; 655 name = "EmbeddedWorkerInstance.Start.TimeToLoad.Network";
610 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration); 656 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration);
611 RecordSuffixedTimeHistogram(name, StartSituationToSuffix(situation), 657 RecordSuffixedMediumTimeHistogram(name, StartSituationToSuffix(situation),
612 duration); 658 duration);
613 break; 659 break;
614 case LoadSource::HTTP_CACHE: 660 case LoadSource::HTTP_CACHE:
615 name = "EmbeddedWorkerInstance.Start.TimeToLoad.HttpCache"; 661 name = "EmbeddedWorkerInstance.Start.TimeToLoad.HttpCache";
616 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration); 662 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration);
617 RecordSuffixedTimeHistogram(name, StartSituationToSuffix(situation), 663 RecordSuffixedMediumTimeHistogram(name, StartSituationToSuffix(situation),
618 duration); 664 duration);
619 break; 665 break;
620 case LoadSource::SERVICE_WORKER_STORAGE: 666 case LoadSource::SERVICE_WORKER_STORAGE:
621 name = "EmbeddedWorkerInstance.Start.TimeToLoad.InstalledScript"; 667 name = "EmbeddedWorkerInstance.Start.TimeToLoad.InstalledScript";
622 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration); 668 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration);
623 RecordSuffixedTimeHistogram(name, StartSituationToSuffix(situation), 669 RecordSuffixedMediumTimeHistogram(name, StartSituationToSuffix(situation),
624 duration); 670 duration);
625 break; 671 break;
626 default: 672 default:
627 NOTREACHED() << static_cast<int>(source); 673 NOTREACHED() << static_cast<int>(source);
628 } 674 }
629 } 675 }
630 676
631 void ServiceWorkerMetrics::RecordTimeToStartThread(base::TimeDelta duration, 677 void ServiceWorkerMetrics::RecordTimeToStartThread(base::TimeDelta duration,
632 StartSituation situation) { 678 StartSituation situation) {
633 std::string name = "EmbeddedWorkerInstance.Start.TimeToStartThread"; 679 std::string name = "EmbeddedWorkerInstance.Start.TimeToStartThread";
634 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration); 680 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration);
635 RecordSuffixedTimeHistogram(name, StartSituationToSuffix(situation), 681 RecordSuffixedMediumTimeHistogram(name, StartSituationToSuffix(situation),
636 duration); 682 duration);
637 } 683 }
638 684
639 void ServiceWorkerMetrics::RecordTimeToEvaluateScript( 685 void ServiceWorkerMetrics::RecordTimeToEvaluateScript(
640 base::TimeDelta duration, 686 base::TimeDelta duration,
641 StartSituation situation) { 687 StartSituation situation) {
642 std::string name = "EmbeddedWorkerInstance.Start.TimeToEvaluateScript"; 688 std::string name = "EmbeddedWorkerInstance.Start.TimeToEvaluateScript";
643 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration); 689 UMA_HISTOGRAM_MEDIUM_TIMES(name, duration);
644 RecordSuffixedTimeHistogram(name, StartSituationToSuffix(situation), 690 RecordSuffixedMediumTimeHistogram(name, StartSituationToSuffix(situation),
645 duration); 691 duration);
646 } 692 }
647 693
648 const char* ServiceWorkerMetrics::LoadSourceToString(LoadSource source) { 694 const char* ServiceWorkerMetrics::LoadSourceToString(LoadSource source) {
649 switch (source) { 695 switch (source) {
650 case LoadSource::NETWORK: 696 case LoadSource::NETWORK:
651 return "Network"; 697 return "Network";
652 case LoadSource::HTTP_CACHE: 698 case LoadSource::HTTP_CACHE:
653 return "HTTP cache"; 699 return "HTTP cache";
654 case LoadSource::SERVICE_WORKER_STORAGE: 700 case LoadSource::SERVICE_WORKER_STORAGE:
655 return "Service worker storage"; 701 return "Service worker storage";
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 } else if (failure_count == 2) { 733 } else if (failure_count == 2) {
688 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_2", 734 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_2",
689 status, SERVICE_WORKER_ERROR_MAX_VALUE); 735 status, SERVICE_WORKER_ERROR_MAX_VALUE);
690 } else if (failure_count == 3) { 736 } else if (failure_count == 3) {
691 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_3", 737 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_3",
692 status, SERVICE_WORKER_ERROR_MAX_VALUE); 738 status, SERVICE_WORKER_ERROR_MAX_VALUE);
693 } 739 }
694 } 740 }
695 741
696 } // namespace content 742 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_metrics.h ('k') | content/browser/service_worker/service_worker_register_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698