1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TEST_PERF_TIME_LOGGER_H_ 6 #define BASE_TEST_PERF_TIME_LOGGER_H_ 7 8 #include <string> 9 10 #include "base/timer/elapsed_timer.h" 11 12 namespace base { 13 14 // Automates calling LogPerfResult for the common case where you want 15 // to measure the time that something took. Call Done() when the test 16 // is complete if you do extra work after the test or there are stack 17 // objects with potentially expensive constructors. Otherwise, this 18 // class with automatically log on destruction. 19 class PerfTimeLogger { 20 public: 21 explicit PerfTimeLogger(const char* test_name); 22 23 PerfTimeLogger(const PerfTimeLogger&) = delete; 24 PerfTimeLogger& operator=(const PerfTimeLogger&) = delete; 25 26 ~PerfTimeLogger(); 27 28 void Done(); 29 30 private: 31 bool logged_; 32 std::string test_name_; 33 ElapsedTimer timer_; 34 }; 35 36 } // namespace base 37 38 #endif // BASE_TEST_PERF_TIME_LOGGER_H_ 39