bug 1339019 - Caution against recording Telemetry in hot paths. r?gfritzsche draft
authorChris H-C <chutten@mozilla.com>
Thu, 06 Apr 2017 14:07:02 -0400
changeset 557401 dbde04ff73afe87b38b172052f30d782dec9cd0f
parent 557400 8a3519624432cad53d657ab0452f3ca11aafd936
child 623036 429b27c274fca277b78952c18e471f8a4983dbfa
push id52700
push userbmo:chutten@mozilla.com
push dateThu, 06 Apr 2017 18:08:39 +0000
reviewersgfritzsche
bugs1339019
milestone55.0a1
bug 1339019 - Caution against recording Telemetry in hot paths. r?gfritzsche Histograms, Scalars, and Events are cheap but not free. Expect performance impacts if you use them in tight loops or hot paths. MozReview-Commit-ID: 2nrdHXrbN9i
toolkit/components/telemetry/docs/collection/events.rst
toolkit/components/telemetry/docs/collection/histograms.rst
toolkit/components/telemetry/docs/collection/scalars.rst
--- a/toolkit/components/telemetry/docs/collection/events.rst
+++ b/toolkit/components/telemetry/docs/collection/events.rst
@@ -129,16 +129,20 @@ Public JS API
 Record a registered event.
 
 * ``value``: Optional, may be ``null``. A string value, limitted to 80 bytes.
 * ``extra``: Optional. An object with string keys & values. Key strings are limitted to what was registered. Value strings are limitted to 80 bytes.
 
 Throws if the combination of ``category``, ``method`` and ``object`` is unknown.
 Recording an expired event will not throw, but print a warning into the browser console.
 
+.. warning::
+
+  Event Telemetry recording is designed to be cheap, not free. If you wish to record events in a performance-sensitive piece of code, store the events locally and record them only after the performance-sensitive piece ("hot path") has completed.
+
 Example:
 
 .. code-block:: js
 
   Services.telemetry.recordEvent("ui", "click", "reload-btn");
   // event: [543345, "ui", "click", "reload-btn"]
   Services.telemetry.recordEvent("ui", "search", "search-bar", "google");
   // event: [89438, "ui", "search", "search-bar", "google"]
--- a/toolkit/components/telemetry/docs/collection/histograms.rst
+++ b/toolkit/components/telemetry/docs/collection/histograms.rst
@@ -255,16 +255,20 @@ Probes in native code can also use the `
   void AccumulateTimeDelta(ID id, TimeStamp start, TimeStamp end = TimeStamp::Now());
 
 The histogram names declared in ``Histograms.json`` are translated into constants in the ``mozilla::Telemetry`` namespace:
 
 .. code-block:: cpp
 
   mozilla::Telemetry::Accumulate(mozilla::Telemetry::STARTUP_CRASH_DETECTED, true);
 
+.. warning::
+
+  Telemetry accumulations are designed to be cheap, not free. If you wish to accumulate values in a performance-sensitive piece of code, store the accumualtions locally and accumulate after the performance-sensitive piece ("hot path") has completed.
+
 The ``Telemetry.h`` header also declares the helper classes ``AutoTimer`` and ``AutoCounter``. Objects of these types automatically record a histogram value when they go out of scope:
 
 .. code-block:: cpp
 
   nsresult
   nsPluginHost::StopPluginInstance(nsNPAPIPluginInstance* aInstance)
   {
     Telemetry::AutoTimer<Telemetry::PLUGIN_SHUTDOWN_MS> timer;
--- a/toolkit/components/telemetry/docs/collection/scalars.rst
+++ b/toolkit/components/telemetry/docs/collection/scalars.rst
@@ -42,16 +42,20 @@ Probes in native code can use the more c
     void ScalarSet(mozilla::Telemetry::ScalarID aId, bool aValue);
     void ScalarSetMaximum(mozilla::Telemetry::ScalarID aId, uint32_t aValue);
 
     void ScalarAdd(mozilla::Telemetry::ScalarID aId, const nsAString& aKey, uint32_t aValue);
     void ScalarSet(mozilla::Telemetry::ScalarID aId, const nsAString& aKey, uint32_t aValue);
     void ScalarSet(mozilla::Telemetry::ScalarID aId, const nsAString& aKey, bool aValue);
     void ScalarSetMaximum(mozilla::Telemetry::ScalarID aId, const nsAString& aKey, uint32_t aValue);
 
+.. warning::
+
+  Scalar operations are designed to be cheap, not free. If you wish to manipulate Scalars in a performance-sensitive piece of code, store the operations locally and change the Scalar only after the performance-sensitive piece ("hot path") has completed.
+
 The YAML definition file
 ========================
 Scalar probes are required to be registered, both for validation and transparency reasons,
 in the `Scalars.yaml <https://dxr.mozilla.org/mozilla-central/source/toolkit/components/telemetry/Scalars.yaml>`_
 definition file.
 
 The probes in the definition file are represented in a fixed-depth, two-level structure: