Skip to content

Commit

Permalink
Add a test for combining auto and manual instrumentation and clean up…
Browse files Browse the repository at this point in the history
… AutoTrace test examples
  • Loading branch information
duncanpo committed Oct 28, 2024
1 parent 1b9ff8a commit 40211f0
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 72 deletions.
9 changes: 0 additions & 9 deletions test/autotrace_examples/example2/example2.m

This file was deleted.

6 changes: 0 additions & 6 deletions test/autotrace_examples/example2/helpers/ex2helper1.m

This file was deleted.

6 changes: 0 additions & 6 deletions test/autotrace_examples/example2/helpers/ex2helper2.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function yf = best_fit_line(x, y)
% example code for testing auto instrumentation
% Fit a straight line on input data

% Copyright 2024 The MathWorks, Inc.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function [x, y] = generate_data(n)
% example code for testing auto instrumentation
% Generate random data with n data points

% Copyright 2024 The MathWorks, Inc.

% check input is valid
if ~(isnumeric(n) && isscalar(n))
error("autotrace_examples:example1:generate_data:InvalidN", ...
error("autotrace_examples:linearfit_example:generate_data:InvalidN", ...
"Input must be a numeric scalar");
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function yf = example1(n)
% example code for testing auto instrumentation. Input n is the number of
function yf = linearfit_example(n)
% Example code for testing auto instrumentation. Input n is the number of
% data points.

% Copyright 2024 The MathWorks, Inc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function yf = example1_trycatch(at, n)
% example code for testing auto instrumentation. This example should not
function yf = linearfit_example_trycatch(at, n)
% Example code for testing auto instrumentation. This example should not
% use beginTrace method and instead should be called directly.

% Copyright 2024 The MathWorks, Inc.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function yf = best_fit_line(x, y)
% Fit a straight line on input data and manually start and end two spans.

% Copyright 2024 The MathWorks, Inc.

tr = opentelemetry.trace.getTracer("ManualInstrument");

sp1 = startSpan(tr, "polyfit");
coefs = polyfit(x, y, 1);
endSpan(sp1);

sp2 = startSpan(tr, "polyval");
yf = polyval(coefs , x);
endSpan(sp2);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function [x, y] = generate_data(n)
% Generate random data with n data points and manually start and end a span.

% Copyright 2024 The MathWorks, Inc.

% check input is valid
if ~(isnumeric(n) && isscalar(n))
error("autotrace_examples:linearfit_example:generate_data:InvalidN", ...
"Input must be a numeric scalar");
end

% generate some random data
a = 1.5;
b = 0.8;
sigma = 5;
x = 1:n;

% start a span
tr = opentelemetry.trace.getTracer("ManualInstrument");
sp = startSpan(tr, "compute_y");
y = a * x + b + sigma * randn(1, n);
endSpan(sp);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function yf = manual_instrumented_example(n)
% Example code for testing auto and manual instrumentation together.
% Input n is the number of data points.

% Copyright 2024 The MathWorks, Inc.

[x, y] = generate_data(n);
yf = best_fit_line(x,y);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function x = subfolder_helper1(x)
% example code for testing auto instrumentation, helper function

% Copyright 2024 The MathWorks, Inc.

x = x * 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function x = subfolder_helper2(x)
% example code for testing auto instrumentation, helper function

% Copyright 2024 The MathWorks, Inc.

x = x * 3;
10 changes: 10 additions & 0 deletions test/autotrace_examples/subfolder_example/subfolder_example.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function x = subfolder_example
% Example code for testing auto instrumentation, with some helper functions
% in a subfolder

% Copyright 2024 The MathWorks, Inc.

x = 10;
x = subfolder_helper1(x);
x = subfolder_helper2(x);

Loading

0 comments on commit 40211f0

Please sign in to comment.