blob: e8608cdf7740cb2af8c2d68596f5f24a625bafda [file] [log] [blame]
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11// A stripped-down version of Chromium's chrome/test/perf/perf_test.cc.
12// ResultsToString(), PrintResult(size_t value) and AppendResult(size_t value)
13// have been modified. The remainder are identical to the Chromium version.
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "test/testsupport/perf_test.h"
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000016
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000017#include <sstream>
pbos@webrtc.org34741c82013-05-27 08:02:22 +000018#include <stdio.h>
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000019
20namespace {
21
22std::string ResultsToString(const std::string& measurement,
23 const std::string& modifier,
24 const std::string& trace,
25 const std::string& values,
26 const std::string& prefix,
27 const std::string& suffix,
28 const std::string& units,
29 bool important) {
30 // <*>RESULT <graph_name>: <trace_name>= <value> <units>
31 // <*>RESULT <graph_name>: <trace_name>= {<mean>, <std deviation>} <units>
32 // <*>RESULT <graph_name>: <trace_name>= [<value>,value,value,...,] <units>
33
34 // TODO(ajm): Use of a stream here may violate the style guide (depending on
35 // one's definition of "logging"). Consider adding StringPrintf-like
36 // functionality as in the original Chromium implementation.
37 std::ostringstream stream;
38 if (important) {
39 stream << "*";
40 }
41 stream << "RESULT " << measurement << modifier << ": " << trace << "= "
42 << prefix << values << suffix << " " << units << std::endl;
43 return stream.str();
44}
45
46void PrintResultsImpl(const std::string& measurement,
47 const std::string& modifier,
48 const std::string& trace,
49 const std::string& values,
50 const std::string& prefix,
51 const std::string& suffix,
52 const std::string& units,
53 bool important) {
54 printf("%s", ResultsToString(measurement, modifier, trace, values,
55 prefix, suffix, units, important).c_str());
56}
57
58} // namespace
59
60namespace webrtc {
61namespace test {
62
63void PrintResult(const std::string& measurement,
64 const std::string& modifier,
65 const std::string& trace,
Edward Lemur6a822072017-11-22 19:17:50 +010066 const double value,
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000067 const std::string& units,
68 bool important) {
69 std::ostringstream value_stream;
70 value_stream << value;
71 PrintResultsImpl(measurement, modifier, trace, value_stream.str(), "", "",
72 units, important);
73}
74
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000075void PrintResultMeanAndError(const std::string& measurement,
76 const std::string& modifier,
77 const std::string& trace,
78 const std::string& mean_and_error,
79 const std::string& units,
80 bool important) {
81 PrintResultsImpl(measurement, modifier, trace, mean_and_error,
82 "{", "}", units, important);
83}
84
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000085void PrintResultList(const std::string& measurement,
86 const std::string& modifier,
87 const std::string& trace,
88 const std::string& values,
89 const std::string& units,
90 bool important) {
91 PrintResultsImpl(measurement, modifier, trace, values,
92 "[", "]", units, important);
93}
94
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000095} // namespace test
96} // namespace webrtc