diff options
author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-06-30 03:29:35 +0900 |
---|---|---|
committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-06-30 14:40:05 +0900 |
commit | 0d8e79b7753a89ac6beaf638a535ec63f1941444 (patch) | |
tree | 560f2c13a5ab1ae528b8425c46aca5046c7f319f /stats.h | |
parent | 24d7a4abad957537c1e9cd32185ab5f53b1016c4 (diff) | |
download | kati-0d8e79b7753a89ac6beaf638a535ec63f1941444.tar.gz |
[C++] Add a way to retrieve stats
Diffstat (limited to 'stats.h')
-rw-r--r-- | stats.h | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -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_ |