ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / media / webrtc_browsertest_perf.cc
blobc6747d74035feecdcb90b2ccfe38b8024e5323e6
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/media/webrtc_browsertest_perf.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/values.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "testing/perf/perf_test.h"
12 static std::string Statistic(const std::string& statistic,
13 const std::string& bucket) {
14 // A ssrc stats key will be on the form stats.<bucket>-<key>.values.
15 // This will give a json "path" which will dig into the time series for the
16 // specified statistic. Buckets can be for instance ssrc_1212344, bweforvideo,
17 // and will each contain a bunch of statistics relevant to their nature.
18 // Each peer connection has a number of such buckets.
19 return base::StringPrintf("stats.%s-%s.values", bucket.c_str(),
20 statistic.c_str());
23 static bool MaybePrintResultsForAudioReceive(
24 const std::string& ssrc, const base::DictionaryValue& pc_dict,
25 const std::string& modifier) {
26 std::string value;
27 if (!pc_dict.GetString(Statistic("audioOutputLevel", ssrc), &value)) {
28 // Not an audio receive stream.
29 return false;
32 EXPECT_TRUE(pc_dict.GetString(Statistic("bytesReceived", ssrc), &value));
33 perf_test::PrintResult(
34 "audio_bytes", modifier, "bytes_recv", value, "bytes", false);
35 EXPECT_TRUE(pc_dict.GetString(Statistic("packetsLost", ssrc), &value));
36 perf_test::PrintResult(
37 "audio_misc", modifier, "packets_lost", value, "frames", false);
39 return true;
42 static bool MaybePrintResultsForAudioSend(
43 const std::string& ssrc, const base::DictionaryValue& pc_dict,
44 const std::string& modifier) {
45 std::string value;
46 if (!pc_dict.GetString(Statistic("audioInputLevel", ssrc), &value)) {
47 // Not an audio send stream.
48 return false;
51 EXPECT_TRUE(pc_dict.GetString(Statistic("bytesSent", ssrc), &value));
52 perf_test::PrintResult(
53 "audio_bytes", modifier, "bytes_sent", value, "bytes", false);
54 EXPECT_TRUE(pc_dict.GetString(Statistic("googJitterReceived", ssrc), &value));
55 perf_test::PrintResult(
56 "audio_tx", modifier, "goog_jitter_recv", value, "ms", false);
57 EXPECT_TRUE(pc_dict.GetString(Statistic("googRtt", ssrc), &value));
58 perf_test::PrintResult(
59 "audio_tx", modifier, "goog_rtt", value, "ms", false);
60 return true;
63 static bool MaybePrintResultsForVideoSend(
64 const std::string& ssrc, const base::DictionaryValue& pc_dict,
65 const std::string& modifier) {
66 std::string value;
67 if (!pc_dict.GetString(Statistic("googFrameRateSent", ssrc), &value)) {
68 // Not a video send stream.
69 return false;
72 // Graph these by unit: the dashboard expects all stats in one graph to have
73 // the same unit (e.g. ms, fps, etc). Most graphs, like video_fps, will also
74 // be populated by the counterparts on the video receiving side.
75 perf_test::PrintResult(
76 "video_fps", modifier, "goog_frame_rate_sent", value, "fps", false);
77 EXPECT_TRUE(pc_dict.GetString(Statistic("googFrameRateInput", ssrc), &value));
78 perf_test::PrintResult(
79 "video_fps", modifier, "goog_frame_rate_input", value, "fps", false);
81 EXPECT_TRUE(pc_dict.GetString(Statistic("bytesSent", ssrc), &value));
82 perf_test::PrintResult(
83 "video_total_bytes", modifier, "bytes_sent", value, "bytes", false);
85 EXPECT_TRUE(pc_dict.GetString(Statistic("googFirsReceived", ssrc), &value));
86 perf_test::PrintResult(
87 "video_misc", modifier, "goog_firs_recv", value, "", false);
88 EXPECT_TRUE(pc_dict.GetString(Statistic("googNacksReceived", ssrc), &value));
89 perf_test::PrintResult(
90 "video_misc", modifier, "goog_nacks_recv", value, "", false);
92 EXPECT_TRUE(pc_dict.GetString(Statistic("googFrameWidthSent", ssrc), &value));
93 perf_test::PrintResult("video_resolution", modifier, "goog_frame_width_sent",
94 value, "pixels", false);
95 EXPECT_TRUE(
96 pc_dict.GetString(Statistic("googFrameHeightSent", ssrc), &value));
97 perf_test::PrintResult("video_resolution", modifier, "goog_frame_height_sent",
98 value, "pixels", false);
100 EXPECT_TRUE(pc_dict.GetString(
101 Statistic("googCaptureJitterMs", ssrc), &value));
102 perf_test::PrintResult(
103 "video_tx", modifier, "goog_capture_jitter_ms", value, "ms", false);
104 EXPECT_TRUE(pc_dict.GetString(
105 Statistic("googCaptureQueueDelayMsPerS", ssrc), &value));
106 perf_test::PrintResult(
107 "video_tx", modifier, "goog_capture_queue_delay_ms_per_s",
108 value, "ms/s", false);
109 EXPECT_TRUE(pc_dict.GetString(Statistic("googAvgEncodeMs", ssrc), &value));
110 perf_test::PrintResult(
111 "video_tx", modifier, "goog_avg_encode_ms", value, "ms", false);
112 EXPECT_TRUE(pc_dict.GetString(Statistic("googRtt", ssrc), &value));
113 perf_test::PrintResult("video_tx", modifier, "goog_rtt", value, "ms", false);
115 EXPECT_TRUE(pc_dict.GetString(
116 Statistic("googEncodeUsagePercent", ssrc), &value));
117 perf_test::PrintResult("video_cpu_usage", modifier,
118 "goog_encode_usage_percent", value, "%", false);
119 return true;
122 static bool MaybePrintResultsForVideoReceive(
123 const std::string& ssrc, const base::DictionaryValue& pc_dict,
124 const std::string& modifier) {
125 std::string value;
126 if (!pc_dict.GetString(Statistic("googFrameRateReceived", ssrc), &value)) {
127 // Not a video receive stream.
128 return false;
131 perf_test::PrintResult(
132 "video_fps", modifier, "goog_frame_rate_recv", value, "fps", false);
133 EXPECT_TRUE(
134 pc_dict.GetString(Statistic("googFrameRateOutput", ssrc), &value));
135 perf_test::PrintResult(
136 "video_fps", modifier, "goog_frame_rate_output", value, "fps", false);
138 EXPECT_TRUE(pc_dict.GetString(Statistic("packetsLost", ssrc), &value));
139 perf_test::PrintResult("video_misc", modifier, "packets_lost", value,
140 "frames", false);
142 EXPECT_TRUE(pc_dict.GetString(Statistic("bytesReceived", ssrc), &value));
143 perf_test::PrintResult(
144 "video_total_bytes", modifier, "bytes_recv", value, "bytes", false);
146 EXPECT_TRUE(
147 pc_dict.GetString(Statistic("googFrameWidthReceived", ssrc), &value));
148 perf_test::PrintResult("video_resolution", modifier, "goog_frame_width_recv",
149 value, "pixels", false);
150 EXPECT_TRUE(
151 pc_dict.GetString(Statistic("googFrameHeightReceived", ssrc), &value));
152 perf_test::PrintResult("video_resolution", modifier, "goog_frame_height_recv",
153 value, "pixels", false);
155 EXPECT_TRUE(pc_dict.GetString(Statistic("googCurrentDelayMs", ssrc), &value));
156 perf_test::PrintResult(
157 "video_rx", modifier, "goog_current_delay_ms", value, "ms", false);
158 EXPECT_TRUE(pc_dict.GetString(Statistic("googTargetDelayMs", ssrc), &value));
159 perf_test::PrintResult(
160 "video_rx", modifier, "goog_target_delay_ms", value, "ms", false);
161 EXPECT_TRUE(pc_dict.GetString(Statistic("googDecodeMs", ssrc), &value));
162 perf_test::PrintResult("video_rx", modifier, "goog_decode_ms", value, "ms",
163 false);
164 EXPECT_TRUE(pc_dict.GetString(Statistic("googMaxDecodeMs", ssrc), &value));
165 perf_test::PrintResult(
166 "video_rx", modifier, "goog_max_decode_ms", value, "ms", false);
167 EXPECT_TRUE(pc_dict.GetString(Statistic("googJitterBufferMs", ssrc), &value));
168 perf_test::PrintResult(
169 "video_rx", modifier, "goog_jitter_buffer_ms", value, "ms", false);
170 EXPECT_TRUE(pc_dict.GetString(Statistic("googRenderDelayMs", ssrc), &value));
171 perf_test::PrintResult(
172 "video_rx", modifier, "goog_render_delay_ms", value, "ms", false);
174 return true;
177 static std::string ExtractSsrcIdentifier(const std::string& key) {
178 // Example key: ssrc_1234-someStatName. Grab the part before the dash.
179 size_t key_start_pos = 0;
180 size_t key_end_pos = key.find("-");
181 CHECK(key_end_pos != std::string::npos) << "Could not parse key " << key;
182 return key.substr(key_start_pos, key_end_pos - key_start_pos);
185 // Returns the set of unique ssrc identifiers in the call (e.g. ssrc_1234,
186 // ssrc_12356, etc). |stats_dict| is the .stats dict from one peer connection.
187 static std::set<std::string> FindAllSsrcIdentifiers(
188 const base::DictionaryValue& stats_dict) {
189 std::set<std::string> result;
190 base::DictionaryValue::Iterator stats_iterator(stats_dict);
192 while (!stats_iterator.IsAtEnd()) {
193 if (stats_iterator.key().find("ssrc_") != std::string::npos)
194 result.insert(ExtractSsrcIdentifier(stats_iterator.key()));
195 stats_iterator.Advance();
197 return result;
200 namespace test {
202 void PrintBweForVideoMetrics(const base::DictionaryValue& pc_dict,
203 const std::string& modifier) {
204 const std::string kBweStatsKey = "bweforvideo";
205 std::string value;
206 ASSERT_TRUE(pc_dict.GetString(
207 Statistic("googAvailableSendBandwidth", kBweStatsKey), &value));
208 perf_test::PrintResult(
209 "bwe_stats", modifier, "available_send_bw", value, "bit/s", false);
210 ASSERT_TRUE(pc_dict.GetString(
211 Statistic("googAvailableReceiveBandwidth", kBweStatsKey), &value));
212 perf_test::PrintResult(
213 "bwe_stats", modifier, "available_recv_bw", value, "bit/s", false);
214 ASSERT_TRUE(pc_dict.GetString(
215 Statistic("googTargetEncBitrate", kBweStatsKey), &value));
216 perf_test::PrintResult(
217 "bwe_stats", modifier, "target_enc_bitrate", value, "bit/s", false);
218 ASSERT_TRUE(pc_dict.GetString(
219 Statistic("googActualEncBitrate", kBweStatsKey), &value));
220 perf_test::PrintResult(
221 "bwe_stats", modifier, "actual_enc_bitrate", value, "bit/s", false);
222 ASSERT_TRUE(pc_dict.GetString(
223 Statistic("googTransmitBitrate", kBweStatsKey), &value));
224 perf_test::PrintResult(
225 "bwe_stats", modifier, "transmit_bitrate", value, "bit/s",false);
228 void PrintMetricsForAllStreams(const base::DictionaryValue& pc_dict,
229 const std::string& modifier) {
230 const base::DictionaryValue* stats_dict;
231 ASSERT_TRUE(pc_dict.GetDictionary("stats", &stats_dict));
232 std::set<std::string> ssrc_identifiers = FindAllSsrcIdentifiers(*stats_dict);
234 std::set<std::string>::const_iterator ssrc_iterator =
235 ssrc_identifiers.begin();
236 for (; ssrc_iterator != ssrc_identifiers.end(); ++ssrc_iterator) {
237 // Figure out which stream type this ssrc represents and print all the
238 // interesting metrics for it.
239 const std::string& ssrc = *ssrc_iterator;
240 bool did_recognize_stream_type =
241 MaybePrintResultsForAudioReceive(ssrc, pc_dict, modifier) ||
242 MaybePrintResultsForAudioSend(ssrc, pc_dict, modifier) ||
243 MaybePrintResultsForVideoReceive(ssrc, pc_dict, modifier) ||
244 MaybePrintResultsForVideoSend(ssrc, pc_dict, modifier);
245 ASSERT_TRUE(did_recognize_stream_type) << "Failed to figure out which "
246 "kind of stream SSRC " << ssrc
247 << " is. ";
251 } // namespace test