OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMECAST_BASE_METRICS_CAST_METRICS_HELPER_H_ |
| 6 #define CHROMECAST_BASE_METRICS_CAST_METRICS_HELPER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/time/time.h" |
| 12 |
| 13 namespace base { |
| 14 class MessageLoopProxy; |
| 15 } |
| 16 |
| 17 namespace chromecast { |
| 18 namespace metrics { |
| 19 |
| 20 // Helper class for tracking complex metrics. This particularly includes |
| 21 // playback metrics that span events across time, such as "time from app launch |
| 22 // to video being rendered." |
| 23 class CastMetricsHelper { |
| 24 public: |
| 25 enum BufferingType { |
| 26 kInitialBuffering, |
| 27 kBufferingAfterUnderrun, |
| 28 kAbortedBuffering, |
| 29 }; |
| 30 |
| 31 class MetricsSink { |
| 32 public: |
| 33 virtual ~MetricsSink() {} |
| 34 |
| 35 virtual void OnEnumerationEvent(const std::string& name, |
| 36 int value, int num_buckets) = 0; |
| 37 virtual void OnTimeEvent(const std::string& name, |
| 38 const base::TimeDelta& value, |
| 39 const base::TimeDelta& min, |
| 40 const base::TimeDelta& max, |
| 41 int num_buckets) = 0; |
| 42 }; |
| 43 |
| 44 static CastMetricsHelper* GetInstance(); |
| 45 |
| 46 explicit CastMetricsHelper( |
| 47 scoped_refptr<base::MessageLoopProxy> message_loop_proxy); |
| 48 virtual ~CastMetricsHelper(); |
| 49 |
| 50 // This function stores the name and startup time of the active application. |
| 51 virtual void TagAppStart(const std::string& app_name); |
| 52 |
| 53 // Logs UMA record for media play/pause user actions. |
| 54 virtual void LogMediaPlay(); |
| 55 virtual void LogMediaPause(); |
| 56 |
| 57 // Logs UMA record of the elapsed time from the app launch |
| 58 // to the time first video frame is displayed. |
| 59 virtual void LogTimeToDisplayVideo(); |
| 60 |
| 61 // Logs UMA record of the time needed to re-buffer A/V. |
| 62 virtual void LogTimeToBufferAv(BufferingType buffering_type, |
| 63 base::TimeDelta time); |
| 64 |
| 65 virtual void ResetVideoFrameSampling(); |
| 66 |
| 67 // Logs UMA statistics for video decoder and rendering data. |
| 68 // Negative values are considered invalid and will not be logged. |
| 69 virtual void LogFramesPer5Seconds(int displayed_frames, int dropped_frames, |
| 70 int delayed_frames, int error_frames); |
| 71 |
| 72 // Returns metrics name with app name between prefix and suffix. |
| 73 virtual std::string GetMetricsNameWithAppName( |
| 74 const std::string& prefix, |
| 75 const std::string& suffix) const; |
| 76 |
| 77 // Provides a MetricsSink instance to delegate UMA event logging. |
| 78 // Once the delegate interface is set, CastMetricsHelper will not log UMA |
| 79 // events internally unless SetMetricsSink(NULL) is called. |
| 80 // CastMetricsHelper can only hold one MetricsSink instance. |
| 81 // Caller retains ownership of MetricsSink. |
| 82 virtual void SetMetricsSink(MetricsSink* delegate); |
| 83 |
| 84 protected: |
| 85 // Creates a CastMetricsHelper instance with no MessageLoopProxy. This should |
| 86 // only be used by tests, since invoking any non-overridden methods on this |
| 87 // instance will cause a failure. |
| 88 CastMetricsHelper(); |
| 89 |
| 90 private: |
| 91 void LogEnumerationHistogramEvent(const std::string& name, |
| 92 int value, int num_buckets); |
| 93 void LogTimeHistogramEvent(const std::string& name, |
| 94 const base::TimeDelta& value, |
| 95 const base::TimeDelta& min, |
| 96 const base::TimeDelta& max, |
| 97 int num_buckets); |
| 98 void LogMediumTimeHistogramEvent(const std::string& name, |
| 99 const base::TimeDelta& value); |
| 100 |
| 101 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 102 |
| 103 // Start time of the most recent app. |
| 104 base::TimeTicks app_start_time_; |
| 105 |
| 106 // Currently running app name. Used to construct histogram name. |
| 107 std::string app_name_; |
| 108 |
| 109 // Whether a new app start time has been stored but not recorded. |
| 110 // After the startup time has been used to generate an UMA event, |
| 111 // this is set to false. |
| 112 bool new_startup_time_; |
| 113 |
| 114 base::TimeTicks previous_video_stat_sample_time_; |
| 115 |
| 116 MetricsSink* metrics_sink_; |
| 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(CastMetricsHelper); |
| 119 }; |
| 120 |
| 121 } // namespace metrics |
| 122 } // namespace chromecast |
| 123 |
| 124 #endif // CHROMECAST_BASE_METRICS_CAST_METRICS_HELPER_H_ |
OLD | NEW |