mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 16:47:50 +01:00

The new interface is called PerfTestResultWriter and is currently implemented by PerfResultsLogger (renamed PerfTestGraphJsonWriter). I plan to introduce a second implementation of the perf logger that uses the new Histogram C++ API. I add a flag that chooses between the two implementations so I can try it out (perhaps by setting up a second, limited run of webrtc_perf_tests on the perf bots that uses the new implementation). The histogram C++ implementation will come in the next patch. As a side effect, I disentangled the plottable counter printer from the perf result printer so it will work for both implementations. The only thing they had in common was that both wrote JSON anyway. See the bug for details on the new API. Bug: chromium:1029452 Change-Id: Icb21b25ced08ea73aeecd221e9d51f2adf3dab1b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165389 Reviewed-by: Artem Titov <titovartem@webrtc.org> Commit-Queue: Patrik Höglund <phoglund@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30243}
144 lines
4.7 KiB
C++
144 lines
4.7 KiB
C++
/*
|
|
* Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "test/testsupport/perf_test_graphjson_writer.h"
|
|
|
|
#include <fstream>
|
|
#include <map>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "rtc_base/checks.h"
|
|
#include "rtc_base/critical_section.h"
|
|
|
|
namespace webrtc {
|
|
namespace test {
|
|
|
|
std::string UnitWithDirection(
|
|
const std::string& units,
|
|
webrtc::test::ImproveDirection improve_direction) {
|
|
switch (improve_direction) {
|
|
case webrtc::test::ImproveDirection::kNone:
|
|
return units;
|
|
case webrtc::test::ImproveDirection::kSmallerIsBetter:
|
|
return units + "_smallerIsBetter";
|
|
case webrtc::test::ImproveDirection::kBiggerIsBetter:
|
|
return units + "_biggerIsBetter";
|
|
}
|
|
}
|
|
|
|
template <typename Container>
|
|
void OutputListToStream(std::ostream* ostream, const Container& values) {
|
|
const char* sep = "";
|
|
for (const auto& v : values) {
|
|
(*ostream) << sep << v;
|
|
sep = ",";
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
|
|
class PerfTestGraphJsonWriter : public PerfTestResultWriter {
|
|
public:
|
|
PerfTestGraphJsonWriter() : crit_(), graphs_() {}
|
|
void ClearResults() {
|
|
rtc::CritScope lock(&crit_);
|
|
graphs_.clear();
|
|
}
|
|
|
|
void LogResult(const std::string& graph_name,
|
|
const std::string& trace_name,
|
|
const double value,
|
|
const std::string& units,
|
|
const bool important,
|
|
webrtc::test::ImproveDirection improve_direction) {
|
|
std::ostringstream json_stream;
|
|
json_stream << '"' << trace_name << R"(":{)";
|
|
json_stream << R"("type":"scalar",)";
|
|
json_stream << R"("value":)" << value << ',';
|
|
json_stream << R"("units":")" << UnitWithDirection(units, improve_direction)
|
|
<< R"("})";
|
|
rtc::CritScope lock(&crit_);
|
|
graphs_[graph_name].push_back(json_stream.str());
|
|
}
|
|
|
|
void LogResultMeanAndError(const std::string& graph_name,
|
|
const std::string& trace_name,
|
|
const double mean,
|
|
const double error,
|
|
const std::string& units,
|
|
const bool important,
|
|
webrtc::test::ImproveDirection improve_direction) {
|
|
std::ostringstream json_stream;
|
|
json_stream << '"' << trace_name << R"(":{)";
|
|
json_stream << R"("type":"list_of_scalar_values",)";
|
|
json_stream << R"("values":[)" << mean << "],";
|
|
json_stream << R"("std":)" << error << ',';
|
|
json_stream << R"("units":")" << UnitWithDirection(units, improve_direction)
|
|
<< R"("})";
|
|
rtc::CritScope lock(&crit_);
|
|
graphs_[graph_name].push_back(json_stream.str());
|
|
}
|
|
|
|
void LogResultList(const std::string& graph_name,
|
|
const std::string& trace_name,
|
|
const rtc::ArrayView<const double> values,
|
|
const std::string& units,
|
|
const bool important,
|
|
webrtc::test::ImproveDirection improve_direction) {
|
|
std::ostringstream value_stream;
|
|
value_stream.precision(8);
|
|
value_stream << '[';
|
|
OutputListToStream(&value_stream, values);
|
|
value_stream << ']';
|
|
|
|
std::ostringstream json_stream;
|
|
json_stream << '"' << trace_name << R"(":{)";
|
|
json_stream << R"("type":"list_of_scalar_values",)";
|
|
json_stream << R"("values":)" << value_stream.str() << ',';
|
|
json_stream << R"("units":")" << UnitWithDirection(units, improve_direction)
|
|
<< R"("})";
|
|
rtc::CritScope lock(&crit_);
|
|
graphs_[graph_name].push_back(json_stream.str());
|
|
}
|
|
|
|
std::string ToJSON() const {
|
|
std::ostringstream json_stream;
|
|
json_stream << R"({"format_version":"1.0",)";
|
|
json_stream << R"("charts":{)";
|
|
rtc::CritScope lock(&crit_);
|
|
for (auto graphs_it = graphs_.begin(); graphs_it != graphs_.end();
|
|
++graphs_it) {
|
|
if (graphs_it != graphs_.begin())
|
|
json_stream << ',';
|
|
json_stream << '"' << graphs_it->first << "\":";
|
|
json_stream << '{';
|
|
OutputListToStream(&json_stream, graphs_it->second);
|
|
json_stream << '}';
|
|
}
|
|
json_stream << "}}";
|
|
return json_stream.str();
|
|
}
|
|
|
|
private:
|
|
rtc::CriticalSection crit_;
|
|
std::map<std::string, std::vector<std::string>> graphs_
|
|
RTC_GUARDED_BY(&crit_);
|
|
};
|
|
|
|
} // namespace
|
|
|
|
PerfTestResultWriter* CreateGraphJsonWriter() {
|
|
return new PerfTestGraphJsonWriter();
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace webrtc
|