From bb5c95c9bff8920f56d1737b27e2eb1ae99c54ad Mon Sep 17 00:00:00 2001 From: "tfarina@chromium.org" Date: Sat, 24 Aug 2013 15:09:45 +0000 Subject: Move perftimer.* into base/test/ directory. This should address the TODO from tools/gn/secondary/base/BUILD.gn BUG=None TEST=test_support_perf R=brettw@chromium.org TBR=cpu, dalecurtis, akalin, thestig Review URL: https://chromiumcodereview.appspot.com/22887041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219448 0039d316-1c4b-4281-b951-d872f2087c98 --- base/base.gyp | 6 ++-- base/perftimer.cc | 45 ----------------------- base/perftimer.h | 85 -------------------------------------------- base/test/perf_test_suite.cc | 2 +- base/test/perftimer.cc | 45 +++++++++++++++++++++++ base/test/perftimer.h | 85 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 134 deletions(-) delete mode 100644 base/perftimer.cc delete mode 100644 base/perftimer.h create mode 100644 base/test/perftimer.cc create mode 100644 base/test/perftimer.h (limited to 'base') diff --git a/base/base.gyp b/base/base.gyp index 39e9f33..fabc868 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -865,7 +865,6 @@ }], ], 'sources': [ - 'perftimer.cc', 'test/expectations/expectation.cc', 'test/expectations/expectation.h', 'test/expectations/parser.cc', @@ -885,6 +884,7 @@ 'test/null_task_runner.h', 'test/perf_test_suite.cc', 'test/perf_test_suite.h', + 'test/perftimer.cc', 'test/power_monitor_test_base.cc', 'test/power_monitor_test_base.h', 'test/scoped_locale.cc', @@ -935,9 +935,9 @@ 'test/thread_test_helper.h', 'test/trace_event_analyzer.cc', 'test/trace_event_analyzer.h', - 'test/unit_test_launcher_ios.cc', 'test/unit_test_launcher.cc', 'test/unit_test_launcher.h', + 'test/unit_test_launcher_ios.cc', 'test/values_test_util.cc', 'test/values_test_util.h', ], @@ -963,7 +963,7 @@ '../testing/gtest.gyp:gtest', ], 'sources': [ - 'perftimer.cc', + 'test/perftimer.cc', 'test/run_all_perftests.cc', ], 'direct_dependent_settings': { diff --git a/base/perftimer.cc b/base/perftimer.cc deleted file mode 100644 index 9ab7c6b..0000000 --- a/base/perftimer.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2006-2008 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/perftimer.h" - -#include -#include - -#include "base/basictypes.h" -#include "base/file_util.h" -#include "base/files/file_path.h" -#include "base/logging.h" - -static FILE* perf_log_file = NULL; - -bool InitPerfLog(const base::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); -} diff --git a/base/perftimer.h b/base/perftimer.h deleted file mode 100644 index 466f81d..0000000 --- a/base/perftimer.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2006-2008 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_PERFTIMER_H_ -#define BASE_PERFTIMER_H_ - -#include - -#include "base/basictypes.h" -#include "base/time/time.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 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() -// ---------------------------------------------------------------------- -class PerfTimer { - public: - PerfTimer() { - begin_ = base::TimeTicks::Now(); - } - - // Returns the time elapsed since object construction - base::TimeDelta Elapsed() const { - return base::TimeTicks::Now() - begin_; - } - - 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_; -}; - -#endif // BASE_PERFTIMER_H_ diff --git a/base/test/perf_test_suite.cc b/base/test/perf_test_suite.cc index 8cfbb73..86be119 100644 --- a/base/test/perf_test_suite.cc +++ b/base/test/perf_test_suite.cc @@ -8,9 +8,9 @@ #include "base/debug/debugger.h" #include "base/files/file_path.h" #include "base/path_service.h" -#include "base/perftimer.h" #include "base/process/launch.h" #include "base/strings/string_util.h" +#include "base/test/perftimer.h" #include "testing/gtest/include/gtest/gtest.h" namespace base { diff --git a/base/test/perftimer.cc b/base/test/perftimer.cc new file mode 100644 index 0000000..6815f0b --- /dev/null +++ b/base/test/perftimer.cc @@ -0,0 +1,45 @@ +// 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/perftimer.h" + +#include +#include + +#include "base/basictypes.h" +#include "base/file_util.h" +#include "base/files/file_path.h" +#include "base/logging.h" + +static FILE* perf_log_file = NULL; + +bool InitPerfLog(const base::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); +} diff --git a/base/test/perftimer.h b/base/test/perftimer.h new file mode 100644 index 0000000..1a26cf5 --- /dev/null +++ b/base/test/perftimer.h @@ -0,0 +1,85 @@ +// 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_PERFTIMER_H_ +#define BASE_TEST_PERFTIMER_H_ + +#include + +#include "base/basictypes.h" +#include "base/time/time.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 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() +// ---------------------------------------------------------------------- +class PerfTimer { + public: + PerfTimer() { + begin_ = base::TimeTicks::Now(); + } + + // Returns the time elapsed since object construction + base::TimeDelta Elapsed() const { + return base::TimeTicks::Now() - begin_; + } + + 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_; +}; + +#endif // BASE_TEST_PERFTIMER_H_ -- cgit v1.1