[#BloombergLP-balm-StopwatchScopedGuard-2constructor-05]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/balm.adoc[balm]::xref:BloombergLP/balm/StopwatchScopedGuard.adoc[StopwatchScopedGuard]::StopwatchScopedGuard
:relfileprefix: ../../../
:mrdocs:

Initialize this scoped guard to record an elapsed time to the specified `metricId`&period;

== Synopsis

Declared in `&lt;balm&lowbar;stopwatchscopedguard&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
StopwatchScopedGuard(
    xref:BloombergLP/balm/MetricId.adoc[MetricId] const& metricId,
    xref:BloombergLP/balm/MetricsManager.adoc[MetricsManager]* manager = 0);
----

== Description

Optionally specify a metrics `manager` and the `timeUnits` in which to report elapsed time&period; If `timeUnits` is not provided, the elapsed time will be reported in seconds&period; If `manager` is 0, the `DefaultMetricsManager` singleton instance is used&period; If no `manager` is supplied and the default instance has not been created, this object will be inactive (i&period;e&period;, it will not record any values)&semi; similarly, if the metric&apos;s associated category is disabled (i&period;e&period;, `metricId&period;category()&hyphen;&gt;enabled()` is `false`), then this object will be inactive&period; The behavior is undefined unless unless `metricId` is a valid id returned by the `MetricRepository` object owned by the indicated metrics manager&period; Note that `timeUnits` indicates the scale of the double value reported by this guard, but does _not_ affect the precision of the elapsed time measurement&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *metricId*
| identity of the metric to record
| *manager*
| metrics manager used to provide the collector (optional)
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
