performance_tracker.h 4.05 KB
Newer Older
1
// Copyright 2015 The Chromium Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_
#define REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_
7

8 9
#include <stdint.h>

10
#include "base/callback.h"
11
#include "base/macros.h"
12
#include "base/timer/timer.h"
13
#include "remoting/base/rate_counter.h"
14
#include "remoting/base/running_samples.h"
sergeyu's avatar
sergeyu committed
15
#include "remoting/protocol/frame_stats.h"
16 17

namespace remoting {
18 19 20 21
namespace protocol {

// PerformanceTracker defines a bundle of performance counters and statistics
// for chromoting.
sergeyu's avatar
sergeyu committed
22
class PerformanceTracker : public FrameStatsConsumer {
23
 public:
24 25
  // Callback that updates UMA custom counts or custom times histograms.
  typedef base::Callback<void(const std::string& histogram_name,
26
                              int64_t value,
27 28 29 30 31 32 33
                              int histogram_min,
                              int histogram_max,
                              int histogram_buckets)>
      UpdateUmaCustomHistogramCallback;

  // Callback that updates UMA enumeration histograms.
  typedef base::Callback<
34
      void(const std::string& histogram_name, int64_t value, int histogram_max)>
35 36
      UpdateUmaEnumHistogramCallback;

37
  PerformanceTracker();
sergeyu's avatar
sergeyu committed
38
  ~PerformanceTracker() override;
39

40 41
  // Constant used to calculate the average for rate metrics and used by the
  // plugin for the frequency at which stats should be updated.
42
  static const int kStatsUpdatePeriodSeconds = 1;
43

44 45 46 47
  // Return rates and running-averages for different metrics.
  double video_bandwidth() { return video_bandwidth_.Rate(); }
  double video_frame_rate() { return video_frame_rate_.Rate(); }
  double video_packet_rate() { return video_packet_rate_.Rate(); }
48 49 50 51 52
  const RunningSamples& video_capture_ms() { return video_capture_ms_; }
  const RunningSamples& video_encode_ms() { return video_encode_ms_; }
  const RunningSamples& video_decode_ms() { return video_decode_ms_; }
  const RunningSamples& video_paint_ms() { return video_paint_ms_; }
  const RunningSamples& round_trip_ms() { return round_trip_ms_; }
53

sergeyu's avatar
sergeyu committed
54 55
  // FrameStatsConsumer interface.
  void OnVideoFrameStats(const FrameStats& stats) override;
56 57 58 59 60 61 62 63

  // Sets callbacks in ChromotingInstance to update a UMA custom counts, custom
  // times or enum histogram.
  void SetUpdateUmaCallbacks(
      UpdateUmaCustomHistogramCallback update_uma_custom_counts_callback,
      UpdateUmaCustomHistogramCallback update_uma_custom_times_callback,
      UpdateUmaEnumHistogramCallback update_uma_enum_histogram_callback);

64 65 66
  void OnPauseStateChanged(bool paused);

 private:
67 68 69
  // Updates frame-rate, packet-rate and bandwidth UMA statistics.
  void UploadRateStatsToUma();

70 71 72
  // The video and packet rate metrics below are updated per video packet
  // received and then, for reporting, averaged over a 1s time-window.
  // Bytes per second for non-empty video-packets.
73
  RateCounter video_bandwidth_;
74 75

  // Frames per second for non-empty video-packets.
76
  RateCounter video_frame_rate_;
77 78 79 80 81

  // Video packets per second, including empty video-packets.
  // This will be greater than the frame rate, as individual frames are
  // contained in packets, some of which might be empty (e.g. when there are no
  // screen changes).
82
  RateCounter video_packet_rate_;
83 84 85 86

  // The following running-averages are uploaded to UMA per video packet and
  // also used for display to users, averaged over the N most recent samples.
  // N = kLatencySampleSize.
87 88 89 90 91
  RunningSamples video_capture_ms_;
  RunningSamples video_encode_ms_;
  RunningSamples video_decode_ms_;
  RunningSamples video_paint_ms_;
  RunningSamples round_trip_ms_;
92

93 94 95 96 97
  // Used to update UMA stats, if set.
  UpdateUmaCustomHistogramCallback uma_custom_counts_updater_;
  UpdateUmaCustomHistogramCallback uma_custom_times_updater_;
  UpdateUmaEnumHistogramCallback uma_enum_histogram_updater_;

98 99
  bool is_paused_ = false;

100
  base::RepeatingTimer upload_uma_stats_timer_;
101

102
  DISALLOW_COPY_AND_ASSIGN(PerformanceTracker);
103 104
};

105
}  // namespace protocol
106 107
}  // namespace remoting

108
#endif  // REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_