summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-17 00:34:38 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-17 00:34:38 +0000
commit9db9c91eb1db09e024449309f0383932eb69a0ed (patch)
tree4795a8031a5a9e8646fa7b9c7402b5c5daaf4e62 /base
parent88dcdb78847445fb487e849d987c15694cf109cb (diff)
downloadchromium_src-9db9c91eb1db09e024449309f0383932eb69a0ed.zip
chromium_src-9db9c91eb1db09e024449309f0383932eb69a0ed.tar.gz
chromium_src-9db9c91eb1db09e024449309f0383932eb69a0ed.tar.bz2
base: Split logging functions and PerfTimeLogger out of perftimer.h
Soon PerfTimer will move into base/timer/ directory as it is already used by production code. This splits the logging stuff into their owns files and also moves PerfTimeLogger into its own files. BUG=None TEST=base_unittests, ipc_perftests, etc... R=brettw@chromium.org Review URL: https://chromiumcodereview.appspot.com/23985006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gyp7
-rw-r--r--base/test/perf_log.cc44
-rw-r--r--base/test/perf_log.h24
-rw-r--r--base/test/perf_test_suite.cc11
-rw-r--r--base/test/perf_time_logger.cc27
-rw-r--r--base/test/perf_time_logger.h37
-rw-r--r--base/test/perftimer.h56
7 files changed, 145 insertions, 61 deletions
diff --git a/base/base.gyp b/base/base.gyp
index bf3e261..7c988f3 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -886,9 +886,14 @@
'test/null_task_runner.h',
'test/parallel_test_launcher.cc',
'test/parallel_test_launcher.h',
+ 'test/perf_log.cc',
+ 'test/perf_log.h',
'test/perf_test_suite.cc',
'test/perf_test_suite.h',
+ 'test/perf_time_logger.cc',
+ 'test/perf_time_logger.h',
'test/perftimer.cc',
+ 'test/perftimer.h',
'test/power_monitor_test_base.cc',
'test/power_monitor_test_base.h',
'test/scoped_locale.cc',
@@ -964,10 +969,10 @@
'type': 'static_library',
'dependencies': [
'base',
+ 'test_support_base',
'../testing/gtest.gyp:gtest',
],
'sources': [
- 'test/perftimer.cc',
'test/run_all_perftests.cc',
],
'direct_dependent_settings': {
diff --git a/base/test/perf_log.cc b/base/test/perf_log.cc
new file mode 100644
index 0000000..aaeb26c
--- /dev/null
+++ b/base/test/perf_log.cc
@@ -0,0 +1,44 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/perf_log.h"
+
+#include "base/file_util.h"
+#include "base/logging.h"
+
+namespace base {
+
+static FILE* perf_log_file = NULL;
+
+bool InitPerfLog(const FilePath& log_file) {
+ if (perf_log_file) {
+ // trying to initialize twice
+ NOTREACHED();
+ return false;
+ }
+
+ perf_log_file = file_util::OpenFile(log_file, "w");
+ return perf_log_file != NULL;
+}
+
+void FinalizePerfLog() {
+ if (!perf_log_file) {
+ // trying to cleanup without initializing
+ NOTREACHED();
+ return;
+ }
+ file_util::CloseFile(perf_log_file);
+}
+
+void LogPerfResult(const char* test_name, double value, const char* units) {
+ if (!perf_log_file) {
+ NOTREACHED();
+ return;
+ }
+
+ fprintf(perf_log_file, "%s\t%g\t%s\n", test_name, value, units);
+ printf("%s\t%g\t%s\n", test_name, value, units);
+}
+
+} // namespace base
diff --git a/base/test/perf_log.h b/base/test/perf_log.h
new file mode 100644
index 0000000..5d6ed9f
--- /dev/null
+++ b/base/test/perf_log.h
@@ -0,0 +1,24 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TEST_PERF_LOG_H_
+#define BASE_TEST_PERF_LOG_H_
+
+namespace base {
+
+class FilePath;
+
+// Initializes and finalizes the perf log. These functions should be
+// called at the beginning and end (respectively) of running all the
+// performance tests. The init function returns true on success.
+bool InitPerfLog(const FilePath& log_path);
+void FinalizePerfLog();
+
+// Writes to the perf result log the given 'value' resulting from the
+// named 'test'. The units are to aid in reading the log by people.
+void LogPerfResult(const char* test_name, double value, const char* units);
+
+} // namespace base
+
+#endif // BASE_TEST_PERF_LOG_H_
diff --git a/base/test/perf_test_suite.cc b/base/test/perf_test_suite.cc
index 86be119..04ebb8b 100644
--- a/base/test/perf_test_suite.cc
+++ b/base/test/perf_test_suite.cc
@@ -10,13 +10,12 @@
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/strings/string_util.h"
-#include "base/test/perftimer.h"
+#include "base/test/perf_log.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
-PerfTestSuite::PerfTestSuite(int argc, char** argv) : TestSuite(argc, argv) {
-}
+PerfTestSuite::PerfTestSuite(int argc, char** argv) : TestSuite(argc, argv) {}
void PerfTestSuite::Initialize() {
TestSuite::Initialize();
@@ -26,7 +25,7 @@ void PerfTestSuite::Initialize() {
CommandLine::ForCurrentProcess()->GetSwitchValuePath("log-file");
if (log_path.empty()) {
FilePath exe;
- PathService::Get(base::FILE_EXE, &exe);
+ PathService::Get(FILE_EXE, &exe);
log_path = exe.ReplaceExtension(FILE_PATH_LITERAL("log"));
log_path = log_path.InsertBeforeExtension(FILE_PATH_LITERAL("_perf"));
}
@@ -34,8 +33,8 @@ void PerfTestSuite::Initialize() {
// Raise to high priority to have more precise measurements. Since we don't
// aim at 1% precision, it is not necessary to run at realtime level.
- if (!base::debug::BeingDebugged())
- base::RaiseProcessToHighPriority();
+ if (!debug::BeingDebugged())
+ RaiseProcessToHighPriority();
}
void PerfTestSuite::Shutdown() {
diff --git a/base/test/perf_time_logger.cc b/base/test/perf_time_logger.cc
new file mode 100644
index 0000000..c05ba51
--- /dev/null
+++ b/base/test/perf_time_logger.cc
@@ -0,0 +1,27 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/perf_time_logger.h"
+
+#include "base/test/perf_log.h"
+
+namespace base {
+
+PerfTimeLogger::PerfTimeLogger(const char* test_name)
+ : logged_(false), test_name_(test_name) {}
+
+PerfTimeLogger::~PerfTimeLogger() {
+ if (!logged_)
+ Done();
+}
+
+void PerfTimeLogger::Done() {
+ // we use a floating-point millisecond value because it is more
+ // intuitive than microseconds and we want more precision than
+ // integer milliseconds
+ LogPerfResult(test_name_.c_str(), timer_.Elapsed().InMillisecondsF(), "ms");
+ logged_ = true;
+}
+
+} // namespace base
diff --git a/base/test/perf_time_logger.h b/base/test/perf_time_logger.h
new file mode 100644
index 0000000..f23c530
--- /dev/null
+++ b/base/test/perf_time_logger.h
@@ -0,0 +1,37 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TEST_PERF_TIME_LOGGER_H_
+#define BASE_TEST_PERF_TIME_LOGGER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/test/perftimer.h"
+
+namespace base {
+
+// Automates calling LogPerfResult for the common case where you want
+// to measure the time that something took. Call Done() when the test
+// is complete if you do extra work after the test or there are stack
+// objects with potentially expensive constructors. Otherwise, this
+// class with automatically log on destruction.
+class PerfTimeLogger {
+ public:
+ explicit PerfTimeLogger(const char* test_name);
+ ~PerfTimeLogger();
+
+ void Done();
+
+ private:
+ bool logged_;
+ std::string test_name_;
+ PerfTimer timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(PerfTimeLogger);
+};
+
+} // namespace base
+
+#endif // BASE_TEST_PERF_TIME_LOGGER_H_
diff --git a/base/test/perftimer.h b/base/test/perftimer.h
index 1a26cf5..86ee126 100644
--- a/base/test/perftimer.h
+++ b/base/test/perftimer.h
@@ -5,8 +5,6 @@
#ifndef BASE_TEST_PERFTIMER_H_
#define BASE_TEST_PERFTIMER_H_
-#include <string>
-
#include "base/basictypes.h"
#include "base/time/time.h"
@@ -14,25 +12,7 @@ namespace base {
class FilePath;
}
-// ----------------------------------------------------------------------
-// Initializes and finalizes the perf log. These functions should be
-// called at the beginning and end (respectively) of running all the
-// performance tests. The init function returns true on success.
-// ----------------------------------------------------------------------
-bool InitPerfLog(const base::FilePath& log_path);
-void FinalizePerfLog();
-
-// ----------------------------------------------------------------------
-// LogPerfResult
-// Writes to the perf result log the given 'value' resulting from the
-// named 'test'. The units are to aid in reading the log by people.
-// ----------------------------------------------------------------------
-void LogPerfResult(const char* test_name, double value, const char* units);
-
-// ----------------------------------------------------------------------
-// PerfTimer
-// A simple wrapper around Now()
-// ----------------------------------------------------------------------
+// A simple wrapper around Now()
class PerfTimer {
public:
PerfTimer() {
@@ -46,40 +26,8 @@ class PerfTimer {
private:
base::TimeTicks begin_;
-};
-
-// ----------------------------------------------------------------------
-// PerfTimeLogger
-// Automates calling LogPerfResult for the common case where you want
-// to measure the time that something took. Call Done() when the test
-// is complete if you do extra work after the test or there are stack
-// objects with potentially expensive constructors. Otherwise, this
-// class with automatically log on destruction.
-// ----------------------------------------------------------------------
-class PerfTimeLogger {
- public:
- explicit PerfTimeLogger(const char* test_name)
- : logged_(false),
- test_name_(test_name) {
- }
-
- ~PerfTimeLogger() {
- if (!logged_)
- Done();
- }
- void Done() {
- // we use a floating-point millisecond value because it is more
- // intuitive than microseconds and we want more precision than
- // integer milliseconds
- LogPerfResult(test_name_.c_str(), timer_.Elapsed().InMillisecondsF(), "ms");
- logged_ = true;
- }
-
- private:
- bool logged_;
- std::string test_name_;
- PerfTimer timer_;
+ DISALLOW_COPY_AND_ASSIGN(PerfTimer);
};
#endif // BASE_TEST_PERFTIMER_H_