Skip to content

Commit

Permalink
Added the possibility to add data to timer measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
ezander committed Sep 27, 2017
1 parent ba3d9ce commit a81056c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion util/timers.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function t=timers(action,timer)
function t=timers(action, timer, varargin)
% TIMERS Allows starting and stopping of timers for performance measurements.
% TIMERS( ACTION, TIMER ) performs the action ACTION on the timer
% identified TIMER by the string TIMER, which must be a valid matlab
Expand Down Expand Up @@ -43,6 +43,7 @@
ts.(timer).time=0;
ts.(timer).tic=-1;
ts.(timer).run=0;
ts.(timer).data=struct();
end
end

Expand All @@ -51,6 +52,7 @@
ts.(timer).time=0;
ts.(timer).tic=-1;
ts.(timer).run=0;
ts.(timer).data=struct();
case {1,'start'}
if ts.(timer).run==0
ts.(timer).tic=tic;
Expand Down Expand Up @@ -79,6 +81,18 @@
end
case {5,'resetall'}
ts=struct();
case {'adddata'}
assert(length(varargin)==2);
key = varargin{1};
value = varargin{2};
ts.(timer).data.(key) = value;
case {'getdata'}
t=struct();
names=sort( fieldnames(ts) );
for i=1:length(names)
timer=names{i};
t.(timer)=ts.(timer).data;
end
otherwise
error( 'timers:wrong_param', 'Unknown action for timers: %s', action );
end

0 comments on commit a81056c

Please sign in to comment.