class MetricsBuffer

Defined at line 131 of file ../../src/lib/metrics_buffer/metrics_buffer.h

The purpose of this class is to ensure the rate of messages to Cobalt stays reasonable, per

Cobalt's rate requirement/recommendation in the Cobalt docs.

Typically it'll make sense to only have one of these per process, but that's not enforced.

Methods of this class can be called on any thread.

Public Methods

std::shared_ptr<MetricsBuffer> Create (uint32_t project_id)

Initially a noop instance, so unit tests don't need to wire up cobalt. Call

SetServiceDirectory() to enable and start logging.

Defined at line 53 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

std::shared_ptr<MetricsBuffer> Create (uint32_t project_id, std::shared_ptr<sys::ServiceDirectory> service_directory)

!service_directory is ok. If !service_directory, the instance will be a nop instance until

SetServiceDirectory() is called.

Defined at line 58 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

void ~MetricsBuffer ()

Defined at line 74 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

void SetServiceDirectory (std::shared_ptr<sys::ServiceDirectory> service_directory)

Set the ServiceDirectory from which to get fuchsia.metrics.MetricEventLoggerFactory. This can

be nullptr. This can be called again, regardless of whether there was already a previous

ServiceDirectory. Previously-queued events may be lost (especially recently-queued events) when

switching to a new ServiceDirectory.

Defined at line 76 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

void SetMinLoggingPeriod (zx::duration min_logging_period)

This specifies the minimum amount of time between logging batches to cobalt. If enough

different metrics have accumulated to force more than one message to cobalt, then more than

one message is possible, but typically a single message will be sent to cobalt no more often

than this. In unit tests we use this to turn the min_logging_period way down so that tests can

finish faster.

Defined at line 144 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

void LogEvent (uint32_t metric_id, std::vector<uint32_t> dimension_values)

Log the event as EVENT_COUNT, with period_duration_micros 0, possibly aggregating with any

other calls to this method with the same component and event wihtin a short duration to limit

the rate of FIDL calls to Cobalt, per the rate requirement/recommendation in the Cobalt docs.

Defined at line 166 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

void LogEventCount (uint32_t metric_id, std::vector<uint32_t> dimension_values, uint32_t count)

Defined at line 150 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

void LogString (uint32_t metric_id, std::vector<uint32_t> dimension_values, std::string string_value)

The string_value is not an arbitrary string; it must be one of the potential strings defined in

the metric definition, or the string_value ends up getting ignored.

Defined at line 170 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

void ForceFlush ()

Use sparingly, only when it's appropriate to force the counts to flush to Cobalt, which will

typically only be before orderly exit or in situations like driver suspend. Over-use of this

method will break the purpose of using this class, which is to ensure the rate of messages to

Cobalt stays reasonable.

MetricBuffer CreateMetricBuffer (uint32_t metric_id)

Defined at line 318 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

StringMetricBuffer CreateStringMetricBuffer (uint32_t metric_id)

Defined at line 322 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

HistogramMetricBuffer CreateHistogramMetricBuffer (HistogramInfo histogram_info)

Defined at line 326 of file ../../src/lib/metrics_buffer/metrics_buffer.cc

Friends

class HistogramMetricBuffer