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