blob: a40fa2daf134734b9fa09548b4bd2fb0bbfd4dea [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_LIB_STORAGE_VFS_CPP_METRICS_COMPOSITE_LATENCY_EVENT_H_
#define SRC_LIB_STORAGE_VFS_CPP_METRICS_COMPOSITE_LATENCY_EVENT_H_
#include <cobalt-client/cpp/histogram.h>
#include "src/lib/storage/vfs/cpp/metrics/cobalt_metrics.h"
#include "src/lib/storage/vfs/cpp/metrics/histograms.h"
namespace fs_metrics {
namespace internal {
// Returns the appropiate histogram for an event.
cobalt_client::Histogram<fs_metrics::FsCommonMetrics::kHistogramBuckets>* SelectHistogram(
Event event, fs_metrics::FsCommonMetrics* metrics);
} // namespace internal
// This class allows clients to create a single filesystem event that creates metrics for both the
// inspect API and Cobalt instrumentation. This is intended to make it easier to measure events for
// tracking through this distinct mechanisms, and should be used for code that already exposes both
// types of metrics.
//
// In the future, this class will be replaced by just using the Inspect API's 'LatencyEvent', and
// Cobalt histograms will be automatically generated by a proxy service tentatively called the
// 'Broker Service.' Clients who do not currently export Cobalt metrics should prefer using this
// Inspect API directly.
class CompositeLatencyEvent {
public:
CompositeLatencyEvent() = delete;
CompositeLatencyEvent(Event event, Histograms* histogram_collection,
fs_metrics::FsCommonMetrics* metrics);
CompositeLatencyEvent(const CompositeLatencyEvent&) = delete;
CompositeLatencyEvent(CompositeLatencyEvent&&) = default;
CompositeLatencyEvent& operator=(const CompositeLatencyEvent&) = delete;
CompositeLatencyEvent& operator=(CompositeLatencyEvent&&) = delete;
~CompositeLatencyEvent();
// Resets start for the latency event.
void Reset();
// Prevents the latency event from being recorded.
void Cancel();
LatencyEvent* mutable_latency_event() { return &inspect_event_; }
cobalt_client::Histogram<fs_metrics::FsCommonMetrics::kHistogramBuckets>* mutable_histogram() {
return cobalt_histogram_;
}
private:
LatencyEvent inspect_event_;
cobalt_client::Histogram<fs_metrics::FsCommonMetrics::kHistogramBuckets>* cobalt_histogram_;
};
} // namespace fs_metrics
#endif // SRC_LIB_STORAGE_VFS_CPP_METRICS_COMPOSITE_LATENCY_EVENT_H_