From 284d003e15dee906fa772706b545de1c69d02259 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Mon, 9 Jan 2012 18:21:28 -0500 Subject: [PATCH] Bug 716657 - add Telemetry::AutoCounter; r=taras --- toolkit/components/telemetry/Telemetry.h | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/toolkit/components/telemetry/Telemetry.h b/toolkit/components/telemetry/Telemetry.h index 6f83cc26a12..c79397a75f7 100644 --- a/toolkit/components/telemetry/Telemetry.h +++ b/toolkit/components/telemetry/Telemetry.h @@ -104,6 +104,34 @@ private: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; +template +class AutoCounter { +public: + AutoCounter(PRUint32 counterStart = 0 MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) + : counter(counterStart) + { + MOZILLA_GUARD_OBJECT_NOTIFIER_INIT; + } + + ~AutoCounter() { + Accumulate(id, counter); + } + + // Prefix increment only, to encourage good habits. + void operator++() { + ++counter; + } + + // Chaining doesn't make any sense, don't return anything. + void operator+=(int increment) { + counter += increment; + } + +private: + PRUint32 counter; + MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + /** * Records slow SQL statements for Telemetry reporting. * For privacy reasons, only prepared statements are reported.