-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ostream_log_test-fix-Mac
- Loading branch information
Showing
26 changed files
with
1,058 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Performance Tests - Benchmarks | ||
============================== | ||
|
||
Click `here <https://open-telemetry.github.io/opentelemetry-cpp/benchmarks/index.html>`_ to view the latest performance benchmarks for packages in this repo. | ||
|
||
Please note that the flutation in the results are mainly because [machines with different CPUs](https://github.com/benchmark-action/github-action-benchmark/issues/79) are used for tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
sdk/include/opentelemetry/sdk/metrics/async_instruments.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include "opentelemetry/metrics/async_instruments.h" | ||
# include "opentelemetry/metrics/observer_result.h" | ||
# include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" | ||
# include "opentelemetry/sdk/metrics/measurement_processor.h" | ||
|
||
# include "opentelemetry/nostd/string_view.h" | ||
# include "opentelemetry/sdk/metrics/instruments.h" | ||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
|
||
template <class T> | ||
class Asynchronous | ||
{ | ||
public: | ||
Asynchronous(nostd::string_view name, | ||
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
*instrumentation_library, | ||
MeasurementProcessor *measurement_processor, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<T> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") | ||
: name_(name), | ||
instrumentation_library_{instrumentation_library}, | ||
measurement_processor_{measurement_processor}, | ||
callback_(callback), | ||
description_(description), | ||
unit_(unit) | ||
{} | ||
|
||
protected: | ||
std::string name_; | ||
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
*instrumentation_library_; | ||
const MeasurementProcessor *measurement_processor_; | ||
void (*callback_)(opentelemetry::metrics::ObserverResult<T> &); | ||
std::string description_; | ||
std::string unit_; | ||
}; | ||
|
||
class LongObservableCounter : public opentelemetry::metrics::ObservableCounter<long>, | ||
public Asynchronous<long> | ||
{ | ||
public: | ||
LongObservableCounter(nostd::string_view name, | ||
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
*instrumentation_library, | ||
MeasurementProcessor *measurement_processor, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") | ||
: Asynchronous(name, | ||
instrumentation_library, | ||
measurement_processor, | ||
callback, | ||
description, | ||
unit) | ||
|
||
{} | ||
}; | ||
|
||
class DoubleObservableCounter : public opentelemetry::metrics::ObservableCounter<double>, | ||
public Asynchronous<double> | ||
{ | ||
public: | ||
DoubleObservableCounter(nostd::string_view name, | ||
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
*instrumentation_library, | ||
MeasurementProcessor *measurement_processor, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") | ||
: Asynchronous(name, | ||
instrumentation_library, | ||
measurement_processor, | ||
callback, | ||
description, | ||
unit) | ||
|
||
{} | ||
}; | ||
|
||
class LongObservableGauge : public opentelemetry::metrics::ObservableGauge<long>, | ||
public Asynchronous<long> | ||
{ | ||
public: | ||
LongObservableGauge(nostd::string_view name, | ||
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
*instrumentation_library, | ||
MeasurementProcessor *measurement_processor, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") | ||
: Asynchronous(name, | ||
instrumentation_library, | ||
measurement_processor, | ||
callback, | ||
description, | ||
unit) | ||
|
||
{} | ||
}; | ||
|
||
class DoubleObservableGauge : public opentelemetry::metrics::ObservableGauge<double>, | ||
public Asynchronous<double> | ||
{ | ||
public: | ||
DoubleObservableGauge(nostd::string_view name, | ||
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
*instrumentation_library, | ||
MeasurementProcessor *measurement_processor, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") | ||
: Asynchronous(name, | ||
instrumentation_library, | ||
measurement_processor, | ||
callback, | ||
description, | ||
unit) | ||
|
||
{} | ||
}; | ||
|
||
class LongObservableUpDownCounter : public opentelemetry::metrics::ObservableUpDownCounter<long>, | ||
public Asynchronous<long> | ||
{ | ||
public: | ||
LongObservableUpDownCounter( | ||
nostd::string_view name, | ||
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
*instrumentation_library, | ||
MeasurementProcessor *measurement_processor, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") | ||
: Asynchronous(name, | ||
instrumentation_library, | ||
measurement_processor, | ||
callback, | ||
description, | ||
unit) | ||
|
||
{} | ||
}; | ||
|
||
class DoubleObservableUpDownCounter | ||
: public opentelemetry::metrics::ObservableUpDownCounter<double>, | ||
public Asynchronous<double> | ||
{ | ||
public: | ||
DoubleObservableUpDownCounter( | ||
nostd::string_view name, | ||
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
*instrumentation_library, | ||
MeasurementProcessor *measurement_processor, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") | ||
: Asynchronous(name, | ||
instrumentation_library, | ||
measurement_processor, | ||
callback, | ||
description, | ||
unit) | ||
{} | ||
}; | ||
|
||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
108 changes: 108 additions & 0 deletions
108
sdk/include/opentelemetry/sdk/metrics/measurement_processor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
|
||
# include "opentelemetry/common/key_value_iterable_view.h" | ||
# include "opentelemetry/sdk/metrics/instruments.h" | ||
# include "opentelemetry/sdk/metrics/metric_reader.h" | ||
# include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" | ||
|
||
# include <map> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
|
||
static std::size_t MakeKey(const MetricReader &metric_reader) | ||
{ | ||
return reinterpret_cast<std::size_t>(&metric_reader); | ||
} | ||
class MeasurementProcessor | ||
{ | ||
public: | ||
virtual void RecordLong(long value) noexcept = 0; | ||
|
||
virtual void RecordLong(long value, | ||
const opentelemetry::common::KeyValueIterable &attributes) noexcept = 0; | ||
|
||
virtual void RecordDouble(double value) noexcept = 0; | ||
|
||
virtual void RecordDouble(double value, | ||
const opentelemetry::common::KeyValueIterable &attributes) noexcept = 0; | ||
|
||
virtual bool Collect(MetricReader &reader, | ||
AggregationTemporarily aggregation_temporarily, | ||
nostd::function_ref<bool(MetricData)> callback) noexcept = 0; | ||
}; | ||
|
||
class DefaultMeasurementProcessor : public MeasurementProcessor | ||
{ | ||
|
||
public: | ||
bool AddMetricStorage(const MetricReader &reader) | ||
{ | ||
// TBD = check if already present. | ||
metric_storages_[MakeKey(reader)] = std::unique_ptr<SyncMetricStorage>(new SyncMetricStorage()); | ||
return true; | ||
} | ||
|
||
virtual void RecordLong(long value) noexcept override | ||
{ | ||
for (const auto &kv : metric_storages_) | ||
{ | ||
kv.second->RecordLong(value); | ||
} | ||
} | ||
|
||
virtual void RecordLong( | ||
long value, | ||
const opentelemetry::common::KeyValueIterable &attributes) noexcept override | ||
{ | ||
for (const auto &kv : metric_storages_) | ||
{ | ||
kv.second->RecordLong(value, attributes); | ||
} | ||
} | ||
|
||
virtual void RecordDouble(double value) noexcept override | ||
{ | ||
for (const auto &kv : metric_storages_) | ||
{ | ||
kv.second->RecordDouble(value); | ||
} | ||
} | ||
|
||
virtual void RecordDouble( | ||
double value, | ||
const opentelemetry::common::KeyValueIterable &attributes) noexcept override | ||
{ | ||
for (const auto &kv : metric_storages_) | ||
{ | ||
kv.second->RecordDouble(value, attributes); | ||
} | ||
} | ||
|
||
bool Collect(MetricReader &reader, | ||
AggregationTemporarily aggregation_temporarily, | ||
nostd::function_ref<bool(MetricData)> callback) noexcept override | ||
{ | ||
auto i = metric_storages_.find(MakeKey(reader)); | ||
if (i != metric_storages_.end()) | ||
{ | ||
return i->second->Collect(aggregation_temporarily, callback); | ||
} | ||
return false; | ||
} | ||
|
||
private: | ||
std::map<std::size_t, std::unique_ptr<SyncMetricStorage>> metric_storages_; | ||
}; | ||
|
||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
Oops, something went wrong.