blob: 41525e116e9deff0c62ced96e6ccd7087d1c604b [file] [log] [blame]
Shinichiro Hamaji0d8e79b2015-06-30 03:29:35 +09001// Copyright 2015 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef STATS_H_
16#define STATS_H_
17
18#include <string>
19
20using namespace std;
21
22class Stats {
23 public:
24 explicit Stats(const char* name);
25
26 string String() const;
27
28 private:
29 void Start();
30 void End();
31
32 friend class ScopedStatsRecorder;
33
34 const char* name_;
35 double start_time_;
36 double elapsed_;
37};
38
39class ScopedStatsRecorder {
40 public:
41 explicit ScopedStatsRecorder(Stats* st);
42 ~ScopedStatsRecorder();
43
44 private:
45 Stats* st_;
46};
47
48void ReportAllStats();
49
50#define COLLECT_STATS(name) \
51 static Stats stats(name); \
52 ScopedStatsRecorder ssr(&stats)
53
54#endif // STATS_H_