Bug 668355: RAII Telemetry timer r=glandium
authorTaras Glek <tglek@mozilla.com>
Fri, 01 Jul 2011 12:06:09 -0700
changeset 72134 4504b65f69dbc4781febc40a2cbeb9ef48ad8d16
parent 72133 788753e18492022732a9e1dced76d9c894744e86
child 72135 3a5af9d36fb1071d562f72e6ac5a2c42283de129
push id366
push usertglek@mozilla.com
push dateFri, 01 Jul 2011 19:06:23 +0000
treeherdermozilla-inbound@3a5af9d36fb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs668355
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 668355: RAII Telemetry timer r=glandium
toolkit/components/telemetry/Telemetry.h
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -34,16 +34,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef Telemetry_h__
 #define Telemetry_h__
 
+#include "mozilla/TimeStamp.h"
+
 namespace mozilla {
 namespace Telemetry {
 
 enum ID {
 #define HISTOGRAM(name, a, b, c, d, e) name,
 
 #include "TelemetryHistograms.h"
 
@@ -54,11 +56,26 @@ HistogramCount
 /**
  * Adds sample to a histogram defined in TelemetryHistograms.h
  *
  * @param id - histogram id
  * @param sample - value to record.
  */
 void Accumulate(ID id, PRUint32 sample);
 
+template<ID id>
+class Timer {
+public:
+  Timer():
+    start(TimeStamp::Now())
+  {
+  }
+
+  ~Timer() {
+    Accumulate(id, (TimeStamp::Now() - start).ToMilliseconds());
+  }
+
+private:
+  const TimeStamp start;
+};
 } // namespace Telemetry
 } // namespace mozilla
 #endif // Telemetry_h__