Add Chromium's perf_test to testsupport.
Review URL: https://webrtc-codereview.appspot.com/936027 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3133 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
0f34fd7660
commit
2009f6b236
@ -35,17 +35,19 @@
|
||||
'sources': [
|
||||
'test_suite.cc',
|
||||
'test_suite.h',
|
||||
'testsupport/fileutils.h',
|
||||
'testsupport/fileutils.cc',
|
||||
'testsupport/frame_reader.h',
|
||||
'testsupport/fileutils.h',
|
||||
'testsupport/frame_reader.cc',
|
||||
'testsupport/frame_writer.h',
|
||||
'testsupport/frame_reader.h',
|
||||
'testsupport/frame_writer.cc',
|
||||
'testsupport/frame_writer.h',
|
||||
'testsupport/gtest_prod_util.h',
|
||||
'testsupport/packet_reader.h',
|
||||
'testsupport/packet_reader.cc',
|
||||
'testsupport/mock/mock_frame_reader.h',
|
||||
'testsupport/mock/mock_frame_writer.h',
|
||||
'testsupport/packet_reader.cc',
|
||||
'testsupport/packet_reader.h',
|
||||
'testsupport/perf_test.cc',
|
||||
'testsupport/perf_test.h',
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -90,6 +92,7 @@
|
||||
'testsupport/frame_reader_unittest.cc',
|
||||
'testsupport/frame_writer_unittest.cc',
|
||||
'testsupport/packet_reader_unittest.cc',
|
||||
'testsupport/perf_test_unittest.cc',
|
||||
],
|
||||
},
|
||||
],
|
||||
|
177
webrtc/test/testsupport/perf_test.cc
Normal file
177
webrtc/test/testsupport/perf_test.cc
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (c) 2012 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.
|
||||
*/
|
||||
|
||||
// A stripped-down version of Chromium's chrome/test/perf/perf_test.cc.
|
||||
// ResultsToString(), PrintResult(size_t value) and AppendResult(size_t value)
|
||||
// have been modified. The remainder are identical to the Chromium version.
|
||||
|
||||
#include "webrtc/test/testsupport/perf_test.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
std::string ResultsToString(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& values,
|
||||
const std::string& prefix,
|
||||
const std::string& suffix,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
// <*>RESULT <graph_name>: <trace_name>= <value> <units>
|
||||
// <*>RESULT <graph_name>: <trace_name>= {<mean>, <std deviation>} <units>
|
||||
// <*>RESULT <graph_name>: <trace_name>= [<value>,value,value,...,] <units>
|
||||
|
||||
// TODO(ajm): Use of a stream here may violate the style guide (depending on
|
||||
// one's definition of "logging"). Consider adding StringPrintf-like
|
||||
// functionality as in the original Chromium implementation.
|
||||
std::ostringstream stream;
|
||||
if (important) {
|
||||
stream << "*";
|
||||
}
|
||||
stream << "RESULT " << measurement << modifier << ": " << trace << "= "
|
||||
<< prefix << values << suffix << " " << units << std::endl;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
void PrintResultsImpl(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& values,
|
||||
const std::string& prefix,
|
||||
const std::string& suffix,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
printf("%s", ResultsToString(measurement, modifier, trace, values,
|
||||
prefix, suffix, units, important).c_str());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
void PrintResult(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
size_t value,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
std::ostringstream value_stream;
|
||||
value_stream << value;
|
||||
PrintResultsImpl(measurement, modifier, trace, value_stream.str(), "", "",
|
||||
units, important);
|
||||
}
|
||||
|
||||
void AppendResult(std::string& output,
|
||||
const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
size_t value,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
std::ostringstream value_stream;
|
||||
value_stream << value;
|
||||
output += ResultsToString(measurement, modifier, trace,
|
||||
value_stream.str(),
|
||||
"", "", units, important);
|
||||
}
|
||||
|
||||
void PrintResult(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& value,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
PrintResultsImpl(measurement, modifier, trace, value, "", "", units,
|
||||
important);
|
||||
}
|
||||
|
||||
void AppendResult(std::string& output,
|
||||
const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& value,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
output += ResultsToString(measurement, modifier, trace, value, "", "", units,
|
||||
important);
|
||||
}
|
||||
|
||||
void PrintResultMeanAndError(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& mean_and_error,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
PrintResultsImpl(measurement, modifier, trace, mean_and_error,
|
||||
"{", "}", units, important);
|
||||
}
|
||||
|
||||
void AppendResultMeanAndError(std::string& output,
|
||||
const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& mean_and_error,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
output += ResultsToString(measurement, modifier, trace, mean_and_error,
|
||||
"{", "}", units, important);
|
||||
}
|
||||
|
||||
void PrintResultList(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& values,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
PrintResultsImpl(measurement, modifier, trace, values,
|
||||
"[", "]", units, important);
|
||||
}
|
||||
|
||||
void AppendResultList(std::string& output,
|
||||
const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& values,
|
||||
const std::string& units,
|
||||
bool important) {
|
||||
output += ResultsToString(measurement, modifier, trace, values,
|
||||
"[", "]", units, important);
|
||||
}
|
||||
|
||||
void PrintSystemCommitCharge(const std::string& test_name,
|
||||
size_t charge,
|
||||
bool important) {
|
||||
PrintSystemCommitCharge(stdout, test_name, charge, important);
|
||||
}
|
||||
|
||||
void PrintSystemCommitCharge(FILE* target,
|
||||
const std::string& test_name,
|
||||
size_t charge,
|
||||
bool important) {
|
||||
fprintf(target, "%s", SystemCommitChargeToString(test_name, charge,
|
||||
important).c_str());
|
||||
}
|
||||
|
||||
std::string SystemCommitChargeToString(const std::string& test_name,
|
||||
size_t charge,
|
||||
bool important) {
|
||||
std::string trace_name(test_name);
|
||||
std::string output;
|
||||
AppendResult(output, "commit_charge", "", "cc" + trace_name, charge, "kb",
|
||||
important);
|
||||
return output;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
122
webrtc/test/testsupport/perf_test.h
Normal file
122
webrtc/test/testsupport/perf_test.h
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2012 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.
|
||||
*/
|
||||
|
||||
// A stripped-down version of Chromium's chrome/test/perf/perf_test.h.
|
||||
// Several functions have been removed; the prototypes of the remainder have
|
||||
// not been changed.
|
||||
|
||||
#ifndef WEBRTC_TEST_TESTSUPPORT_PERF_TEST_H_
|
||||
#define WEBRTC_TEST_TESTSUPPORT_PERF_TEST_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
// Prints numerical information to stdout in a controlled format, for
|
||||
// post-processing. |measurement| is a description of the quantity being
|
||||
// measured, e.g. "vm_peak"; |modifier| is provided as a convenience and
|
||||
// will be appended directly to the name of the |measurement|, e.g.
|
||||
// "_browser"; |trace| is a description of the particular data point, e.g.
|
||||
// "reference"; |value| is the measured value; and |units| is a description
|
||||
// of the units of measure, e.g. "bytes". If |important| is true, the output
|
||||
// line will be specially marked, to notify the post-processor. The strings
|
||||
// may be empty. They should not contain any colons (:) or equals signs (=).
|
||||
// A typical post-processing step would be to produce graphs of the data
|
||||
// produced for various builds, using the combined |measurement| + |modifier|
|
||||
// string to specify a particular graph and the |trace| to identify a trace
|
||||
// (i.e., data series) on that graph.
|
||||
void PrintResult(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
size_t value,
|
||||
const std::string& units,
|
||||
bool important);
|
||||
|
||||
void AppendResult(std::string& output,
|
||||
const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
size_t value,
|
||||
const std::string& units,
|
||||
bool important);
|
||||
|
||||
// Like the above version of PrintResult(), but takes a std::string value
|
||||
// instead of a size_t.
|
||||
void PrintResult(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& value,
|
||||
const std::string& units,
|
||||
bool important);
|
||||
|
||||
void AppendResult(std::string& output,
|
||||
const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& value,
|
||||
const std::string& units,
|
||||
bool important);
|
||||
|
||||
// Like PrintResult(), but prints a (mean, standard deviation) result pair.
|
||||
// The |<values>| should be two comma-separated numbers, the mean and
|
||||
// standard deviation (or other error metric) of the measurement.
|
||||
void PrintResultMeanAndError(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& mean_and_error,
|
||||
const std::string& units,
|
||||
bool important);
|
||||
|
||||
void AppendResultMeanAndError(std::string& output,
|
||||
const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& mean_and_error,
|
||||
const std::string& units,
|
||||
bool important);
|
||||
|
||||
// Like PrintResult(), but prints an entire list of results. The |values|
|
||||
// will generally be a list of comma-separated numbers. A typical
|
||||
// post-processing step might produce plots of their mean and standard
|
||||
// deviation.
|
||||
void PrintResultList(const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& values,
|
||||
const std::string& units,
|
||||
bool important);
|
||||
|
||||
void AppendResultList(std::string& output,
|
||||
const std::string& measurement,
|
||||
const std::string& modifier,
|
||||
const std::string& trace,
|
||||
const std::string& values,
|
||||
const std::string& units,
|
||||
bool important);
|
||||
|
||||
// Prints memory commit charge stats for use by perf graphs.
|
||||
void PrintSystemCommitCharge(const std::string& test_name,
|
||||
size_t charge,
|
||||
bool important);
|
||||
|
||||
void PrintSystemCommitCharge(FILE* target,
|
||||
const std::string& test_name,
|
||||
size_t charge,
|
||||
bool important);
|
||||
|
||||
std::string SystemCommitChargeToString(const std::string& test_name,
|
||||
size_t charge,
|
||||
bool important);
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_TEST_TESTSUPPORT_PERF_TEST_H_
|
34
webrtc/test/testsupport/perf_test_unittest.cc
Normal file
34
webrtc/test/testsupport/perf_test_unittest.cc
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2012 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 "webrtc/test/testsupport/perf_test.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
TEST(PerfTest, AppendResult) {
|
||||
std::string expected = "RESULT measurementmodifier: trace= 42 units\n";
|
||||
std::string output;
|
||||
AppendResult(output, "measurement", "modifier", "trace", 42, "units", false);
|
||||
EXPECT_EQ(expected, output);
|
||||
std::cout << output;
|
||||
|
||||
expected += "*RESULT foobar: baz= 7 widgets\n";
|
||||
AppendResult(output, "foo", "bar", "baz", 7, "widgets", true);
|
||||
EXPECT_EQ(expected, output);
|
||||
std::cout << output;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
Loading…
x
Reference in New Issue
Block a user