perf_time_logger.h 1020 B

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