diff options
author | Evan Martin <martine@danga.com> | 2012-09-13 22:33:40 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-09-13 22:33:40 (GMT) |
commit | 7096bf1507f98be981aa14ffd9ed5a4a8b1c1494 (patch) | |
tree | 10f75334ddb1dc86c2cc85db0cab93ca672d39de /src/metrics.h | |
parent | 50af448b293b411bde5232931525574aba3bb451 (diff) | |
parent | 06fa62352d1e9868409b299ffc8abc8f4cd9a39d (diff) | |
download | Ninja-7096bf1507f98be981aa14ffd9ed5a4a8b1c1494.zip Ninja-7096bf1507f98be981aa14ffd9ed5a4a8b1c1494.tar.gz Ninja-7096bf1507f98be981aa14ffd9ed5a4a8b1c1494.tar.bz2 |
version 1.0.0v1.0.0
Diffstat (limited to 'src/metrics.h')
-rw-r--r-- | src/metrics.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/metrics.h b/src/metrics.h index af6e9a2..f5ac0de 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -33,6 +33,7 @@ struct Metric { int64_t sum; }; + /// A scoped object for recording a metric across the body of a function. /// Used by the METRIC_RECORD macro. struct ScopedMetric { @@ -57,6 +58,30 @@ private: vector<Metric*> metrics_; }; +/// Get the current time as relative to some epoch. +/// Epoch varies between platforms; only useful for measuring elapsed +/// time. +int64_t GetTimeMillis(); + + +/// A simple stopwatch which retruns the time +// in seconds since Restart() was called +class Stopwatch +{ +public: + Stopwatch() : started_(0) {} + + /// Seconds since Restart() call + double Elapsed() const { return 1e-6 * static_cast<double>(Now() - started_); } + + void Restart() { started_ = Now(); } + +private: + uint64_t started_; + uint64_t Now() const; +}; + + /// The primary interface to metrics. Use METRIC_RECORD("foobar") at the top /// of a function to get timing stats recorded for each call of the function. #define METRIC_RECORD(name) \ |