summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2014-03-05 15:45:11 +0100
committerByron Jones <bjones@mozilla.com>2014-03-05 15:45:11 +0100
commit82731c84210d42bdd66c6d5e4ec80cb26a44b1ae (patch)
tree69fe2887cd9b649796c078b373a97ca4f0d10ea9 /Bugzilla
parent682e51ae50ca12a43b7714c53afaa40f6c4d1dc6 (diff)
downloadbugzilla-82731c84210d42bdd66c6d5e4ec80cb26a44b1ae.tar.gz
bugzilla-82731c84210d42bdd66c6d5e4ec80cb26a44b1ae.tar.xz
restore old show_bug timing code to allow for before/after comparisons
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Instrument.pm68
1 files changed, 68 insertions, 0 deletions
diff --git a/Bugzilla/Instrument.pm b/Bugzilla/Instrument.pm
new file mode 100644
index 000000000..4ab74ff8e
--- /dev/null
+++ b/Bugzilla/Instrument.pm
@@ -0,0 +1,68 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Instrument;
+
+use strict;
+use warnings;
+
+use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
+use Encode qw(encode_utf8);
+use Sys::Syslog qw(:DEFAULT);
+
+sub new {
+ my ($class, $label) = @_;
+ my $self = bless({ times => [], labels => [], values => [] }, $class);
+ $self->label($label);
+ $self->time('start_time');
+ return $self;
+}
+
+sub time {
+ my ($self, $name) = @_;
+ # for now $name isn't used
+ push @{ $self->{times} }, clock_gettime(CLOCK_MONOTONIC);
+}
+
+sub label {
+ my ($self, $value) = @_;
+ push @{ $self->{labels} }, $value;
+}
+
+sub value {
+ my ($self, $name, $value) = @_;
+ # for now $name isn't used
+ push @{ $self->{values} }, $value;
+}
+
+sub log {
+ my $self = shift;
+
+ my @times = @{ $self->{times} };
+ return unless scalar(@times) >= 2;
+ my @labels = @{ $self->{labels} };
+ my @values = @{ $self->{values} };
+
+ # calculate diffs
+ my @diffs = ($times[$#times] - $times[0]);
+ while (1) {
+ my $start = shift(@times);
+ last unless scalar(@times);
+ push @diffs, $times[0] - $start;
+ }
+
+ # build syslog string
+ my $format = '[timing]' . (' %s' x scalar(@labels)) . (' %.6f' x scalar(@diffs)) . (' %s' x scalar(@values));
+ my $entry = sprintf($format, @labels, @diffs, @values);
+
+ # and log
+ openlog('apache', 'cons,pid', 'local4');
+ syslog('notice', encode_utf8($entry));
+ closelog();
+}
+
+1;