File: webrtc_browsertest_perf.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (409 lines) | stat: -rw-r--r-- 17,703 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/media/webrtc/webrtc_browsertest_perf.h"

#include <stddef.h>

#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "testing/perf/perf_result_reporter.h"
#include "testing/perf/perf_test.h"

namespace {

std::string Statistic(const std::string& statistic, const std::string& bucket) {
  // A ssrc stats key will be on the form stats.<bucket>-<key>.values.
  // This will give a json "path" which will dig into the time series for the
  // specified statistic. Buckets can be for instance ssrc_1212344, bweforvideo,
  // and will each contain a bunch of statistics relevant to their nature.
  // Each peer connection has a number of such buckets.
  return base::StringPrintf("stats.%s-%s.values", bucket.c_str(),
                            statistic.c_str());
}

void MaybePrintResultsForAudioReceive(const std::string& ssrc,
                                      const base::Value::Dict& pc_dict,
                                      const std::string& modifier) {
  const std::string* value =
      pc_dict.FindStringByDottedPath(Statistic("audioOutputLevel", ssrc));
  if (!value) {
    // Not an audio receive stream.
    return;
  }

  value = pc_dict.FindStringByDottedPath(Statistic("packetsLost", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("audio_misc", modifier, "packets_lost", *value,
                         "frames", false);
  value = pc_dict.FindStringByDottedPath(Statistic("googJitterReceived", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("audio_rx", modifier, "goog_jitter_recv", *value, "ms",
                         false);

  value = pc_dict.FindStringByDottedPath(Statistic("googExpandRate", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("audio_rates", modifier, "goog_expand_rate", *value,
                         "%", false);
  value =
      pc_dict.FindStringByDottedPath(Statistic("googSpeechExpandRate", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("audio_rates", modifier, "goog_speech_expand_rate",
                         *value, "%", false);
  value = pc_dict.FindStringByDottedPath(
      Statistic("googSecondaryDecodedRate", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("audio_rates", modifier, "goog_secondary_decoded_rate",
                         *value, "%", false);
}

void MaybePrintResultsForAudioSend(const std::string& ssrc,
                                   const base::Value::Dict& pc_dict,
                                   const std::string& modifier) {
  const std::string* value =
      pc_dict.FindStringByDottedPath(Statistic("audioInputLevel", ssrc));
  if (!value) {
    // Not an audio send stream.
    return;
  }

  value = pc_dict.FindStringByDottedPath(Statistic("googJitterReceived", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("audio_tx", modifier, "goog_jitter_recv", *value, "ms",
                         false);
  value = pc_dict.FindStringByDottedPath(Statistic("googRtt", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("audio_tx", modifier, "goog_rtt", *value, "ms", false);
  value =
      pc_dict.FindStringByDottedPath(Statistic("packetsSentPerSecond", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("audio_tx", modifier, "packets_sent_per_second",
                         *value, "packets", false);
}

void MaybePrintResultsForVideoSend(const std::string& ssrc,
                                   const base::Value::Dict& pc_dict,
                                   const std::string& modifier) {
  const std::string* value =
      pc_dict.FindStringByDottedPath(Statistic("googFrameRateSent", ssrc));
  if (!value) {
    // Not a video send stream.
    return;
  }

  // Graph these by unit: the dashboard expects all stats in one graph to have
  // the same unit (e.g. ms, fps, etc). Most graphs, like video_fps, will also
  // be populated by the counterparts on the video receiving side.
  perf_test::PrintResult("video_fps", modifier, "goog_frame_rate_sent", *value,
                         "fps", false);
  value = pc_dict.FindStringByDottedPath(Statistic("googFrameRateInput", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_fps", modifier, "goog_frame_rate_input", *value,
                         "fps", false);

  value = pc_dict.FindStringByDottedPath(Statistic("googFirsReceived", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_misc", modifier, "goog_firs_recv", *value, "",
                         false);
  value = pc_dict.FindStringByDottedPath(Statistic("googNacksReceived", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_misc", modifier, "goog_nacks_recv", *value, "",
                         false);

  value = pc_dict.FindStringByDottedPath(Statistic("googFrameWidthSent", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_resolution", modifier, "goog_frame_width_sent",
                         *value, "pixels", false);
  value =
      pc_dict.FindStringByDottedPath(Statistic("googFrameHeightSent", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_resolution", modifier, "goog_frame_height_sent",
                         *value, "pixels", false);

  value = pc_dict.FindStringByDottedPath(Statistic("googAvgEncodeMs", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_tx", modifier, "goog_avg_encode_ms", *value,
                         "ms", false);
  value = pc_dict.FindStringByDottedPath(Statistic("googRtt", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_tx", modifier, "goog_rtt", *value, "ms", false);

  value =
      pc_dict.FindStringByDottedPath(Statistic("googEncodeUsagePercent", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_cpu_usage", modifier,
                         "goog_encode_usage_percent", *value, "%", false);
}

void MaybePrintResultsForVideoReceive(const std::string& ssrc,
                                      const base::Value::Dict& pc_dict,
                                      const std::string& modifier) {
  const std::string* value =
      pc_dict.FindStringByDottedPath(Statistic("googFrameRateReceived", ssrc));
  if (!value) {
    // Not a video receive stream.
    return;
  }

  perf_test::PrintResult("video_fps", modifier, "goog_frame_rate_recv", *value,
                         "fps", false);
  value =
      pc_dict.FindStringByDottedPath(Statistic("googFrameRateOutput", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_fps", modifier, "goog_frame_rate_output",
                         *value, "fps", false);

  value = pc_dict.FindStringByDottedPath(Statistic("packetsLost", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_misc", modifier, "packets_lost", *value,
                         "frames", false);

  value =
      pc_dict.FindStringByDottedPath(Statistic("googFrameWidthReceived", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_resolution", modifier, "goog_frame_width_recv",
                         *value, "pixels", false);
  value = pc_dict.FindStringByDottedPath(
      Statistic("googFrameHeightReceived", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_resolution", modifier, "goog_frame_height_recv",
                         *value, "pixels", false);

  value = pc_dict.FindStringByDottedPath(Statistic("googCurrentDelayMs", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_rx", modifier, "goog_current_delay_ms", *value,
                         "ms", false);
  value = pc_dict.FindStringByDottedPath(Statistic("googTargetDelayMs", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_rx", modifier, "goog_target_delay_ms", *value,
                         "ms", false);
  value = pc_dict.FindStringByDottedPath(Statistic("googDecodeMs", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_rx", modifier, "goog_decode_ms", *value, "ms",
                         false);
  value = pc_dict.FindStringByDottedPath(Statistic("googMaxDecodeMs", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_rx", modifier, "goog_max_decode_ms", *value,
                         "ms", false);
  value = pc_dict.FindStringByDottedPath(Statistic("googJitterBufferMs", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_rx", modifier, "goog_jitter_buffer_ms", *value,
                         "ms", false);
  value = pc_dict.FindStringByDottedPath(Statistic("googRenderDelayMs", ssrc));
  ASSERT_TRUE(value);
  perf_test::PrintResult("video_rx", modifier, "goog_render_delay_ms", *value,
                         "ms", false);
}

std::string ExtractSsrcIdentifier(const std::string& key) {
  // Example key: ssrc_1234-someStatName. Grab the part before the dash.
  size_t key_start_pos = 0;
  size_t key_end_pos = key.find("-");
  CHECK(key_end_pos != std::string::npos) << "Could not parse key " << key;
  return key.substr(key_start_pos, key_end_pos - key_start_pos);
}

// Returns the set of unique ssrc identifiers in the call (e.g. ssrc_1234,
// ssrc_12356, etc). |stats_dict| is the .stats dict from one peer connection.
std::set<std::string> FindAllSsrcIdentifiers(
    const base::Value::Dict& stats_dict) {
  std::set<std::string> result;
  for (auto kv : stats_dict) {
    if (kv.first.find("ssrc_") != std::string::npos)
      result.insert(ExtractSsrcIdentifier(kv.first));
  }
  return result;
}

}  // namespace

namespace test {

void PrintBweForVideoMetrics(const base::Value::Dict& pc_dict,
                             const std::string& modifier,
                             const std::string& video_codec) {
  std::string video_modifier =
      video_codec.empty() ? modifier : modifier + "_" + video_codec;
  const std::string kBweStatsKey = "bweforvideo";
  const std::string* value = pc_dict.FindStringByDottedPath(
      Statistic("googAvailableSendBandwidth", kBweStatsKey));
  ASSERT_TRUE(value);
  perf_test::PrintResult("bwe_stats", video_modifier, "available_send_bw",
                         *value, "bit/s", false);
  value = pc_dict.FindStringByDottedPath(
      Statistic("googAvailableReceiveBandwidth", kBweStatsKey));
  ASSERT_TRUE(value);
  perf_test::PrintResult("bwe_stats", video_modifier, "available_recv_bw",
                         *value, "bit/s", false);
  value = pc_dict.FindStringByDottedPath(
      Statistic("googTargetEncBitrate", kBweStatsKey));
  ASSERT_TRUE(value);
  perf_test::PrintResult("bwe_stats", video_modifier, "target_enc_bitrate",
                         *value, "bit/s", false);
  value = pc_dict.FindStringByDottedPath(
      Statistic("googActualEncBitrate", kBweStatsKey));
  ASSERT_TRUE(value);
  perf_test::PrintResult("bwe_stats", video_modifier, "actual_enc_bitrate",
                         *value, "bit/s", false);
  value = pc_dict.FindStringByDottedPath(
      Statistic("googTransmitBitrate", kBweStatsKey));
  ASSERT_TRUE(value);
  perf_test::PrintResult("bwe_stats", video_modifier, "transmit_bitrate",
                         *value, "bit/s", false);
}

void PrintMetricsForAllStreams(const base::Value::Dict& pc_dict,
                               const std::string& modifier,
                               const std::string& video_codec) {
  PrintMetricsForSendStreams(pc_dict, modifier, video_codec);
  PrintMetricsForRecvStreams(pc_dict, modifier, video_codec);
}

void PrintMetricsForSendStreams(const base::Value::Dict& pc_dict,
                                const std::string& modifier,
                                const std::string& video_codec) {
  std::string video_modifier =
      video_codec.empty() ? modifier : modifier + "_" + video_codec;
  const base::Value::Dict* stats_dict = pc_dict.FindDict("stats");
  ASSERT_TRUE(stats_dict);
  std::set<std::string> ssrc_identifiers = FindAllSsrcIdentifiers(*stats_dict);

  auto ssrc_iterator = ssrc_identifiers.begin();
  for (; ssrc_iterator != ssrc_identifiers.end(); ++ssrc_iterator) {
    const std::string& ssrc = *ssrc_iterator;
    MaybePrintResultsForAudioSend(ssrc, pc_dict, modifier);
    MaybePrintResultsForVideoSend(ssrc, pc_dict, video_modifier);
  }
}

void PrintMetricsForRecvStreams(const base::Value::Dict& pc_dict,
                                const std::string& modifier,
                                const std::string& video_codec) {
  std::string video_modifier =
      video_codec.empty() ? modifier : modifier + "_" + video_codec;
  const base::Value::Dict* stats_dict = pc_dict.FindDict("stats");
  ASSERT_TRUE(stats_dict);
  std::set<std::string> ssrc_identifiers = FindAllSsrcIdentifiers(*stats_dict);

  auto ssrc_iterator = ssrc_identifiers.begin();
  for (; ssrc_iterator != ssrc_identifiers.end(); ++ssrc_iterator) {
    const std::string& ssrc = *ssrc_iterator;
    MaybePrintResultsForAudioReceive(ssrc, pc_dict, modifier);
    MaybePrintResultsForVideoReceive(ssrc, pc_dict, video_modifier);
  }
}

constexpr char kMetricPrefixVideoQualityTest[] =
    "WebRtcVideoQualityBrowserTest.";
constexpr char kMetricUniqueFramesCount[] = "Unique_frames_count";
constexpr char kMetricPsnrUnitless[] = "PSNR";
constexpr char kMetricSsimUnitless[] = "SSIM";
constexpr char kMetricMaxRepeatedCount[] = "Max_repeated";
constexpr char kMetricMaxSkippedCount[] = "Max_skipped";
constexpr char kMetricTotalSkippedCount[] = "Total_skipped";
constexpr char kMetricDecodeErrorsReferenceCount[] = "Decode_errors_reference";
constexpr char kMetricDecodeErrorsTestCount[] = "Decode_errors_test";

bool ParseDoubleFromOutput(const std::string& line,
                           const char* expected_label,
                           double* value) {
  auto fields = base::SplitString(line, " ", base::TRIM_WHITESPACE,
                                  base::SPLIT_WANT_NONEMPTY);
  auto actual_label = std::string(expected_label) + ":";
  if (fields.size() < 4 || fields[1] != actual_label) {
    LOG(ERROR) << "Expected line with " << actual_label
               << " and four or five space-separated fields, got " << line;
    return false;
  }
  if (!base::StringToDouble(fields[3], value)) {
    LOG(ERROR) << "Expected " << fields[3] << " to be an int";
    return false;
  }
  return true;
}

bool ParseListFromOutput(const std::string& line,
                         const char* expected_label,
                         std::string* value) {
  auto fields = base::SplitString(line, " ", base::TRIM_WHITESPACE,
                                  base::SPLIT_WANT_NONEMPTY);
  auto actual_label = std::string(expected_label) + ":";
  if (fields.size() < 4 || fields[1] != actual_label) {
    LOG(ERROR) << "Expected line with " << actual_label
               << " and four or five space-separated fields, got " << line;
    return false;
  }

  // Strip out [].
  std::string values = fields[3];
  if (values.length() < 2) {
    LOG(ERROR) << "Malformed values, expected [val1, val2], got " << values;
    return false;
  }
  *value = values.substr(1, values.length() - 2);
  return true;
}

bool WriteCompareVideosOutputAsHistogram(const std::string& test_label,
                                         const std::string& output) {
  perf_test::PerfResultReporter reporter(kMetricPrefixVideoQualityTest,
                                         test_label);

  reporter.RegisterFyiMetric(kMetricUniqueFramesCount, "count");
  reporter.RegisterFyiMetric(kMetricPsnrUnitless, "unitless");
  reporter.RegisterFyiMetric(kMetricSsimUnitless, "unitless");
  reporter.RegisterFyiMetric(kMetricMaxRepeatedCount, "count");
  reporter.RegisterFyiMetric(kMetricMaxSkippedCount, "count");
  reporter.RegisterFyiMetric(kMetricTotalSkippedCount, "count");
  reporter.RegisterFyiMetric(kMetricDecodeErrorsReferenceCount, "count");
  reporter.RegisterFyiMetric(kMetricDecodeErrorsTestCount, "count");
  auto lines = base::SplitString(output, "\n", base::TRIM_WHITESPACE,
                                 base::SPLIT_WANT_NONEMPTY);

  if (lines.size() == 12) {
    // Remove warning about colorspace conversion.
    lines.erase(lines.begin(), lines.begin() + 4);
  }

  if (lines.size() != 8) {
    LOG(ERROR) << "Expected 8 lines, got " << lines.size()
               << " lines. Output:\n\n"
               << output;
    return false;
  }

  double value;
  if (!ParseDoubleFromOutput(lines[0], kMetricUniqueFramesCount, &value))
    return false;
  reporter.AddResult(kMetricUniqueFramesCount, value);
  std::string value_list;
  if (!ParseListFromOutput(lines[1], kMetricPsnrUnitless, &value_list))
    return false;
  reporter.AddResultList(kMetricPsnrUnitless, value_list);
  if (!ParseListFromOutput(lines[2], kMetricSsimUnitless, &value_list))
    return false;
  reporter.AddResultList(kMetricSsimUnitless, value_list);
  if (!ParseDoubleFromOutput(lines[3], kMetricMaxRepeatedCount, &value))
    return false;
  reporter.AddResult(kMetricMaxRepeatedCount, value);
  if (!ParseDoubleFromOutput(lines[4], kMetricMaxSkippedCount, &value))
    return false;
  reporter.AddResult(kMetricMaxSkippedCount, value);
  if (!ParseDoubleFromOutput(lines[5], kMetricTotalSkippedCount, &value))
    return false;
  reporter.AddResult(kMetricTotalSkippedCount, value);
  if (!ParseDoubleFromOutput(lines[6], kMetricDecodeErrorsReferenceCount,
                             &value))
    return false;
  reporter.AddResult(kMetricDecodeErrorsReferenceCount, value);
  if (!ParseDoubleFromOutput(lines[7], kMetricDecodeErrorsTestCount, &value))
    return false;
  reporter.AddResult(kMetricDecodeErrorsTestCount, value);
  return true;
}

}  // namespace test