[#BloombergLP-balm-MetricRegistry]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/balm.adoc[balm]::MetricRegistry
:relfileprefix: ../../
:mrdocs:

The class defines a thread&hyphen;aware mechanism for registering metrics and metric categories&period; A metric is uniquely identified by its name and category, and the metric registry provides a mapping from those identifying properties to a `balm&colon;&colon;MetricId`&period; A `balm&colon;&colon;MetricRegistry` object also provides a mapping from a category name to the address of a non&hyphen;modifiable `balm&colon;&colon;Category` object&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class MetricRegistry;
----

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/balm/MetricRegistry/2constructor.adoc[`MetricRegistry`]         [.small]#[constructor]#
| Create an empty metric registry&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is 0, the currently installed default allocator is used&period;
| xref:BloombergLP/balm/MetricRegistry/2destructor.adoc[`&#126;MetricRegistry`] [.small]#[destructor]#
| Destroy this metric registry&period;
| xref:BloombergLP/balm/MetricRegistry/addCategory.adoc[`addCategory`] 
| Add the specified `category` to this registry, unless it has already been registered&period; Return the address of the newly&hyphen;created non&hyphen;modifiable `balm&colon;&colon;Category` object on success, and 0 otherwise&period; The behavior is undefined unless `category` is null&hyphen;terminated&period;
| xref:BloombergLP/balm/MetricRegistry/addId.adoc[`addId`] 
| Add the specified `category` and `name` to this registry, unless it has already been registered, and return a `balm&colon;&colon;MetricId` object identifying the newly&hyphen;registered metric&period; If the indicated metric has already been registered, the returned `balm&colon;&colon;MetricId` object will _not_ be valid (i&period;e&period;, `isValid` will return `false`)&period; The behavior is undefined unless `category` and `name` are null&hyphen;terminated&period;
| xref:BloombergLP/balm/MetricRegistry/createUserDataKey.adoc[`createUserDataKey`] 
| Return a new unique key that can be used to associate (via `setUserData`) and retrieve (via `userData`) a value with a metric (or group of metrics)&period; Note that the returned key can be used by clients of `balm` to associate additional information with a metric&period;
| xref:BloombergLP/balm/MetricRegistry/findCategory.adoc[`findCategory`] 
| Find the specified `category`, a null&hyphen;terminated string, in this registry&period; Return the address of the non&hyphen;modifiable `balm&colon;&colon;Category` object corresponding to the `category`, or 0 if no such category has been registered&period;
| xref:BloombergLP/balm/MetricRegistry/findId.adoc[`findId`] 
| Find the specified null&hyphen;terminated strings `category` and `name` in this registry&period; Return the `balm&colon;&colon;MetricId` object corresponding to the metric having the `category` and `name`, if found, or an invalid metric id if no such metric has been registered (i&period;e&period;, `isValid` will return `false`)&period;
| xref:BloombergLP/balm/MetricRegistry/getAllCategories.adoc[`getAllCategories`] 
| Append to the specified `categories` the addresses of all the categories registered by this `balm&colon;&colon;MetricRegistry` object&period;
| xref:BloombergLP/balm/MetricRegistry/getCategory.adoc[`getCategory`] 
| Return the address of the non&hyphen;modifiable `balm&colon;&colon;Category` object for the specified `category`&period; If no corresponding category exists, register a new category and return the address of the newly&hyphen;created `balm&colon;&colon;Category` object&period; The behavior is undefined unless `category` is null&hyphen;terminated&period; Note that this operation is guaranteed to return a valid address&period;
| xref:BloombergLP/balm/MetricRegistry/getId.adoc[`getId`] 
| Return a `balm&colon;&colon;MetricId` object for the metric identified by the specified `category` and `name`&period; If no corresponding metric has already been registered, register a new metric and return a `balm&colon;&colon;MetricId` object identifying that newly&hyphen;registered metric&period; The behavior is undefined unless `category` and `name` are null&hyphen;terminated&period; Note that this operation is guaranteed to return a valid `balm&colon;&colon;MetricId` object&period;
| xref:BloombergLP/balm/MetricRegistry/numCategories.adoc[`numCategories`] 
| Return the number of categories in this registry&period;
| xref:BloombergLP/balm/MetricRegistry/numMetrics.adoc[`numMetrics`] 
| Return the number of metrics in this registry&period;
| xref:BloombergLP/balm/MetricRegistry/print.adoc[`print`] 
| Format this object to the specified output `stream` at the (absolute value of) the optionally specified indentation `level` and return a reference to `stream`&period; If `level` is specified, optionally specify `spacesPerLevel`, the number of spaces per indentation level for this and all of its nested objects&period; If `level` is negative, suppress indentation of the first line&period; If `spacesPerLevel` is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by `level`)&period; If `stream` is not valid on entry, this operation has no effect&period;
| xref:BloombergLP/balm/MetricRegistry/registerCategoryHolder.adoc[`registerCategoryHolder`] 
| Load into the specified `holder` the address of the specified `category`, its `enabled` status, and the address of the next holder in the linked list of category holders maintained by `category` (prepending `holder` to the linked list of category holders for `category`)&period; The supplied `category` will update the value returned by `holder&hyphen;&gt;enabled()` when its enabled state changes, and will reset `holder` (i&period;e&period;, `holder&hyphen;&gt;reset()`) when `category` is destroyed&period; The behavior is undefined unless `holder` remains valid and _unmodified_ (by the client) for the lifetime of this object&period;
| xref:BloombergLP/balm/MetricRegistry/setAllCategoriesEnabled.adoc[`setAllCategoriesEnabled`] 
| Set whether each currently registered category is enabled to the specified `value`, and ensure that categories registered after this call are initialized as either enabled or disabled, accordingly&period; This operation is logically equivalent to iterating over the list of currently registered categories and calling `setCategoryEnabled` on each category individually, and also setting a default `enabled` value (for newly&hyphen;created categories)&period; Hence, subsequent calls `setCategoryEnabled` will override this value for a particular category&period; Note that this operation is thread&hyphen;safe, but _not_ atomic&colon; Other threads may simultaneously access the current enabled status for registered categories while this operation completes&period; Also note that this operation has _linear_ runtime performance with respect to the total number of category holders registered with this repository&period;
| xref:BloombergLP/balm/MetricRegistry/setCategoryEnabled.adoc[`setCategoryEnabled`] 
| Set whether the specified `category` is enabled to the specified `value`&period; The behavior is undefined unless `category` is a valid address of a category previously returned by this metric registry&period; Note that this operation is thread&hyphen;safe, but _not_ atomic&colon; Other threads may simultaneously access the current enabled value for `category` while this operation completes&period; Also note that this operation has _linear_ runtime performance with respect to the number of registered category holders for `category`&period;
| xref:BloombergLP/balm/MetricRegistry/setFormat.adoc[`setFormat`] 
| Set the format for the specified `metricId` to the specified `format`&period; Note that there is no uniform specification for how publisher implementations will interpret the supplied `format`&period; Also note that the format for a metric is accessed through the `balm&colon;&colon;MetricDescription`&period; For example&colon; &grave; metric&period;description()&hyphen;&gt;format()&semi; &grave;
| xref:BloombergLP/balm/MetricRegistry/setPreferredPublicationType.adoc[`setPreferredPublicationType`] 
| Set the preferred publication type of the specified `metric` to the specified `type`&period; The preferred publication type of a metric indicates the preferred aggregate to publish for that metric, or `balm&colon;&colon;PublicationType&colon;&colon;UNSPECIFIED` if there is no preference&period; The behavior is undefined unless `metric` was previously returned by this metric registry&period; Note that there is no uniform definition for how publishers will interpret this value&semi; an `UNSPECIFIED` value generally indicates that the all the collected aggregates (total, count, minimum, and maximum value) should be published&period; Also note that the preferred publication type is accessed through the `balm&colon;&colon;MetricDescription` (i&period;e&period;, `metric&period;description()&hyphen;&gt;preferredPublicationType()`)&period;
| xref:BloombergLP/balm/MetricRegistry/setUserData-0b.adoc[`setUserData`] 
| `setUserData` overloads
| xref:BloombergLP/balm/MetricRegistry/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;MetricRegistry, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===



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