Chromium Code Reviews| Index: components/visitedlink/test/visitedlink_perftest.cc |
| diff --git a/components/visitedlink/test/visitedlink_perftest.cc b/components/visitedlink/test/visitedlink_perftest.cc |
| index 5bf7b600367934f8bc3ff96192a8a278fd6fc228..40c77f5d8205c937a73b16bf3bab6c67f3c8e502 100644 |
| --- a/components/visitedlink/test/visitedlink_perftest.cc |
| +++ b/components/visitedlink/test/visitedlink_perftest.cc |
| @@ -9,14 +9,13 @@ |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| #include "base/strings/stringprintf.h" |
| -#include "base/test/perf_log.h" |
| -#include "base/test/perf_time_logger.h" |
| #include "base/test/test_file_util.h" |
| #include "base/timer/elapsed_timer.h" |
| #include "components/visitedlink/browser/visitedlink_master.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
| #include "content/public/test/test_utils.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "testing/perf/perf_test.h" |
| #include "url/gurl.h" |
| using base::TimeDelta; |
| @@ -25,6 +24,39 @@ namespace visitedlink { |
| namespace { |
| +// Designed like base/test/perf_time_logger but uses testing/perf instead of |
| +// base/test/perf* to report timings. |
| +class TimeLogger { |
| + public: |
| + explicit TimeLogger(std::string test_name); |
|
Alexei Svitkine (slow)
2016/10/21 19:01:46
Nit: const&
Peter Kasting
2016/10/21 19:45:21
Can't, he's doing std::move() below to move into t
|
| + ~TimeLogger(); |
| + void Done(); |
| + |
| + private: |
| + bool logged_; |
| + std::string test_name_; |
| + base::ElapsedTimer timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TimeLogger); |
| +}; |
| + |
| +TimeLogger::TimeLogger(std::string test_name) |
| + : logged_(false), test_name_(std::move(test_name)) {} |
| + |
| +TimeLogger::~TimeLogger() { |
| + if (!logged_) |
| + Done(); |
| +} |
| + |
| +void TimeLogger::Done() { |
| + // We use a floating-point millisecond value because it is more |
| + // intuitive than microseconds and we want more precision than |
| + // integer milliseconds. |
| + perf_test::PrintResult(test_name_, std::string(), std::string(), |
| + timer_.Elapsed().InMillisecondsF(), "ms", true); |
| + logged_ = true; |
| +} |
| + |
| // how we generate URLs, note that the two strings should be the same length |
| const int add_count = 10000; |
| const int load_test_add_count = 250000; |
| @@ -86,7 +118,7 @@ TEST_F(VisitedLink, TestAddAndQuery) { |
| ASSERT_TRUE(master.Init()); |
| content::RunAllBlockingPoolTasksUntilIdle(); |
| - base::PerfTimeLogger timer("Visited_link_add_and_query"); |
| + TimeLogger timer("Visited_link_add_and_query"); |
| // first check without anything in the table |
| CheckVisited(master, added_prefix, 0, add_count); |
| @@ -111,13 +143,13 @@ TEST_F(VisitedLink, TestAddAndQuery) { |
| TEST_F(VisitedLink, TestLoad) { |
| // create a big DB |
| { |
| - base::PerfTimeLogger table_initialization_timer("Table_initialization"); |
| + TimeLogger table_initialization_timer("Table_initialization"); |
| VisitedLinkMaster master(new DummyVisitedLinkEventListener(), |
| NULL, true, true, db_path_, 0); |
| // time init with empty table |
| - base::PerfTimeLogger initTimer("Empty_visited_link_init"); |
| + TimeLogger initTimer("Empty_visited_link_init"); |
| bool success = master.Init(); |
| content::RunAllBlockingPoolTasksUntilIdle(); |
| initTimer.Done(); |
| @@ -130,7 +162,7 @@ TEST_F(VisitedLink, TestLoad) { |
| FillTable(master, added_prefix, 0, load_test_add_count); |
| // time writing the file out out |
| - base::PerfTimeLogger flushTimer("Visited_link_database_flush"); |
| + TimeLogger flushTimer("Visited_link_database_flush"); |
| master.RewriteFile(); |
| // TODO(maruel): Without calling FlushFileBuffers(master.file_); you don't |
| // know really how much time it took to write the file. |
| @@ -196,10 +228,13 @@ TEST_F(VisitedLink, TestLoad) { |
| cold_sum += cold_load_times[i]; |
| hot_sum += hot_load_times[i]; |
| } |
| - base::LogPerfResult( |
| - "Visited_link_cold_load_time", cold_sum / cold_load_times.size(), "ms"); |
| - base::LogPerfResult( |
| - "Visited_link_hot_load_time", hot_sum / hot_load_times.size(), "ms"); |
| + |
| + perf_test::PrintResult("Visited_link_cold_load_time", std::string(), |
| + std::string(), cold_sum / cold_load_times.size(), "ms", |
| + true); |
| + perf_test::PrintResult("Visited_link_hot_load_time", std::string(), |
| + std::string(), hot_sum / hot_load_times.size(), "ms", |
| + true); |
| } |
| } // namespace visitedlink |