Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: media/cast/logging/stats_event_subscriber.h

Issue 482383005: Cast logging: Additional stats for getStats() API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@REAL-NEW-MASTER
Patch Set: Rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ 5 #ifndef MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_
6 #define MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ 6 #define MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_
7 7
8 #include "base/gtest_prod_util.h" 8 #include "base/gtest_prod_util.h"
9 #include "base/memory/linked_ptr.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
11 #include "base/time/tick_clock.h" 12 #include "base/time/tick_clock.h"
12 #include "media/cast/logging/logging_defines.h" 13 #include "media/cast/logging/logging_defines.h"
13 #include "media/cast/logging/raw_event_subscriber.h" 14 #include "media/cast/logging/raw_event_subscriber.h"
14 #include "media/cast/logging/receiver_time_offset_estimator.h" 15 #include "media/cast/logging/receiver_time_offset_estimator.h"
15 16
16 namespace base { 17 namespace base {
17 class DictionaryValue; 18 class DictionaryValue;
19 class ListValue;
18 } 20 }
19 21
20 namespace media { 22 namespace media {
21 namespace cast { 23 namespace cast {
22 24
23 class StatsEventSubscriberTest; 25 class StatsEventSubscriberTest;
24 26
25 // A RawEventSubscriber implementation that subscribes to events, 27 // A RawEventSubscriber implementation that subscribes to events,
26 // and aggregates them into stats. 28 // and aggregates them into stats.
27 class StatsEventSubscriber : public RawEventSubscriber { 29 class StatsEventSubscriber : public RawEventSubscriber {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 base::TimeDelta sum_delay; 71 base::TimeDelta sum_delay;
70 }; 72 };
71 73
72 struct PacketLogStats { 74 struct PacketLogStats {
73 PacketLogStats(); 75 PacketLogStats();
74 ~PacketLogStats(); 76 ~PacketLogStats();
75 int event_counter; 77 int event_counter;
76 size_t sum_size; 78 size_t sum_size;
77 }; 79 };
78 80
81 class SimpleHistogram {
82 public:
83 // This will create N+2 buckets where N = (max - min) / width:
84 // Underflow bucket: < min
85 // Bucket 0: [min, min + width - 1]
86 // Bucket 1: [min + width, min + 2 * width - 1]
87 // ...
88 // Bucket N-1: [max - width, max - 1]
89 // Overflow bucket: >= max
90 // |min| must be less than |max|.
91 // |width| must divide |max - min| evenly.
92 SimpleHistogram(int64 min, int64 max, int64 width);
93
94 ~SimpleHistogram();
95
96 void Add(int64 sample);
97
98 void Reset();
99
100 scoped_ptr<base::ListValue> GetHistogram() const;
101
102 private:
103 int64 min_;
104 int64 max_;
105 int64 width_;
106 std::vector<int> buckets_;
107 };
108
79 enum CastStat { 109 enum CastStat {
80 // Capture frame rate. 110 // Capture frame rate.
81 CAPTURE_FPS, 111 CAPTURE_FPS,
82 // Encode frame rate. 112 // Encode frame rate.
83 ENCODE_FPS, 113 ENCODE_FPS,
84 // Decode frame rate. 114 // Decode frame rate.
85 DECODE_FPS, 115 DECODE_FPS,
86 // Average encode duration in milliseconds. 116 // Average encode duration in milliseconds.
87 // TODO(imcheng): This stat is not populated yet because we do not have 117 // TODO(imcheng): This stat is not populated yet because we do not have
88 // the time when encode started. Record it in FRAME_ENCODED event. 118 // the time when encode started. Record it in FRAME_ENCODED event.
(...skipping 20 matching lines...) Expand all
109 // Number of frames dropped by encoder. 139 // Number of frames dropped by encoder.
110 NUM_FRAMES_DROPPED_BY_ENCODER, 140 NUM_FRAMES_DROPPED_BY_ENCODER,
111 // Number of late frames. 141 // Number of late frames.
112 NUM_FRAMES_LATE, 142 NUM_FRAMES_LATE,
113 // Number of packets that were sent (not retransmitted). 143 // Number of packets that were sent (not retransmitted).
114 NUM_PACKETS_SENT, 144 NUM_PACKETS_SENT,
115 // Number of packets that were retransmitted. 145 // Number of packets that were retransmitted.
116 NUM_PACKETS_RETRANSMITTED, 146 NUM_PACKETS_RETRANSMITTED,
117 // Number of packets that had their retransmission cancelled. 147 // Number of packets that had their retransmission cancelled.
118 NUM_PACKETS_RTX_REJECTED, 148 NUM_PACKETS_RTX_REJECTED,
149 // Unix time in milliseconds of first event since reset.
150 FIRST_EVENT_TIME_MS,
151 // Unix time in milliseconds of last event since reset.
152 LAST_EVENT_TIME_MS,
153
154 // Histograms
155 CAPTURE_LATENCY_MS_HISTO,
156 ENCODE_LATENCY_MS_HISTO,
157 PACKET_LATENCY_MS_HISTO,
158 FRAME_LATENCY_MS_HISTO,
159 PLAYOUT_DELAY_MS_HISTO
119 }; 160 };
120 161
121 struct FrameInfo { 162 struct FrameInfo {
122 explicit FrameInfo(base::TimeTicks capture_time); 163 FrameInfo();
123 ~FrameInfo(); 164 ~FrameInfo();
124 165
125 base::TimeTicks capture_time; 166 base::TimeTicks capture_time;
167 base::TimeTicks capture_end_time;
168 base::TimeTicks encode_time;
126 bool encoded; 169 bool encoded;
127 }; 170 };
128 171
129 typedef std::map<CastStat, double> StatsMap; 172 typedef std::map<CastStat, double> StatsMap;
173 typedef std::map<CastStat, linked_ptr<SimpleHistogram> > HistogramMap;
130 typedef std::map<RtpTimestamp, FrameInfo> FrameInfoMap; 174 typedef std::map<RtpTimestamp, FrameInfo> FrameInfoMap;
131 typedef std::map< 175 typedef std::map<
132 std::pair<RtpTimestamp, uint16>, 176 std::pair<RtpTimestamp, uint16>,
133 std::pair<base::TimeTicks, CastLoggingEvent> > 177 std::pair<base::TimeTicks, CastLoggingEvent> >
134 PacketEventTimeMap; 178 PacketEventTimeMap;
135 typedef std::map<CastLoggingEvent, FrameLogStats> FrameStatsMap; 179 typedef std::map<CastLoggingEvent, FrameLogStats> FrameStatsMap;
136 typedef std::map<CastLoggingEvent, PacketLogStats> PacketStatsMap; 180 typedef std::map<CastLoggingEvent, PacketLogStats> PacketStatsMap;
137 181
138 static const char* CastStatToString(CastStat stat); 182 static const char* CastStatToString(CastStat stat);
139 183
184 void InitHistograms();
185
140 // Assigns |stats_map| with stats data. Used for testing. 186 // Assigns |stats_map| with stats data. Used for testing.
141 void GetStatsInternal(StatsMap* stats_map) const; 187 void GetStatsInternal(StatsMap* stats_map) const;
142 188
189 void UpdateFirstLastEventTime(base::TimeTicks timestamp,
190 bool is_receiver_event);
143 bool GetReceiverOffset(base::TimeDelta* offset); 191 bool GetReceiverOffset(base::TimeDelta* offset);
192 void MaybeInsertFrameInfo(RtpTimestamp rtp_timestamp,
193 const FrameInfo& frame_info);
144 void RecordFrameCaptureTime(const FrameEvent& frame_event); 194 void RecordFrameCaptureTime(const FrameEvent& frame_event);
145 void MarkAsEncoded(RtpTimestamp rtp_timestamp); 195 void RecordCaptureLatency(const FrameEvent& frame_event);
196 void RecordEncodeLatency(const FrameEvent& frame_event);
197 void RecordFrameTxLatency(const FrameEvent& frame_event);
146 void RecordE2ELatency(const FrameEvent& frame_event); 198 void RecordE2ELatency(const FrameEvent& frame_event);
147 void RecordPacketSentTime(const PacketEvent& packet_event); 199 void RecordPacketSentTime(const PacketEvent& packet_event);
148 void ErasePacketSentTime(const PacketEvent& packet_event); 200 void ErasePacketSentTime(const PacketEvent& packet_event);
149 void RecordNetworkLatency(const PacketEvent& packet_event); 201 void RecordNetworkLatency(const PacketEvent& packet_event);
150 void UpdateLastResponseTime(base::TimeTicks receiver_time); 202 void UpdateLastResponseTime(base::TimeTicks receiver_time);
151 203
152 void PopulateFpsStat(base::TimeTicks now, 204 void PopulateFpsStat(base::TimeTicks now,
153 CastLoggingEvent event, 205 CastLoggingEvent event,
154 CastStat stat, 206 CastStat stat,
155 StatsMap* stats_map) const; 207 StatsMap* stats_map) const;
(...skipping 26 matching lines...) Expand all
182 int network_latency_datapoints_; 234 int network_latency_datapoints_;
183 base::TimeDelta total_e2e_latency_; 235 base::TimeDelta total_e2e_latency_;
184 int e2e_latency_datapoints_; 236 int e2e_latency_datapoints_;
185 237
186 base::TimeTicks last_response_received_time_; 238 base::TimeTicks last_response_received_time_;
187 239
188 int num_frames_dropped_by_encoder_; 240 int num_frames_dropped_by_encoder_;
189 int num_frames_late_; 241 int num_frames_late_;
190 242
191 // Fixed size map to record when recent frames were captured and other info. 243 // Fixed size map to record when recent frames were captured and other info.
192 FrameInfoMap recent_captured_frames_; 244 FrameInfoMap recent_frame_infos_;
193 245
194 // Fixed size map to record when recent packets were sent. 246 // Fixed size map to record when recent packets were sent.
195 PacketEventTimeMap packet_sent_times_; 247 PacketEventTimeMap packet_sent_times_;
196 248
197 // Sender time assigned on creation and |Reset()|. 249 // Sender time assigned on creation and |Reset()|.
198 base::TimeTicks start_time_; 250 base::TimeTicks start_time_;
251 base::TimeTicks first_event_time_;
252 base::TimeTicks last_event_time_;
253
254 HistogramMap histograms_;
199 255
200 base::ThreadChecker thread_checker_; 256 base::ThreadChecker thread_checker_;
201 DISALLOW_COPY_AND_ASSIGN(StatsEventSubscriber); 257 DISALLOW_COPY_AND_ASSIGN(StatsEventSubscriber);
202 }; 258 };
203 259
204 } // namespace cast 260 } // namespace cast
205 } // namespace media 261 } // namespace media
206 262
207 #endif // MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ 263 #endif // MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_
OLDNEW
« no previous file with comments | « media/cast/logging/receiver_time_offset_estimator_impl_unittest.cc ('k') | media/cast/logging/stats_event_subscriber.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698