-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
api/metrics/include/opentelemetry-matlab/metrics/MeterProxy.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,36 @@ | ||
// Copyright 2023 The MathWorks, Inc. | ||
|
||
#pragma once | ||
|
||
#include "libmexclass/proxy/Proxy.h" | ||
#include "libmexclass/proxy/method/Context.h" | ||
|
||
#include "opentelemetry-matlab/metrics/CounterProxy.h" | ||
#include "opentelemetry-matlab/metrics/HistogramProxy.h" | ||
#include "opentelemetry-matlab/metrics/UpDownCounterProxy.h" | ||
|
||
#include "opentelemetry/metrics/meter.h" | ||
|
||
namespace metrics_api = opentelemetry::metrics; | ||
namespace nostd = opentelemetry::nostd; | ||
|
||
namespace libmexclass::opentelemetry { | ||
class MeterProxy : public libmexclass::proxy::Proxy { | ||
public: | ||
MeterProxy(nostd::shared_ptr<metrics_api::Meter> mt) : CppMeter(mt) { | ||
REGISTER_METHOD(MeterProxy, createCounter); | ||
REGISTER_METHOD(MeterProxy, createUpDownCounter); | ||
REGISTER_METHOD(MeterProxy, createHistogram); | ||
} | ||
|
||
void createCounter(libmexclass::proxy::method::Context& context); | ||
|
||
void createUpDownCounter(libmexclass::proxy::method::Context& context); | ||
|
||
void createHistogram(libmexclass::proxy::method::Context& context); | ||
|
||
private: | ||
|
||
nostd::shared_ptr<metrics_api::Meter> CppMeter; | ||
}; | ||
} // namespace libmexclass::opentelemetry |
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,88 @@ | ||
// Copyright 2023 The MathWorks, Inc. | ||
|
||
#include "opentelemetry-matlab/metrics/MeterProxy.h" | ||
|
||
#include "libmexclass/proxy/ProxyManager.h" | ||
|
||
#include "MatlabDataArray.hpp" | ||
|
||
#include <chrono> | ||
|
||
namespace libmexclass::opentelemetry { | ||
void MeterProxy::createCounter(libmexclass::proxy::method::Context& context) { | ||
// Always assumes 3 inputs | ||
matlab::data::StringArray name_mda = context.inputs[0]; | ||
std::string name = static_cast<std::string>(name_mda[0]); | ||
matlab::data::StringArray description_mda = context.inputs[1]; | ||
std::string description= static_cast<std::string>(description_mda[0]); | ||
matlab::data::StringArray unit_mda = context.inputs[2]; | ||
std::string unit = static_cast<std::string>(unit_mda[0]); | ||
|
||
nostd::shared_ptr<metrics_api::Counter<double> > ct = std::move(CppMeter->CreateDoubleCounter(name, description, unit)); | ||
|
||
// instantiate a CounterProxy instance | ||
CounterProxy* newproxy = new CounterProxy(ct); | ||
auto proxy = std::shared_ptr<libmexclass::proxy::Proxy>(newproxy); | ||
|
||
// obtain a proxy ID | ||
libmexclass::proxy::ID proxyid = libmexclass::proxy::ProxyManager::manageProxy(proxy); | ||
|
||
// return the ID | ||
matlab::data::ArrayFactory factory; | ||
auto proxyid_mda = factory.createScalar<libmexclass::proxy::ID>(proxyid); | ||
context.outputs[0] = proxyid_mda; | ||
} | ||
|
||
|
||
void MeterProxy::createUpDownCounter(libmexclass::proxy::method::Context& context) { | ||
// Always assumes 3 inputs | ||
matlab::data::StringArray name_mda = context.inputs[0]; | ||
std::string name = static_cast<std::string>(name_mda[0]); | ||
matlab::data::StringArray description_mda = context.inputs[1]; | ||
std::string description= static_cast<std::string>(description_mda[0]); | ||
matlab::data::StringArray unit_mda = context.inputs[2]; | ||
std::string unit = static_cast<std::string>(unit_mda[0]); | ||
|
||
nostd::shared_ptr<metrics_api::UpDownCounter<double> > ct = std::move(CppMeter->CreateDoubleUpDownCounter | ||
(name, description, unit)); | ||
|
||
// instantiate a UpDownCounterProxy instance | ||
UpDownCounterProxy* newproxy = new UpDownCounterProxy(ct); | ||
auto proxy = std::shared_ptr<libmexclass::proxy::Proxy>(newproxy); | ||
|
||
// obtain a proxy ID | ||
libmexclass::proxy::ID proxyid = libmexclass::proxy::ProxyManager::manageProxy(proxy); | ||
|
||
// return the ID | ||
matlab::data::ArrayFactory factory; | ||
auto proxyid_mda = factory.createScalar<libmexclass::proxy::ID>(proxyid); | ||
context.outputs[0] = proxyid_mda; | ||
} | ||
|
||
|
||
void MeterProxy::createHistogram(libmexclass::proxy::method::Context& context) { | ||
// Always assumes 3 inputs | ||
matlab::data::StringArray name_mda = context.inputs[0]; | ||
std::string name = static_cast<std::string>(name_mda[0]); | ||
matlab::data::StringArray description_mda = context.inputs[1]; | ||
std::string description= static_cast<std::string>(description_mda[0]); | ||
matlab::data::StringArray unit_mda = context.inputs[2]; | ||
std::string unit = static_cast<std::string>(unit_mda[0]); | ||
|
||
nostd::shared_ptr<metrics_api::Histogram<double> > hist = std::move(CppMeter->CreateDoubleHistogram(name, description, unit)); | ||
|
||
// instantiate a HistogramProxy instance | ||
HistogramProxy* newproxy = new HistogramProxy(hist); | ||
auto proxy = std::shared_ptr<libmexclass::proxy::Proxy>(newproxy); | ||
|
||
// obtain a proxy ID | ||
libmexclass::proxy::ID proxyid = libmexclass::proxy::ProxyManager::manageProxy(proxy); | ||
|
||
// return the ID | ||
matlab::data::ArrayFactory factory; | ||
auto proxyid_mda = factory.createScalar<libmexclass::proxy::ID>(proxyid); | ||
context.outputs[0] = proxyid_mda; | ||
} | ||
|
||
|
||
} // namespace libmexclass::opentelemetry |