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 "remoting/base/rate_counter.h"
10 #include "remoting/base/running_average.h"
18 // PerformanceTracker defines a bundle of performance counters and statistics
20 class PerformanceTracker
{
22 // Callback that updates UMA custom counts or custom times histograms.
23 typedef base::Callback
<void(const std::string
& histogram_name
,
27 int histogram_buckets
)>
28 UpdateUmaCustomHistogramCallback
;
30 // Callback that updates UMA enumeration histograms.
31 typedef base::Callback
<
32 void(const std::string
& histogram_name
, int64 value
, int histogram_max
)>
33 UpdateUmaEnumHistogramCallback
;
36 virtual ~PerformanceTracker();
38 // Constant used to calculate the average for rate metrics and used by the
39 // plugin for the frequency at which stats should be updated.
40 static const int kStatsUpdateFrequencyInSeconds
= 1;
42 // Return rates and running-averages for different metrics.
43 double video_bandwidth() { return video_bandwidth_
.Rate(); }
44 double video_frame_rate() { return video_frame_rate_
.Rate(); }
45 double video_packet_rate() { return video_packet_rate_
.Rate(); }
46 double video_capture_ms() { return video_capture_ms_
.Average(); }
47 double video_encode_ms() { return video_encode_ms_
.Average(); }
48 double video_decode_ms() { return video_decode_ms_
.Average(); }
49 double video_paint_ms() { return video_paint_ms_
.Average(); }
50 double round_trip_ms() { return round_trip_ms_
.Average(); }
52 // Record stats for a video-packet.
53 void RecordVideoPacketStats(const VideoPacket
& packet
);
55 void RecordDecodeTime(double value
);
56 void RecordPaintTime(double value
);
58 // Sets callbacks in ChromotingInstance to update a UMA custom counts, custom
59 // times or enum histogram.
60 void SetUpdateUmaCallbacks(
61 UpdateUmaCustomHistogramCallback update_uma_custom_counts_callback
,
62 UpdateUmaCustomHistogramCallback update_uma_custom_times_callback
,
63 UpdateUmaEnumHistogramCallback update_uma_enum_histogram_callback
);
65 // Updates frame-rate, packet-rate and bandwidth UMA statistics.
66 void UploadRateStatsToUma();
69 // The video and packet rate metrics below are updated per video packet
70 // received and then, for reporting, averaged over a 1s time-window.
71 // Bytes per second for non-empty video-packets.
72 RateCounter video_bandwidth_
;
74 // Frames per second for non-empty video-packets.
75 RateCounter video_frame_rate_
;
77 // Video packets per second, including empty video-packets.
78 // This will be greater than the frame rate, as individual frames are
79 // contained in packets, some of which might be empty (e.g. when there are no
81 RateCounter video_packet_rate_
;
83 // The following running-averages are uploaded to UMA per video packet and
84 // also used for display to users, averaged over the N most recent samples.
85 // N = kLatencySampleSize.
86 RunningAverage video_capture_ms_
;
87 RunningAverage video_encode_ms_
;
88 RunningAverage video_decode_ms_
;
89 RunningAverage video_paint_ms_
;
90 RunningAverage round_trip_ms_
;
92 // Used to update UMA stats, if set.
93 UpdateUmaCustomHistogramCallback uma_custom_counts_updater_
;
94 UpdateUmaCustomHistogramCallback uma_custom_times_updater_
;
95 UpdateUmaEnumHistogramCallback uma_enum_histogram_updater_
;
97 // The latest input timestamp that a VideoPacket was seen annotated with.
98 int64 latest_input_event_timestamp_
= 0;
100 DISALLOW_COPY_AND_ASSIGN(PerformanceTracker
);
103 } // namespace protocol
104 } // namespace remoting
106 #endif // REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_