iceberg-cpp
Loading...
Searching...
No Matches
metrics_context.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <memory>
26#include <string_view>
27
28#include "iceberg/iceberg_export.h"
29#include "iceberg/metrics/counter.h"
30#include "iceberg/metrics/timer.h"
31
32namespace iceberg {
33
35class ICEBERG_EXPORT MetricsContext {
36 public:
37 virtual ~MetricsContext() = default;
38
40 virtual std::shared_ptr<Counter> GetCounter(std::string_view name,
41 CounterUnit unit) = 0;
42
46 std::shared_ptr<Counter> GetCounter(std::string_view name) {
47 return GetCounter(name, CounterUnit::kCount);
48 }
49
51 virtual std::shared_ptr<Timer> GetTimer(std::string_view name, TimerUnit unit) = 0;
52
56 std::shared_ptr<Timer> GetTimer(std::string_view name) {
57 return GetTimer(name, TimerUnit::kNanoseconds);
58 }
59
63 static const std::shared_ptr<MetricsContext>& Noop();
64
66 static std::unique_ptr<MetricsContext> Default();
67};
68
70class ICEBERG_EXPORT DefaultMetricsContext : public MetricsContext {
71 public:
72 using MetricsContext::GetCounter; // expose the one-arg base overload
73 using MetricsContext::GetTimer; // expose the one-arg base overload
74
75 std::shared_ptr<Counter> GetCounter(std::string_view name, CounterUnit unit) override;
76
77 std::shared_ptr<Timer> GetTimer(std::string_view name, TimerUnit unit) override;
78};
79
80} // namespace iceberg
MetricsContext backed by DefaultCounter and DefaultTimer instances.
Definition metrics_context.h:70
Factory for creating named Counter and Timer instances.
Definition metrics_context.h:35
virtual std::shared_ptr< Counter > GetCounter(std::string_view name, CounterUnit unit)=0
Get or create a named Counter with an explicit unit.
virtual std::shared_ptr< Timer > GetTimer(std::string_view name, TimerUnit unit)=0
Get or create a named Timer with an explicit unit.
std::shared_ptr< Timer > GetTimer(std::string_view name)
Get or create a nanosecond-precision Timer by name.
Definition metrics_context.h:56
std::shared_ptr< Counter > GetCounter(std::string_view name)
Get or create a count-unit Counter by name.
Definition metrics_context.h:46