blob: 1f3c6b6629543418cde347849299a32f4d40ff72 [file] [log] [blame]
sergeyuaa1f02392015-09-17 00:45:241// Copyright 2015 The Chromium Authors. All rights reserved.
[email protected]778d599d2011-04-05 18:03:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
sergeyuaa1f02392015-09-17 00:45:245#ifndef REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_
6#define REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_
[email protected]778d599d2011-04-05 18:03:317
avi5a080f012015-12-22 23:15:438#include <stdint.h>
9
anandc84142832015-08-14 21:48:5810#include "base/callback.h"
avi5a080f012015-12-22 23:15:4311#include "base/macros.h"
sergeyu92dcbfc2015-09-21 18:43:0112#include "base/timer/timer.h"
[email protected]778d599d2011-04-05 18:03:3113#include "remoting/base/rate_counter.h"
yuweihd2a0c5cb2016-03-23 22:41:0514#include "remoting/base/running_samples.h"
sergeyu47dc4a532016-07-06 21:07:2215#include "remoting/protocol/frame_stats.h"
[email protected]778d599d2011-04-05 18:03:3116
17namespace remoting {
sergeyuaa1f02392015-09-17 00:45:2418namespace protocol {
19
20// PerformanceTracker defines a bundle of performance counters and statistics
21// for chromoting.
sergeyu47dc4a532016-07-06 21:07:2222class PerformanceTracker : public FrameStatsConsumer {
[email protected]778d599d2011-04-05 18:03:3123 public:
anandc84142832015-08-14 21:48:5824 // Callback that updates UMA custom counts or custom times histograms.
25 typedef base::Callback<void(const std::string& histogram_name,
sergeyu752c6e62015-09-30 06:40:2726 int64_t value,
anandc84142832015-08-14 21:48:5827 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<
sergeyu752c6e62015-09-30 06:40:2734 void(const std::string& histogram_name, int64_t value, int histogram_max)>
anandc84142832015-08-14 21:48:5835 UpdateUmaEnumHistogramCallback;
36
sergeyuaa1f02392015-09-17 00:45:2437 PerformanceTracker();
sergeyu47dc4a532016-07-06 21:07:2238 ~PerformanceTracker() override;
[email protected]778d599d2011-04-05 18:03:3139
anandcb877083e2015-07-16 22:00:1840 // Constant used to calculate the average for rate metrics and used by the
41 // plugin for the frequency at which stats should be updated.
sergeyu92dcbfc2015-09-21 18:43:0142 static const int kStatsUpdatePeriodSeconds = 1;
anandcb877083e2015-07-16 22:00:1843
anandc84142832015-08-14 21:48:5844 // Return rates and running-averages for different metrics.
Yuwei Huang16cddbe2018-03-27 00:47:0445 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_; }
anandc84142832015-08-14 21:48:5853
sergeyu47dc4a532016-07-06 21:07:2254 // FrameStatsConsumer interface.
55 void OnVideoFrameStats(const FrameStats& stats) override;
anandc84142832015-08-14 21:48:5856
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
sergeyu92dcbfc2015-09-21 18:43:0164 void OnPauseStateChanged(bool paused);
65
66 private:
anandc84142832015-08-14 21:48:5867 // Updates frame-rate, packet-rate and bandwidth UMA statistics.
68 void UploadRateStatsToUma();
69
anandcb877083e2015-07-16 22:00:1870 // 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.
anandc84142832015-08-14 21:48:5873 RateCounter video_bandwidth_;
anandcb877083e2015-07-16 22:00:1874
75 // Frames per second for non-empty video-packets.
anandc84142832015-08-14 21:48:5876 RateCounter video_frame_rate_;
anandcb877083e2015-07-16 22:00:1877
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 Sachanandani46697882015-08-14 04:55:5182 RateCounter video_packet_rate_;
anandc84142832015-08-14 21:48:5883
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.
yuweihd2a0c5cb2016-03-23 22:41:0587 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]778d599d2011-04-05 18:03:3192
anandc84142832015-08-14 21:48:5893 // 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
sergeyu92dcbfc2015-09-21 18:43:0198 bool is_paused_ = false;
99
danakj8c3eb802015-09-24 07:53:00100 base::RepeatingTimer upload_uma_stats_timer_;
anandc84142832015-08-14 21:48:58101
sergeyuaa1f02392015-09-17 00:45:24102 DISALLOW_COPY_AND_ASSIGN(PerformanceTracker);
[email protected]778d599d2011-04-05 18:03:31103};
104
sergeyuaa1f02392015-09-17 00:45:24105} // namespace protocol
[email protected]778d599d2011-04-05 18:03:31106} // namespace remoting
107
sergeyuaa1f02392015-09-17 00:45:24108#endif // REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_