perf_time_logger.h 977 B

12345678910111213141516171819202122232425262728293031323334353637
  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/macros.h"
  8. #include "base/timer/elapsed_timer.h"
  9. namespace base {
  10. // Automates calling LogPerfResult for the common case where you want
  11. // to measure the time that something took. Call Done() when the test
  12. // is complete if you do extra work after the test or there are stack
  13. // objects with potentially expensive constructors. Otherwise, this
  14. // class with automatically log on destruction.
  15. class PerfTimeLogger {
  16. public:
  17. explicit PerfTimeLogger(const char* test_name);
  18. ~PerfTimeLogger();
  19. void Done();
  20. private:
  21. bool logged_;
  22. std::string test_name_;
  23. ElapsedTimer timer_;
  24. DISALLOW_COPY_AND_ASSIGN(PerfTimeLogger);
  25. };
  26. } // namespace base
  27. #endif // BASE_TEST_PERF_TIME_LOGGER_H_