Skip to content

Commit 4a12e67

Browse files
committed
add a SynchronousInstrument base class
1 parent b7bb9cf commit 4a12e67

File tree

4 files changed

+48
-90
lines changed

4 files changed

+48
-90
lines changed
Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,36 @@
1-
classdef Counter < handle
2-
% Counter is a value that accumulates over time,
3-
% you can think of this like an odometer on a car; it only ever goes up.
1+
classdef Counter < opentelemetry.metrics.SynchronousInstrument
2+
% Counter is a value that accumulates over time and can only increase
3+
% but not decrease.
44

55
% Copyright 2023 The MathWorks, Inc.
66

7-
properties (SetAccess=immutable)
8-
Name (1,1) string
9-
Description (1,1) string
10-
Unit (1,1) string
11-
end
12-
13-
properties (Access=private)
14-
Proxy % Proxy object to interface C++ code
15-
end
16-
177
methods (Access={?opentelemetry.metrics.Meter})
18-
19-
function obj = Counter(proxy, ctname, ctdescription, ctunit)
8+
function obj = Counter(proxy, name, description, unit)
209
% Private constructor. Use createCounter method of Meter
2110
% to create Counters.
22-
obj.Proxy = proxy;
23-
obj.Name = ctname;
24-
obj.Description = ctdescription;
25-
obj.Unit = ctunit;
11+
[email protected](proxy, name, description, unit);
2612
end
27-
2813
end
29-
14+
3015
methods
31-
3216
function add(obj, value, varargin)
3317
% input value must be a numerical scalar
3418
if isnumeric(value) && isscalar(value)
35-
3619
if nargin == 2
3720
obj.Proxy.add(value);
38-
3921
elseif isa(varargin{1}, "dictionary")
4022
attrkeys = keys(varargin{1});
4123
attrvals = values(varargin{1},"cell");
4224
if all(cellfun(@iscell, attrvals))
4325
attrvals = [attrvals{:}];
4426
end
45-
obj.Proxy.add(value,attrkeys,attrvals);
46-
27+
obj.Proxy.add(value, attrkeys, attrvals);
4728
else
4829
attrkeys = [varargin{1:2:length(varargin)}]';
4930
attrvals = [varargin(2:2:length(varargin))]';
50-
obj.Proxy.add(value,attrkeys,attrvals);
31+
obj.Proxy.add(value, attrkeys, attrvals);
5132
end
5233
end
53-
5434
end
55-
5635
end
57-
58-
59-
end
36+
end
Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,35 @@
1-
classdef Histogram < handle
2-
% Histogram is an instrument that adds or reduce values.
1+
classdef Histogram < opentelemetry.metrics.SynchronousInstrument
2+
% Histogram is an instrument that aggregates values into bins
33

44
% Copyright 2023 The MathWorks, Inc.
55

6-
properties (SetAccess=immutable)
7-
Name (1,1) string
8-
Description (1,1) string
9-
Unit (1,1) string
10-
end
11-
12-
properties (Access=public)
13-
Proxy % Proxy object to interface C++ code
14-
end
15-
166
methods (Access={?opentelemetry.metrics.Meter})
17-
18-
function obj = Histogram(proxy, hiname, hidescription, hiunit)
7+
function obj = Histogram(proxy, name, description, unit)
198
% Private constructor. Use createHistogram method of Meter
209
% to create Histograms.
21-
obj.Proxy = proxy;
22-
obj.Name = hiname;
23-
obj.Description = hidescription;
24-
obj.Unit = hiunit;
10+
[email protected](proxy, name, description, unit);
2511
end
26-
2712
end
28-
13+
2914
methods
30-
3115
function record(obj, value, varargin)
3216
% input value must be a numerical scalar
3317
if isnumeric(value) && isscalar(value)
34-
if nargin == 2
18+
if nargin == 2
3519
obj.Proxy.record(value);
3620
elseif isa(varargin{1}, "dictionary")
3721
attrkeys = keys(varargin{1});
3822
attrvals = values(varargin{1},"cell");
3923
if all(cellfun(@iscell, attrvals))
4024
attrvals = [attrvals{:}];
4125
end
42-
obj.Proxy.record(value,attrkeys,attrvals);
26+
obj.Proxy.record(value, attrkeys, attrvals);
4327
else
4428
attrkeys = [varargin{1:2:length(varargin)}]';
4529
attrvals = [varargin(2:2:length(varargin))]';
46-
obj.Proxy.record(value,attrkeys,attrvals);
30+
obj.Proxy.record(value, attrkeys, attrvals);
4731
end
4832
end
49-
5033
end
51-
5234
end
53-
54-
5535
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
classdef SynchronousInstrument < handle
2+
% Base class inherited by all synchronous instruments
3+
4+
% Copyright 2023 The MathWorks, Inc.
5+
6+
properties (SetAccess=immutable)
7+
Name (1,1) string
8+
Description (1,1) string
9+
Unit (1,1) string
10+
end
11+
12+
properties (Access=protected)
13+
Proxy % Proxy object to interface C++ code
14+
end
15+
16+
methods (Access=protected)
17+
function obj = SynchronousInstrument(proxy, name, description, unit)
18+
obj.Proxy = proxy;
19+
obj.Name = name;
20+
obj.Description = description;
21+
obj.Unit = unit;
22+
end
23+
end
24+
end
Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,35 @@
1-
classdef UpDownCounter < handle
1+
classdef UpDownCounter < opentelemetry.metrics.SynchronousInstrument
22
% UpDownCounter is an instrument that adds or reduce values.
33

44
% Copyright 2023 The MathWorks, Inc.
55

6-
properties (SetAccess=immutable)
7-
Name (1,1) string
8-
Description (1,1) string
9-
Unit (1,1) string
10-
end
11-
12-
properties (Access=public)
13-
Proxy % Proxy object to interface C++ code
14-
end
15-
166
methods (Access={?opentelemetry.metrics.Meter})
17-
18-
function obj = UpDownCounter(proxy, ctname, ctdescription, ctunit)
7+
function obj = UpDownCounter(proxy, name, description, unit)
198
% Private constructor. Use createUpDownCounter method of Meter
209
% to create UpDownCounters.
21-
obj.Proxy = proxy;
22-
obj.Name = ctname;
23-
obj.Description = ctdescription;
24-
obj.Unit = ctunit;
10+
[email protected](proxy, name, description, unit);
2511
end
26-
2712
end
28-
13+
2914
methods
30-
3115
function add(obj, value, varargin)
3216
% input value must be a numerical scalar
3317
if isnumeric(value) && isscalar(value)
34-
3518
if nargin == 2
3619
obj.Proxy.add(value);
37-
3820
elseif isa(varargin{1}, "dictionary")
3921
attrkeys = keys(varargin{1});
4022
attrvals = values(varargin{1},"cell");
4123
if all(cellfun(@iscell, attrvals))
4224
attrvals = [attrvals{:}];
4325
end
44-
obj.Proxy.add(value,attrkeys,attrvals);
45-
26+
obj.Proxy.add(value, attrkeys, attrvals);
4627
else
4728
attrkeys = [varargin{1:2:length(varargin)}]';
4829
attrvals = [varargin(2:2:length(varargin))]';
49-
obj.Proxy.add(value,attrkeys,attrvals);
30+
obj.Proxy.add(value, attrkeys, attrvals);
5031
end
5132
end
52-
5333
end
54-
5534
end
56-
57-
58-
end
35+
end

0 commit comments

Comments
 (0)