-
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.
Merge pull request #49 from mathworks/sync_instrument
add a SynchronousInstrument base class
- Loading branch information
Showing
4 changed files
with
48 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,36 @@ | ||
classdef Counter < handle | ||
% Counter is a value that accumulates over time, | ||
% you can think of this like an odometer on a car; it only ever goes up. | ||
classdef Counter < opentelemetry.metrics.SynchronousInstrument | ||
% Counter is a value that accumulates over time and can only increase | ||
% but not decrease. | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (SetAccess=immutable) | ||
Name (1,1) string | ||
Description (1,1) string | ||
Unit (1,1) string | ||
end | ||
|
||
properties (Access=private) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
|
||
function obj = Counter(proxy, ctname, ctdescription, ctunit) | ||
function obj = Counter(proxy, name, description, unit) | ||
% Private constructor. Use createCounter method of Meter | ||
% to create Counters. | ||
obj.Proxy = proxy; | ||
obj.Name = ctname; | ||
obj.Description = ctdescription; | ||
obj.Unit = ctunit; | ||
[email protected](proxy, name, description, unit); | ||
end | ||
|
||
end | ||
|
||
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); | ||
|
||
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); | ||
obj.Proxy.add(value, attrkeys, attrvals); | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
|
||
end | ||
end |
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 |
---|---|---|
@@ -1,55 +1,35 @@ | ||
classdef Histogram < handle | ||
% Histogram is an instrument that adds or reduce values. | ||
classdef Histogram < opentelemetry.metrics.SynchronousInstrument | ||
% Histogram is an instrument that aggregates values into bins | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (SetAccess=immutable) | ||
Name (1,1) string | ||
Description (1,1) string | ||
Unit (1,1) string | ||
end | ||
|
||
properties (Access=public) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
|
||
function obj = Histogram(proxy, hiname, hidescription, hiunit) | ||
function obj = Histogram(proxy, name, description, unit) | ||
% Private constructor. Use createHistogram method of Meter | ||
% to create Histograms. | ||
obj.Proxy = proxy; | ||
obj.Name = hiname; | ||
obj.Description = hidescription; | ||
obj.Unit = hiunit; | ||
[email protected](proxy, name, description, unit); | ||
end | ||
|
||
end | ||
|
||
methods | ||
|
||
function record(obj, value, varargin) | ||
% input value must be a numerical scalar | ||
if isnumeric(value) && isscalar(value) | ||
if nargin == 2 | ||
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); | ||
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); | ||
obj.Proxy.record(value, attrkeys, attrvals); | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
|
||
end |
24 changes: 24 additions & 0 deletions
24
api/metrics/+opentelemetry/+metrics/SynchronousInstrument.m
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,24 @@ | ||
classdef SynchronousInstrument < handle | ||
% Base class inherited by all synchronous instruments | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (SetAccess=immutable) | ||
Name (1,1) string | ||
Description (1,1) string | ||
Unit (1,1) string | ||
end | ||
|
||
properties (Access=protected) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access=protected) | ||
function obj = SynchronousInstrument(proxy, name, description, unit) | ||
obj.Proxy = proxy; | ||
obj.Name = name; | ||
obj.Description = description; | ||
obj.Unit = unit; | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,58 +1,35 @@ | ||
classdef UpDownCounter < handle | ||
classdef UpDownCounter < opentelemetry.metrics.SynchronousInstrument | ||
% UpDownCounter is an instrument that adds or reduce values. | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (SetAccess=immutable) | ||
Name (1,1) string | ||
Description (1,1) string | ||
Unit (1,1) string | ||
end | ||
|
||
properties (Access=public) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
|
||
function obj = UpDownCounter(proxy, ctname, ctdescription, ctunit) | ||
function obj = UpDownCounter(proxy, name, description, unit) | ||
% Private constructor. Use createUpDownCounter method of Meter | ||
% to create UpDownCounters. | ||
obj.Proxy = proxy; | ||
obj.Name = ctname; | ||
obj.Description = ctdescription; | ||
obj.Unit = ctunit; | ||
[email protected](proxy, name, description, unit); | ||
end | ||
|
||
end | ||
|
||
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); | ||
|
||
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); | ||
obj.Proxy.add(value, attrkeys, attrvals); | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
|
||
end | ||
end |