blob: 201f6438e21faf0c6c0eaef71f6836152a24496a [file] [log] [blame]
// Copyright 2018 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.
#include <lib/fit/function.h>
#include <lib/zx/channel.h>
#include <lib/zx/time.h>
#include <lib/zx/vmo.h>
#include <limits.h>
#include <zircon/types.h>
#include <cstdint>
#include <string>
#include <string_view>
#include <cobalt-client/cpp/types_internal.h>
namespace cobalt_client {
namespace internal {
struct CobaltOptions {
// Service path to LoggerFactory interface.
std::string service_path;
// Performs a connection to a service at a given path.
fit::function<zx_status_t(const char* service_path, zx::channel service)> service_connect =
// Used to acquire a logger instance.
uint32_t project_id;
// Logger implementation that pushes data to cobalt.
class CobaltLogger final : public Logger {
static std::string_view GetServiceName();
CobaltLogger() = delete;
// instance from cobalt service;
explicit CobaltLogger(CobaltOptions options) : options_(std::move(options)) {}
CobaltLogger(const CobaltLogger&) = delete;
CobaltLogger(CobaltLogger&&) = delete;
CobaltLogger& operator=(const CobaltLogger&) = delete;
CobaltLogger& operator=(CobaltLogger&&) = delete;
~CobaltLogger() final = default;
// Returns true if the histogram was persisted.
bool Log(const MetricOptions& metric_info, const HistogramBucket* buckets,
size_t bucket_count) final;
// Returns true if the counter was persisted.
bool Log(const MetricOptions& metric_info, int64_t count) final;
// Logs integer/memory-usage metrics. Returns true if |bytes| was persisted.
bool LogInteger(const MetricOptions& metric_info, int64_t bytes) final;
// Returns true if |logger_| is able to provide a logging service instance for |options_|.
bool TryObtainLogger();
// Cleans up the state of the logger.
void Reset() { logger_.client_end().reset(); }
// Set of options for this logger.
CobaltOptions options_;
fidl::WireSyncClient<fuchsia_cobalt::Logger> logger_;
} // namespace internal
} // namespace cobalt_client