Skip to content

Commit

Permalink
Complex number handling and more code sharing between metric instruments
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanpo committed Nov 9, 2023
1 parent adb6cd3 commit 9f9fbc7
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 226 deletions.
18 changes: 1 addition & 17 deletions api/metrics/+opentelemetry/+metrics/Counter.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,7 @@

methods
function add(obj, value, varargin)
% input value must be a numerical scalar
if isnumeric(value) && isscalar(value)
if nargin == 2
obj.Proxy.add(value);
elseif isa(varargin{1}, "dictionary")
attrkeys = keys(varargin{1});
attrvals = values(varargin{1},"cell");
if all(cellfun(@iscell, attrvals))
attrvals = [attrvals{:}];
end
obj.Proxy.add(value, attrkeys, attrvals);
else
attrkeys = [varargin{1:2:length(varargin)}]';
attrvals = [varargin(2:2:length(varargin))]';
obj.Proxy.add(value, attrkeys, attrvals);
end
end
obj.processValue(value, varargin{:});
end
end
end
18 changes: 1 addition & 17 deletions api/metrics/+opentelemetry/+metrics/Histogram.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,7 @@

methods
function record(obj, value, varargin)
% input value must be a numerical scalar
if isnumeric(value) && isscalar(value)
if nargin == 2
obj.Proxy.record(value);
elseif isa(varargin{1}, "dictionary")
attrkeys = keys(varargin{1});
attrvals = values(varargin{1},"cell");
if all(cellfun(@iscell, attrvals))
attrvals = [attrvals{:}];
end
obj.Proxy.record(value, attrkeys, attrvals);
else
attrkeys = [varargin{1:2:length(varargin)}]';
attrvals = [varargin(2:2:length(varargin))]';
obj.Proxy.record(value, attrkeys, attrvals);
end
end
obj.processValue(value, varargin{:});
end
end
end
22 changes: 21 additions & 1 deletion api/metrics/+opentelemetry/+metrics/SynchronousInstrument.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Unit (1,1) string
end

properties (Access=protected)
properties (Access=private)
Proxy % Proxy object to interface C++ code
end

Expand All @@ -20,5 +20,25 @@
obj.Description = description;
obj.Unit = unit;
end

function processValue(obj, value, varargin)
% input value must be a numerical real scalar
if isnumeric(value) && isscalar(value) && isreal(value)
if nargin == 2
obj.Proxy.processValue(value);
elseif isa(varargin{1}, "dictionary")
attrkeys = keys(varargin{1});
attrvals = values(varargin{1},"cell");
if all(cellfun(@iscell, attrvals))
attrvals = [attrvals{:}];
end
obj.Proxy.processValue(value, attrkeys, attrvals);
else
attrkeys = [varargin{1:2:length(varargin)}]';
attrvals = [varargin(2:2:length(varargin))]';
obj.Proxy.processValue(value, attrkeys, attrvals);
end
end
end
end
end
18 changes: 1 addition & 17 deletions api/metrics/+opentelemetry/+metrics/UpDownCounter.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,7 @@

methods
function add(obj, value, varargin)
% input value must be a numerical scalar
if isnumeric(value) && isscalar(value)
if nargin == 2
obj.Proxy.add(value);
elseif isa(varargin{1}, "dictionary")
attrkeys = keys(varargin{1});
attrvals = values(varargin{1},"cell");
if all(cellfun(@iscell, attrvals))
attrvals = [attrvals{:}];
end
obj.Proxy.add(value, attrkeys, attrvals);
else
attrkeys = [varargin{1:2:length(varargin)}]';
attrvals = [varargin(2:2:length(varargin))]';
obj.Proxy.add(value, attrkeys, attrvals);
end
end
obj.processValue(value, varargin{:});
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace libmexclass::opentelemetry {
class CounterProxy : public libmexclass::proxy::Proxy {
public:
CounterProxy(nostd::shared_ptr<metrics_api::Counter<double> > ct) : CppCounter(ct) {
REGISTER_METHOD(CounterProxy, add);
REGISTER_METHOD(CounterProxy, processValue);
}

void add(libmexclass::proxy::method::Context& context);
void processValue(libmexclass::proxy::method::Context& context);

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace libmexclass::opentelemetry {
class HistogramProxy : public libmexclass::proxy::Proxy {
public:
HistogramProxy(nostd::shared_ptr<metrics_api::Histogram<double> > hist) : CppHistogram(hist) {
REGISTER_METHOD(HistogramProxy, record);
REGISTER_METHOD(HistogramProxy, processValue);
}

void record(libmexclass::proxy::method::Context& context);
void processValue(libmexclass::proxy::method::Context& context);

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace libmexclass::opentelemetry {
class UpDownCounterProxy : public libmexclass::proxy::Proxy {
public:
UpDownCounterProxy(nostd::shared_ptr<metrics_api::UpDownCounter<double> > ct) : CppUpDownCounter(ct) {
REGISTER_METHOD(UpDownCounterProxy, add);
REGISTER_METHOD(UpDownCounterProxy, processValue);
}

void add(libmexclass::proxy::method::Context& context);
void processValue(libmexclass::proxy::method::Context& context);

private:

Expand Down
2 changes: 1 addition & 1 deletion api/metrics/src/CounterProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace libmexclass::opentelemetry {


void CounterProxy::add(libmexclass::proxy::method::Context& context){
void CounterProxy::processValue(libmexclass::proxy::method::Context& context){

matlab::data::Array value_mda = context.inputs[0];
double value = static_cast<double>(value_mda[0]);
Expand Down
2 changes: 1 addition & 1 deletion api/metrics/src/HistogramProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace libmexclass::opentelemetry {


void HistogramProxy::record(libmexclass::proxy::method::Context& context){
void HistogramProxy::processValue(libmexclass::proxy::method::Context& context){
// Get value
matlab::data::Array value_mda = context.inputs[0];
double value = static_cast<double>(value_mda[0]);
Expand Down
2 changes: 1 addition & 1 deletion api/metrics/src/UpDownCounterProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace libmexclass::opentelemetry {


void UpDownCounterProxy::add(libmexclass::proxy::method::Context& context){
void UpDownCounterProxy::processValue(libmexclass::proxy::method::Context& context){

matlab::data::Array value_mda = context.inputs[0];
double value = static_cast<double>(value_mda[0]);
Expand Down
Loading

0 comments on commit 9f9fbc7

Please sign in to comment.