Move media/base/simd/x86inc.asm to third_party/x86inc
[chromium-blink-merge.git] / base / perftimer.h
blob9a23ff1d6fe5a35dddf02484aa98bd9d710b9b99
1 // Copyright (c) 2006-2008 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.
5 #ifndef BASE_PERFTIMER_H_
6 #define BASE_PERFTIMER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/time.h"
13 namespace base {
14 class FilePath;
17 // ----------------------------------------------------------------------
18 // Initializes and finalizes the perf log. These functions should be
19 // called at the beginning and end (respectively) of running all the
20 // performance tests. The init function returns true on success.
21 // ----------------------------------------------------------------------
22 bool InitPerfLog(const base::FilePath& log_path);
23 void FinalizePerfLog();
25 // ----------------------------------------------------------------------
26 // LogPerfResult
27 // Writes to the perf result log the given 'value' resulting from the
28 // named 'test'. The units are to aid in reading the log by people.
29 // ----------------------------------------------------------------------
30 void LogPerfResult(const char* test_name, double value, const char* units);
32 // ----------------------------------------------------------------------
33 // PerfTimer
34 // A simple wrapper around Now()
35 // ----------------------------------------------------------------------
36 class PerfTimer {
37 public:
38 PerfTimer() {
39 begin_ = base::TimeTicks::Now();
42 // Returns the time elapsed since object construction
43 base::TimeDelta Elapsed() const {
44 return base::TimeTicks::Now() - begin_;
47 private:
48 base::TimeTicks begin_;
51 // ----------------------------------------------------------------------
52 // PerfTimeLogger
53 // Automates calling LogPerfResult for the common case where you want
54 // to measure the time that something took. Call Done() when the test
55 // is complete if you do extra work after the test or there are stack
56 // objects with potentially expensive constructors. Otherwise, this
57 // class with automatically log on destruction.
58 // ----------------------------------------------------------------------
59 class PerfTimeLogger {
60 public:
61 explicit PerfTimeLogger(const char* test_name)
62 : logged_(false),
63 test_name_(test_name) {
66 ~PerfTimeLogger() {
67 if (!logged_)
68 Done();
71 void Done() {
72 // we use a floating-point millisecond value because it is more
73 // intuitive than microseconds and we want more precision than
74 // integer milliseconds
75 LogPerfResult(test_name_.c_str(), timer_.Elapsed().InMillisecondsF(), "ms");
76 logged_ = true;
79 private:
80 bool logged_;
81 std::string test_name_;
82 PerfTimer timer_;
85 #endif // BASE_PERFTIMER_H_