| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ | 5 #ifndef REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ |
| 6 #define REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ | 6 #define REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | |
| 11 | |
| 12 #include "base/callback.h" | 10 #include "base/callback.h" |
| 13 #include "base/macros.h" | 11 #include "base/macros.h" |
| 14 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 15 #include "remoting/base/rate_counter.h" | 13 #include "remoting/base/rate_counter.h" |
| 16 #include "remoting/base/running_samples.h" | 14 #include "remoting/base/running_samples.h" |
| 17 | 15 |
| 18 namespace remoting { | 16 namespace remoting { |
| 17 namespace protocol { |
| 19 | 18 |
| 20 class VideoPacket; | 19 struct FrameStats; |
| 21 | |
| 22 namespace protocol { | |
| 23 | 20 |
| 24 // PerformanceTracker defines a bundle of performance counters and statistics | 21 // PerformanceTracker defines a bundle of performance counters and statistics |
| 25 // for chromoting. | 22 // for chromoting. |
| 26 class PerformanceTracker { | 23 class PerformanceTracker { |
| 27 public: | 24 public: |
| 28 // Callback that updates UMA custom counts or custom times histograms. | 25 // Callback that updates UMA custom counts or custom times histograms. |
| 29 typedef base::Callback<void(const std::string& histogram_name, | 26 typedef base::Callback<void(const std::string& histogram_name, |
| 30 int64_t value, | 27 int64_t value, |
| 31 int histogram_min, | 28 int histogram_min, |
| 32 int histogram_max, | 29 int histogram_max, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 49 double video_bandwidth() { return video_bandwidth_.Rate(); } | 46 double video_bandwidth() { return video_bandwidth_.Rate(); } |
| 50 double video_frame_rate() { return video_frame_rate_.Rate(); } | 47 double video_frame_rate() { return video_frame_rate_.Rate(); } |
| 51 double video_packet_rate() { return video_packet_rate_.Rate(); } | 48 double video_packet_rate() { return video_packet_rate_.Rate(); } |
| 52 const RunningSamples& video_capture_ms() { return video_capture_ms_; } | 49 const RunningSamples& video_capture_ms() { return video_capture_ms_; } |
| 53 const RunningSamples& video_encode_ms() { return video_encode_ms_; } | 50 const RunningSamples& video_encode_ms() { return video_encode_ms_; } |
| 54 const RunningSamples& video_decode_ms() { return video_decode_ms_; } | 51 const RunningSamples& video_decode_ms() { return video_decode_ms_; } |
| 55 const RunningSamples& video_paint_ms() { return video_paint_ms_; } | 52 const RunningSamples& video_paint_ms() { return video_paint_ms_; } |
| 56 const RunningSamples& round_trip_ms() { return round_trip_ms_; } | 53 const RunningSamples& round_trip_ms() { return round_trip_ms_; } |
| 57 | 54 |
| 58 // Record stats for a video-packet. | 55 // Record stats for a video-packet. |
| 59 void RecordVideoPacketStats(const VideoPacket& packet); | 56 void RecordVideoFrameStats(const FrameStats& stats); |
| 60 | |
| 61 // Helpers to track decode and paint time. If the render drops some frames | |
| 62 // before they are painted then OnFramePainted() records paint time when the | |
| 63 // following frame is rendered. OnFramePainted() may be called multiple times, | |
| 64 // in which case all calls after the first one are ignored. | |
| 65 void OnFrameDecoded(int32_t frame_id); | |
| 66 void OnFramePainted(int32_t frame_id); | |
| 67 | 57 |
| 68 // Sets callbacks in ChromotingInstance to update a UMA custom counts, custom | 58 // Sets callbacks in ChromotingInstance to update a UMA custom counts, custom |
| 69 // times or enum histogram. | 59 // times or enum histogram. |
| 70 void SetUpdateUmaCallbacks( | 60 void SetUpdateUmaCallbacks( |
| 71 UpdateUmaCustomHistogramCallback update_uma_custom_counts_callback, | 61 UpdateUmaCustomHistogramCallback update_uma_custom_counts_callback, |
| 72 UpdateUmaCustomHistogramCallback update_uma_custom_times_callback, | 62 UpdateUmaCustomHistogramCallback update_uma_custom_times_callback, |
| 73 UpdateUmaEnumHistogramCallback update_uma_enum_histogram_callback); | 63 UpdateUmaEnumHistogramCallback update_uma_enum_histogram_callback); |
| 74 | 64 |
| 75 void OnPauseStateChanged(bool paused); | 65 void OnPauseStateChanged(bool paused); |
| 76 | 66 |
| 77 private: | 67 private: |
| 78 struct FrameTimestamps { | |
| 79 FrameTimestamps(); | |
| 80 ~FrameTimestamps(); | |
| 81 | |
| 82 // Set to null for frames that were not sent after a fresh input event. | |
| 83 base::TimeTicks latest_event_timestamp; | |
| 84 | |
| 85 // Set to TimeDelta::Max() when unknown. | |
| 86 base::TimeDelta total_host_latency; | |
| 87 | |
| 88 base::TimeTicks time_received; | |
| 89 base::TimeTicks time_decoded; | |
| 90 }; | |
| 91 typedef std::map<int32_t, FrameTimestamps> FramesTimestampsMap; | |
| 92 | |
| 93 // Helper to record input roundtrip latency after a frame has been painted. | |
| 94 void RecordRoundTripLatency(const FrameTimestamps& timestamps); | |
| 95 | |
| 96 // Updates frame-rate, packet-rate and bandwidth UMA statistics. | 68 // Updates frame-rate, packet-rate and bandwidth UMA statistics. |
| 97 void UploadRateStatsToUma(); | 69 void UploadRateStatsToUma(); |
| 98 | 70 |
| 99 // The video and packet rate metrics below are updated per video packet | 71 // The video and packet rate metrics below are updated per video packet |
| 100 // received and then, for reporting, averaged over a 1s time-window. | 72 // received and then, for reporting, averaged over a 1s time-window. |
| 101 // Bytes per second for non-empty video-packets. | 73 // Bytes per second for non-empty video-packets. |
| 102 RateCounter video_bandwidth_; | 74 RateCounter video_bandwidth_; |
| 103 | 75 |
| 104 // Frames per second for non-empty video-packets. | 76 // Frames per second for non-empty video-packets. |
| 105 RateCounter video_frame_rate_; | 77 RateCounter video_frame_rate_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 117 RunningSamples video_encode_ms_; | 89 RunningSamples video_encode_ms_; |
| 118 RunningSamples video_decode_ms_; | 90 RunningSamples video_decode_ms_; |
| 119 RunningSamples video_paint_ms_; | 91 RunningSamples video_paint_ms_; |
| 120 RunningSamples round_trip_ms_; | 92 RunningSamples round_trip_ms_; |
| 121 | 93 |
| 122 // Used to update UMA stats, if set. | 94 // Used to update UMA stats, if set. |
| 123 UpdateUmaCustomHistogramCallback uma_custom_counts_updater_; | 95 UpdateUmaCustomHistogramCallback uma_custom_counts_updater_; |
| 124 UpdateUmaCustomHistogramCallback uma_custom_times_updater_; | 96 UpdateUmaCustomHistogramCallback uma_custom_times_updater_; |
| 125 UpdateUmaEnumHistogramCallback uma_enum_histogram_updater_; | 97 UpdateUmaEnumHistogramCallback uma_enum_histogram_updater_; |
| 126 | 98 |
| 127 // The latest event timestamp that a VideoPacket was seen annotated with. | |
| 128 base::TimeTicks latest_event_timestamp_; | |
| 129 | |
| 130 // Stores timestamps for the frames that are currently being processed. | |
| 131 FramesTimestampsMap frame_timestamps_; | |
| 132 | |
| 133 bool is_paused_ = false; | 99 bool is_paused_ = false; |
| 134 | 100 |
| 135 base::RepeatingTimer upload_uma_stats_timer_; | 101 base::RepeatingTimer upload_uma_stats_timer_; |
| 136 | 102 |
| 137 DISALLOW_COPY_AND_ASSIGN(PerformanceTracker); | 103 DISALLOW_COPY_AND_ASSIGN(PerformanceTracker); |
| 138 }; | 104 }; |
| 139 | 105 |
| 140 } // namespace protocol | 106 } // namespace protocol |
| 141 } // namespace remoting | 107 } // namespace remoting |
| 142 | 108 |
| 143 #endif // REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ | 109 #endif // REMOTING_PROTOCOL_PERFORMANCE_TRACKER_H_ |
| OLD | NEW |