This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathInstrumentation.pm
99 lines (77 loc) · 1.58 KB
/
Instrumentation.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Workflow::Instrumentation;
# --- WARNING ---
# This is a prototype interface to the statsd server.
# It is likely to change, so use it at your own risk.
# --- WARNING ---
use strict;
use warnings;
use Net::Statsd;
use Time::HiRes;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(decrement
increment
gauge
timer
timing
);
BEGIN {
if ($ENV{UR_DBI_NO_COMMIT}) {
$Net::Statsd::HOST = ''; # disabled if testing
$Net::Statsd::PORT = 0;
} else {
$Net::Statsd::HOST = 'apipe-statsd.gsc.wustl.edu';
$Net::Statsd::PORT = 8125;
}
};
sub dec {
eval {
Net::Statsd::dec(@_);
};
}
sub decrement {
eval {
Net::Statsd::decrement(@_);
};
}
sub gauge {
eval {
Net::Statsd::gauge(@_);
};
}
sub inc {
eval {
Net::Statsd::inc(@_);
};
}
sub increment {
eval {
Net::Statsd::increment(@_);
};
}
sub timer {
my ($name, $code) = @_;
my $start_time = Time::HiRes::time();
eval {
$code->();
};
if ($@) {
my $error = $@;
my $stop_time = Time::HiRes::time();
eval {
my $error_name = "$name\_error";
Net::Statsd::timing($error_name, 1000 * ($stop_time - $start_time));
};
die $error;
}
my $stop_time = Time::HiRes::time();
eval {
Net::Statsd::timing($name, 1000 * ($stop_time - $start_time));
};
}
sub timing {
eval {
Net::Statsd::timing(@_);
};
}
1;