1 // Copyright 2015 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.
5 #ifndef REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_
6 #define REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_
8 #include "base/callback.h"
9 #include "base/timer/timer.h"
10 #include "remoting/base/rate_counter.h"
11 #include "remoting/base/running_average.h"
19 // PerformanceTracker defines a bundle of performance counters and statistics
21 class PerformanceTracker
{
23 // Callback that updates UMA custom counts or custom times histograms.
24 typedef base::Callback
<void(const std::string
& histogram_name
,
28 int histogram_buckets
)>
29 UpdateUmaCustomHistogramCallback
;
31 // Callback that updates UMA enumeration histograms.
32 typedef base::Callback
<
33 void(const std::string
& histogram_name
, int64 value
, int histogram_max
)>
34 UpdateUmaEnumHistogramCallback
;
37 virtual ~PerformanceTracker();
39 // Constant used to calculate the average for rate metrics and used by the
40 // plugin for the frequency at which stats should be updated.
41 static const int kStatsUpdatePeriodSeconds
= 1;
43 // Return rates and running-averages for different metrics.
44 double video_bandwidth() { return video_bandwidth_
.Rate(); }
45 double video_frame_rate() { return video_frame_rate_
.Rate(); }
46 double video_packet_rate() { return video_packet_rate_
.Rate(); }
47 double video_capture_ms() { return video_capture_ms_
.Average(); }
48 double video_encode_ms() { return video_encode_ms_
.Average(); }
49 double video_decode_ms() { return video_decode_ms_
.Average(); }
50 double video_paint_ms() { return video_paint_ms_
.Average(); }
51 double round_trip_ms() { return round_trip_ms_
.Average(); }
53 // Record stats for a video-packet.
54 void RecordVideoPacketStats(const VideoPacket
& packet
);
56 void RecordDecodeTime(double value
);
57 void RecordPaintTime(double value
);
59 // Sets callbacks in ChromotingInstance to update a UMA custom counts, custom
60 // times or enum histogram.
61 void SetUpdateUmaCallbacks(
62 UpdateUmaCustomHistogramCallback update_uma_custom_counts_callback
,
63 UpdateUmaCustomHistogramCallback update_uma_custom_times_callback
,
64 UpdateUmaEnumHistogramCallback update_uma_enum_histogram_callback
);
66 void OnPauseStateChanged(bool paused
);
69 // Updates frame-rate, packet-rate and bandwidth UMA statistics.
70 void UploadRateStatsToUma();
72 // The video and packet rate metrics below are updated per video packet
73 // received and then, for reporting, averaged over a 1s time-window.
74 // Bytes per second for non-empty video-packets.
75 RateCounter video_bandwidth_
;
77 // Frames per second for non-empty video-packets.
78 RateCounter video_frame_rate_
;
80 // Video packets per second, including empty video-packets.
81 // This will be greater than the frame rate, as individual frames are
82 // contained in packets, some of which might be empty (e.g. when there are no
84 RateCounter video_packet_rate_
;
86 // The following running-averages are uploaded to UMA per video packet and
87 // also used for display to users, averaged over the N most recent samples.
88 // N = kLatencySampleSize.
89 RunningAverage video_capture_ms_
;
90 RunningAverage video_encode_ms_
;
91 RunningAverage video_decode_ms_
;
92 RunningAverage video_paint_ms_
;
93 RunningAverage round_trip_ms_
;
95 // Used to update UMA stats, if set.
96 UpdateUmaCustomHistogramCallback uma_custom_counts_updater_
;
97 UpdateUmaCustomHistogramCallback uma_custom_times_updater_
;
98 UpdateUmaEnumHistogramCallback uma_enum_histogram_updater_
;
100 // The latest input timestamp that a VideoPacket was seen annotated with.
101 int64_t latest_input_event_timestamp_
= 0;
103 bool is_paused_
= false;
105 base::RepeatingTimer
<PerformanceTracker
> upload_uma_stats_timer_
;
107 DISALLOW_COPY_AND_ASSIGN(PerformanceTracker
);
110 } // namespace protocol
111 } // namespace remoting
113 #endif // REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_