blob: 6e49ac90e0e8653cc9550e88ef4fa1b1a8ce8f81 [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.h.
12// Several functions have been removed; the prototypes of the remainder have
13// not been changed.
14
15#ifndef WEBRTC_TEST_TESTSUPPORT_PERF_TEST_H_
16#define WEBRTC_TEST_TESTSUPPORT_PERF_TEST_H_
17
danilchap46b89b92016-06-03 09:27:37 -070018#include <sstream>
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000019#include <string>
20
21namespace webrtc {
22namespace test {
23
24// Prints numerical information to stdout in a controlled format, for
25// post-processing. |measurement| is a description of the quantity being
26// measured, e.g. "vm_peak"; |modifier| is provided as a convenience and
27// will be appended directly to the name of the |measurement|, e.g.
28// "_browser"; |trace| is a description of the particular data point, e.g.
29// "reference"; |value| is the measured value; and |units| is a description
30// of the units of measure, e.g. "bytes". If |important| is true, the output
31// line will be specially marked, to notify the post-processor. The strings
32// may be empty. They should not contain any colons (:) or equals signs (=).
33// A typical post-processing step would be to produce graphs of the data
34// produced for various builds, using the combined |measurement| + |modifier|
35// string to specify a particular graph and the |trace| to identify a trace
36// (i.e., data series) on that graph.
37void PrintResult(const std::string& measurement,
38 const std::string& modifier,
39 const std::string& trace,
40 size_t value,
41 const std::string& units,
42 bool important);
43
44void AppendResult(std::string& output,
45 const std::string& measurement,
46 const std::string& modifier,
47 const std::string& trace,
48 size_t value,
49 const std::string& units,
50 bool important);
51
52// Like the above version of PrintResult(), but takes a std::string value
53// instead of a size_t.
54void PrintResult(const std::string& measurement,
55 const std::string& modifier,
56 const std::string& trace,
57 const std::string& value,
58 const std::string& units,
59 bool important);
60
61void AppendResult(std::string& output,
62 const std::string& measurement,
63 const std::string& modifier,
64 const std::string& trace,
65 const std::string& value,
66 const std::string& units,
67 bool important);
68
69// Like PrintResult(), but prints a (mean, standard deviation) result pair.
70// The |<values>| should be two comma-separated numbers, the mean and
71// standard deviation (or other error metric) of the measurement.
72void PrintResultMeanAndError(const std::string& measurement,
73 const std::string& modifier,
74 const std::string& trace,
75 const std::string& mean_and_error,
76 const std::string& units,
77 bool important);
78
79void AppendResultMeanAndError(std::string& output,
80 const std::string& measurement,
81 const std::string& modifier,
82 const std::string& trace,
83 const std::string& mean_and_error,
84 const std::string& units,
85 bool important);
86
87// Like PrintResult(), but prints an entire list of results. The |values|
88// will generally be a list of comma-separated numbers. A typical
89// post-processing step might produce plots of their mean and standard
90// deviation.
91void PrintResultList(const std::string& measurement,
92 const std::string& modifier,
93 const std::string& trace,
94 const std::string& values,
95 const std::string& units,
96 bool important);
97
98void AppendResultList(std::string& output,
99 const std::string& measurement,
100 const std::string& modifier,
101 const std::string& trace,
102 const std::string& values,
103 const std::string& units,
104 bool important);
105
106// Prints memory commit charge stats for use by perf graphs.
107void PrintSystemCommitCharge(const std::string& test_name,
108 size_t charge,
109 bool important);
110
111void PrintSystemCommitCharge(FILE* target,
112 const std::string& test_name,
113 size_t charge,
114 bool important);
115
116std::string SystemCommitChargeToString(const std::string& test_name,
117 size_t charge,
118 bool important);
119
danilchap46b89b92016-06-03 09:27:37 -0700120// Converts list of values into comma-separated string for PrintResultList.
121template <typename Container>
122std::string ValuesToString(const Container& container) {
123 if (container.empty())
124 return "";
125
126 std::stringstream ss;
127 auto it = container.begin();
128 while (true) {
129 ss << *it;
130 if (++it == container.end())
131 break;
132 ss << ',';
133 }
134 return ss.str();
135}
136
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +0000137} // namespace test
138} // namespace webrtc
139
140#endif // WEBRTC_TEST_TESTSUPPORT_PERF_TEST_H_