зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1436680 - Allow non-templated uses of AutoCounter. r=Dexter
In order to stay consistent with the AutoTimer api, allowed non-templates uses or AutoCounter. MozReview-Commit-ID: 9qnAeQTIY9T --HG-- extra : rebase_source : 8c95992e2d291d628721febbc7b641b91c850288
This commit is contained in:
Родитель
fabf9a4e7b
Коммит
9c6c1ed9e2
|
@ -305,6 +305,41 @@ private:
|
|||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
class MOZ_RAII RuntimeAutoCounter
|
||||
{
|
||||
public:
|
||||
explicit RuntimeAutoCounter(
|
||||
HistogramID aId,
|
||||
uint32_t counterStart = 0 MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: id(aId)
|
||||
, counter(counterStart)
|
||||
{
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
}
|
||||
|
||||
~RuntimeAutoCounter()
|
||||
{
|
||||
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:
|
||||
HistogramID id;
|
||||
uint32_t counter;
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
template<HistogramID id>
|
||||
class MOZ_RAII AutoCounter {
|
||||
public:
|
||||
|
|
|
@ -331,7 +331,7 @@ The ``Telemetry.h`` header also declares the helper classes ``AutoTimer`` and ``
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
If the HistogramID is not known at compile time, one can use the ``RuntimeAutoTimer`` class, which behaves like the template parameterized ``AutoTimer``.
|
||||
If the HistogramID is not known at compile time, one can use the ``RuntimeAutoTimer`` and ``RuntimeAutoCounter`` classes, which behave like the template parameterized ``AutoTimer`` and ``AutoCounter`` ones.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
|
@ -344,4 +344,14 @@ If the HistogramID is not known at compile time, one can use the ``RuntimeAutoTi
|
|||
...
|
||||
}
|
||||
|
||||
int32_t
|
||||
FunctionWithCounter(Telemetry::HistogramID aTelemetryID)
|
||||
{
|
||||
...
|
||||
// Increment an AutoCounter
|
||||
Telemetry::RuntimeAutoCounter myCounter(aTelemetryID);
|
||||
++myCounter;
|
||||
...
|
||||
}
|
||||
|
||||
Prefer using the template parameterized ``AutoTimer`` and ``AutoCounter`` on hot paths, if possible.
|
||||
|
|
Загрузка…
Ссылка в новой задаче