aboutsummaryrefslogtreecommitdiff
path: root/stats.h
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-30 03:29:35 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-30 14:40:05 +0900
commit0d8e79b7753a89ac6beaf638a535ec63f1941444 (patch)
tree560f2c13a5ab1ae528b8425c46aca5046c7f319f /stats.h
parent24d7a4abad957537c1e9cd32185ab5f53b1016c4 (diff)
downloadkati-0d8e79b7753a89ac6beaf638a535ec63f1941444.tar.gz
[C++] Add a way to retrieve stats
Diffstat (limited to 'stats.h')
-rw-r--r--stats.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/stats.h b/stats.h
new file mode 100644
index 0000000..41525e1
--- /dev/null
+++ b/stats.h
@@ -0,0 +1,54 @@
+// Copyright 2015 Google Inc. All rights reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef STATS_H_
+#define STATS_H_
+
+#include <string>
+
+using namespace std;
+
+class Stats {
+ public:
+ explicit Stats(const char* name);
+
+ string String() const;
+
+ private:
+ void Start();
+ void End();
+
+ friend class ScopedStatsRecorder;
+
+ const char* name_;
+ double start_time_;
+ double elapsed_;
+};
+
+class ScopedStatsRecorder {
+ public:
+ explicit ScopedStatsRecorder(Stats* st);
+ ~ScopedStatsRecorder();
+
+ private:
+ Stats* st_;
+};
+
+void ReportAllStats();
+
+#define COLLECT_STATS(name) \
+ static Stats stats(name); \
+ ScopedStatsRecorder ssr(&stats)
+
+#endif // STATS_H_