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..898f6c218a7a805aab4920b33bbb915487f492db 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,38 @@ namespace visitedlink { |
| namespace { |
| +// designed like base/test/perf_time_logger, but uses different output strategy. |
|
Peter Kasting
2016/10/17 18:44:46
Nit: Initial capital
You might want to describe w
|
| +class TimeLogger { |
| + public: |
| + explicit TimeLogger(std::string test_name); |
| + ~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 |
|
Peter Kasting
2016/10/17 18:44:45
Nit: Add trailing period
|
| + perf_test::PrintResult(test_name_, "", "", timer_.Elapsed().InMillisecondsF(), |
|
Peter Kasting
2016/10/17 18:44:46
Nit: "" -> std::string()
|
| + "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 +117,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 +142,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 +161,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 +227,11 @@ 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", "", "", |
|
Peter Kasting
2016/10/17 18:44:45
Nit: "" -> std::string (2 places)
|
| + cold_sum / cold_load_times.size(), "ms", true); |
| + perf_test::PrintResult("Visited_link_hot_load_time", "", "", |
| + hot_sum / hot_load_times.size(), "ms", true); |
| } |
| } // namespace visitedlink |