sergeyu | aa1f0239 | 2015-09-17 00:45:24 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
sergeyu | aa1f0239 | 2015-09-17 00:45:24 | [diff] [blame] | 5 | #ifndef REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ |
| 6 | #define REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 7 | |
avi | 5a080f01 | 2015-12-22 23:15:43 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 10 | #include "base/callback.h" |
avi | 5a080f01 | 2015-12-22 23:15:43 | [diff] [blame] | 11 | #include "base/macros.h" |
sergeyu | 92dcbfc | 2015-09-21 18:43:01 | [diff] [blame] | 12 | #include "base/timer/timer.h" |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 13 | #include "remoting/base/rate_counter.h" |
yuweih | d2a0c5cb | 2016-03-23 22:41:05 | [diff] [blame] | 14 | #include "remoting/base/running_samples.h" |
sergeyu | 47dc4a53 | 2016-07-06 21:07:22 | [diff] [blame] | 15 | #include "remoting/protocol/frame_stats.h" |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 16 | |
| 17 | namespace remoting { |
sergeyu | aa1f0239 | 2015-09-17 00:45:24 | [diff] [blame] | 18 | namespace protocol { |
| 19 | |
| 20 | // PerformanceTracker defines a bundle of performance counters and statistics |
| 21 | // for chromoting. |
sergeyu | 47dc4a53 | 2016-07-06 21:07:22 | [diff] [blame] | 22 | class PerformanceTracker : public FrameStatsConsumer { |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 23 | public: |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 24 | // Callback that updates UMA custom counts or custom times histograms. |
| 25 | typedef base::Callback<void(const std::string& histogram_name, |
sergeyu | 752c6e6 | 2015-09-30 06:40:27 | [diff] [blame] | 26 | int64_t value, |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 27 | int histogram_min, |
| 28 | int histogram_max, |
| 29 | int histogram_buckets)> |
| 30 | UpdateUmaCustomHistogramCallback; |
| 31 | |
| 32 | // Callback that updates UMA enumeration histograms. |
| 33 | typedef base::Callback< |
sergeyu | 752c6e6 | 2015-09-30 06:40:27 | [diff] [blame] | 34 | void(const std::string& histogram_name, int64_t value, int histogram_max)> |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 35 | UpdateUmaEnumHistogramCallback; |
| 36 | |
sergeyu | aa1f0239 | 2015-09-17 00:45:24 | [diff] [blame] | 37 | PerformanceTracker(); |
sergeyu | 47dc4a53 | 2016-07-06 21:07:22 | [diff] [blame] | 38 | ~PerformanceTracker() override; |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 39 | |
anandc | b877083e | 2015-07-16 22:00:18 | [diff] [blame] | 40 | // Constant used to calculate the average for rate metrics and used by the |
| 41 | // plugin for the frequency at which stats should be updated. |
sergeyu | 92dcbfc | 2015-09-21 18:43:01 | [diff] [blame] | 42 | static const int kStatsUpdatePeriodSeconds = 1; |
anandc | b877083e | 2015-07-16 22:00:18 | [diff] [blame] | 43 | |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 44 | // Return rates and running-averages for different metrics. |
Yuwei Huang | 16cddbe | 2018-03-27 00:47:04 | [diff] [blame] | 45 | double video_bandwidth() const { return video_bandwidth_.Rate(); } |
| 46 | double video_frame_rate() const { return video_frame_rate_.Rate(); } |
| 47 | double video_packet_rate() const { return video_packet_rate_.Rate(); } |
| 48 | const RunningSamples& video_capture_ms() const { return video_capture_ms_; } |
| 49 | const RunningSamples& video_encode_ms() const { return video_encode_ms_; } |
| 50 | const RunningSamples& video_decode_ms() const { return video_decode_ms_; } |
| 51 | const RunningSamples& video_paint_ms() const { return video_paint_ms_; } |
| 52 | const RunningSamples& round_trip_ms() const { return round_trip_ms_; } |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 53 | |
sergeyu | 47dc4a53 | 2016-07-06 21:07:22 | [diff] [blame] | 54 | // FrameStatsConsumer interface. |
| 55 | void OnVideoFrameStats(const FrameStats& stats) override; |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 56 | |
| 57 | // Sets callbacks in ChromotingInstance to update a UMA custom counts, custom |
| 58 | // times or enum histogram. |
| 59 | void SetUpdateUmaCallbacks( |
| 60 | UpdateUmaCustomHistogramCallback update_uma_custom_counts_callback, |
| 61 | UpdateUmaCustomHistogramCallback update_uma_custom_times_callback, |
| 62 | UpdateUmaEnumHistogramCallback update_uma_enum_histogram_callback); |
| 63 | |
sergeyu | 92dcbfc | 2015-09-21 18:43:01 | [diff] [blame] | 64 | void OnPauseStateChanged(bool paused); |
| 65 | |
| 66 | private: |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 67 | // Updates frame-rate, packet-rate and bandwidth UMA statistics. |
| 68 | void UploadRateStatsToUma(); |
| 69 | |
anandc | b877083e | 2015-07-16 22:00:18 | [diff] [blame] | 70 | // The video and packet rate metrics below are updated per video packet |
| 71 | // received and then, for reporting, averaged over a 1s time-window. |
| 72 | // Bytes per second for non-empty video-packets. |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 73 | RateCounter video_bandwidth_; |
anandc | b877083e | 2015-07-16 22:00:18 | [diff] [blame] | 74 | |
| 75 | // Frames per second for non-empty video-packets. |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 76 | RateCounter video_frame_rate_; |
anandc | b877083e | 2015-07-16 22:00:18 | [diff] [blame] | 77 | |
| 78 | // Video packets per second, including empty video-packets. |
| 79 | // This will be greater than the frame rate, as individual frames are |
| 80 | // contained in packets, some of which might be empty (e.g. when there are no |
| 81 | // screen changes). |
Sunny Sachanandani | 4669788 | 2015-08-14 04:55:51 | [diff] [blame] | 82 | RateCounter video_packet_rate_; |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 83 | |
| 84 | // The following running-averages are uploaded to UMA per video packet and |
| 85 | // also used for display to users, averaged over the N most recent samples. |
| 86 | // N = kLatencySampleSize. |
yuweih | d2a0c5cb | 2016-03-23 22:41:05 | [diff] [blame] | 87 | RunningSamples video_capture_ms_; |
| 88 | RunningSamples video_encode_ms_; |
| 89 | RunningSamples video_decode_ms_; |
| 90 | RunningSamples video_paint_ms_; |
| 91 | RunningSamples round_trip_ms_; |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 92 | |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 93 | // Used to update UMA stats, if set. |
| 94 | UpdateUmaCustomHistogramCallback uma_custom_counts_updater_; |
| 95 | UpdateUmaCustomHistogramCallback uma_custom_times_updater_; |
| 96 | UpdateUmaEnumHistogramCallback uma_enum_histogram_updater_; |
| 97 | |
sergeyu | 92dcbfc | 2015-09-21 18:43:01 | [diff] [blame] | 98 | bool is_paused_ = false; |
| 99 | |
danakj | 8c3eb80 | 2015-09-24 07:53:00 | [diff] [blame] | 100 | base::RepeatingTimer upload_uma_stats_timer_; |
anandc | 8414283 | 2015-08-14 21:48:58 | [diff] [blame] | 101 | |
sergeyu | aa1f0239 | 2015-09-17 00:45:24 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(PerformanceTracker); |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 103 | }; |
| 104 | |
sergeyu | aa1f0239 | 2015-09-17 00:45:24 | [diff] [blame] | 105 | } // namespace protocol |
[email protected] | 778d599d | 2011-04-05 18:03:31 | [diff] [blame] | 106 | } // namespace remoting |
| 107 | |
sergeyu | aa1f0239 | 2015-09-17 00:45:24 | [diff] [blame] | 108 | #endif // REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ |