This source file includes following definitions.
- Statistic
- MaybePrintResultsForAudioReceive
- MaybePrintResultsForAudioSend
- MaybePrintResultsForVideoReceive
- MaybePrintResultsForVideoSend
- ExtractSsrcIdentifier
- FindAllSsrcIdentifiers
- PrintBweForVideoMetrics
- PrintMetricsForAllStreams
#include "chrome/browser/media/webrtc_browsertest_perf.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "testing/perf/perf_test.h"
static std::string Statistic(const std::string& statistic,
const std::string& bucket) {
return base::StringPrintf("stats.%s-%s.values", bucket.c_str(),
statistic.c_str());
}
static bool MaybePrintResultsForAudioReceive(
const std::string& ssrc, const base::DictionaryValue& pc_dict) {
std::string value;
if (!pc_dict.GetString(Statistic("audioOutputLevel", ssrc), &value)) {
return false;
}
EXPECT_TRUE(pc_dict.GetString(Statistic("bytesReceived", ssrc), &value));
perf_test::PrintResult("audio_recv", "", "bytes_recv", value, "bytes", false);
EXPECT_TRUE(pc_dict.GetString(Statistic("packetsLost", ssrc), &value));
perf_test::PrintResult("audio_recv", "", "packets_lost", value, "", false);
return true;
}
static bool MaybePrintResultsForAudioSend(
const std::string& ssrc, const base::DictionaryValue& pc_dict) {
std::string value;
if (!pc_dict.GetString(Statistic("audioInputLevel", ssrc), &value)) {
return false;
}
EXPECT_TRUE(pc_dict.GetString(Statistic("bytesSent", ssrc), &value));
perf_test::PrintResult("audio_send", "", "bytes_sent", value, "bytes", false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googJitterReceived", ssrc), &value));
perf_test::PrintResult("audio_send", "", "goog_jitter_recv", value, "",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googRtt", ssrc), &value));
perf_test::PrintResult("audio_send", "", "goog_rtt", value, "ms", false);
return true;
}
static bool MaybePrintResultsForVideoReceive(
const std::string& ssrc, const base::DictionaryValue& pc_dict) {
std::string value;
if (!pc_dict.GetString(Statistic("googFrameRateInput", ssrc), &value)) {
return false;
}
perf_test::PrintResult("video_recv", "", "goog_frame_rate_input", value,
"fps", false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googFrameRateSent", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_frame_rate_sent", value, "fps",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("bytesSent", ssrc), &value));
perf_test::PrintResult("video_recv", "", "bytes_sent", value, "bytes", false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googFirsReceived", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_firs_recv", value, "", false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googNacksReceived", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_nacks_recv", value, "", false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googFrameWidthSent", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_frame_width_sent", value,
"pixels", false);
EXPECT_TRUE(
pc_dict.GetString(Statistic("googFrameHeightSent", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_frame_height_sent", value,
"pixels", false);
EXPECT_TRUE(pc_dict.GetString(
Statistic("googCaptureJitterMs", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_capture_jitter_ms", value,
"ms", false);
EXPECT_TRUE(pc_dict.GetString(
Statistic("googCaptureQueueDelayMsPerS", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_capture_queue_delay_ms_per_s",
value, "ms/s", false);
EXPECT_TRUE(pc_dict.GetString(
Statistic("googEncodeUsagePercent", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_encode_usage_percent",
value, "%", false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googAvgEncodeMs", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_avg_encode_ms", value, "ms",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googRtt", ssrc), &value));
perf_test::PrintResult("video_recv", "", "goog_rtt", value, "ms", false);
return true;
}
static bool MaybePrintResultsForVideoSend(
const std::string& ssrc, const base::DictionaryValue& pc_dict) {
std::string value;
if (!pc_dict.GetString(Statistic("googFrameRateOutput", ssrc), &value)) {
return false;
}
perf_test::PrintResult("video_send", "", "goog_frame_rate_output", value,
"fps", false);
EXPECT_TRUE(pc_dict.GetString(Statistic("packetsLost", ssrc), &value));
perf_test::PrintResult("video_send", "", "packets_lost", value, "packets",
false);
EXPECT_TRUE(
pc_dict.GetString(Statistic("googFrameWidthReceived", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_frame_width_recv", value,
"pixels", false);
EXPECT_TRUE(
pc_dict.GetString(Statistic("googFrameHeightReceived", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_frame_height_recv", value,
"pixels", false);
EXPECT_TRUE(
pc_dict.GetString(Statistic("googFrameRateReceived", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_frame_rate_recv", value, "fps",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googCurrentDelayMs", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_current_delay_ms", value, "ms",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googTargetDelayMs", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_target_delay_ms", value, "ms",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googDecodeMs", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_decode_ms", value, "ms",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googMaxDecodeMs", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_max_decode_ms", value, "ms",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googJitterBufferMs", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_jitter_buffer_ms", value, "ms",
false);
EXPECT_TRUE(pc_dict.GetString(Statistic("googRenderDelayMs", ssrc), &value));
perf_test::PrintResult("video_send", "", "goog_render_delay_ms", value, "ms",
false);
return true;
}
static std::string ExtractSsrcIdentifier(const std::string& key) {
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);
}
static std::set<std::string> FindAllSsrcIdentifiers(
const base::DictionaryValue& stats_dict) {
std::set<std::string> result;
base::DictionaryValue::Iterator stats_iterator(stats_dict);
while (!stats_iterator.IsAtEnd()) {
if (stats_iterator.key().find("ssrc_") != std::string::npos)
result.insert(ExtractSsrcIdentifier(stats_iterator.key()));
stats_iterator.Advance();
}
return result;
}
namespace test {
void PrintBweForVideoMetrics(const base::DictionaryValue& pc_dict) {
const std::string kBweStatsKey = "bweforvideo";
std::string value;
ASSERT_TRUE(pc_dict.GetString(
Statistic("googAvailableSendBandwidth", kBweStatsKey), &value));
perf_test::PrintResult("bwe_stats", "", "available_send_bw", value, "bytes/s",
false);
ASSERT_TRUE(pc_dict.GetString(
Statistic("googAvailableReceiveBandwidth", kBweStatsKey), &value));
perf_test::PrintResult("bwe_stats", "", "available_recv_bw", value, "bytes/s",
false);
ASSERT_TRUE(pc_dict.GetString(Statistic("googTargetEncBitrate", kBweStatsKey),
&value));
perf_test::PrintResult("bwe_stats", "", "target_enc_bitrate", value, "bit/s",
false);
ASSERT_TRUE(pc_dict.GetString(Statistic("googActualEncBitrate", kBweStatsKey),
&value));
perf_test::PrintResult("bwe_stats", "", "actual_enc_bitrate", value, "bit/s",
false);
ASSERT_TRUE(pc_dict.GetString(Statistic("googTransmitBitrate", kBweStatsKey),
&value));
perf_test::PrintResult("bwe_stats", "", "transmit_bitrate", value, "bit/s",
false);
}
void PrintMetricsForAllStreams(const base::DictionaryValue& pc_dict) {
const base::DictionaryValue* stats_dict;
ASSERT_TRUE(pc_dict.GetDictionary("stats", &stats_dict));
std::set<std::string> ssrc_identifiers = FindAllSsrcIdentifiers(*stats_dict);
std::set<std::string>::const_iterator ssrc_iterator =
ssrc_identifiers.begin();
for (; ssrc_iterator != ssrc_identifiers.end(); ++ssrc_iterator) {
const std::string& ssrc = *ssrc_iterator;
bool did_recognize_stream_type =
MaybePrintResultsForAudioReceive(ssrc, pc_dict) ||
MaybePrintResultsForAudioSend(ssrc, pc_dict) ||
MaybePrintResultsForVideoReceive(ssrc, pc_dict) ||
MaybePrintResultsForVideoSend(ssrc, pc_dict);
ASSERT_TRUE(did_recognize_stream_type) << "Failed to figure out which "
"kind of stream SSRC " << ssrc
<< " is. ";
}
}
}