From 18524ec34d43f4da378cea7b5eb9ea83ccd963c3 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Wed, 25 Apr 2012 15:20:46 -0400 Subject: [PATCH] Instrument the TPAC: add timelog() method to EGCatLoader Meant for timing how long events take to generate a single TPAC page, the timelog() method will provide timing in microsecond granularity of various events required to build the page. To invoke: $self->timelog("Event description..."); Builds up a context variable named "timing" containing a list of arrays; each array entry contains a time and the event description. Disabled by default; to enable, set DEBUG_TIMING = 1 in OpenILS/WWW/EGCatLoader.pm Signed-off-by: Dan Scott Signed-off-by: Lebbeous Fogle-Weekley --- .../perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 19 +++++++++++++++++++ Open-ILS/src/templates/opac/parts/footer.tt2 | 9 ++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index c333023b8b..2e83f0f013 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -14,6 +14,7 @@ use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Fieldmapper; use DateTime::Format::ISO8601; use CGI qw(:all -utf8); +use Time::HiRes; # EGCatLoader sub-modules use OpenILS::WWW::EGCatLoader::Util; @@ -33,6 +34,8 @@ use constant COOKIE_ANON_CACHE => 'anoncache'; use constant ANON_CACHE_MYLIST => 'mylist'; use constant ANON_CACHE_STAFF_SEARCH => 'staffsearch'; +use constant DEBUG_TIMING => 0; + sub new { my($class, $apache, $ctx) = @_; @@ -41,6 +44,7 @@ sub new { $self->apache($apache); $self->ctx($ctx); $self->cgi(new CGI); + $self->timelog("New page"); OpenILS::Utils::CStoreEditor->init; # just in case $self->editor(new_editor()); @@ -77,6 +81,20 @@ sub cgi { return $self->{cgi}; } +sub timelog { + my($self, $description) = @_; + + return unless DEBUG_TIMING; + return unless $description; + $self->ctx->{timing} ||= []; + + my $timer = [Time::HiRes::gettimeofday()]; + $self->ctx->{time_begin} ||= $timer; + + push @{$self->ctx->{timing}}, [ + Time::HiRes::tv_interval($self->ctx->{time_begin}, $timer), $description + ]; +} # ----------------------------------------------------------------------------- # Perform initial setup, load common data, then load page data @@ -85,6 +103,7 @@ sub load { my $self = shift; $self->init_ro_object_cache; + $self->timelog("Initial load"); my $stat = $self->load_common; return $stat unless $stat == Apache2::Const::OK; diff --git a/Open-ILS/src/templates/opac/parts/footer.tt2 b/Open-ILS/src/templates/opac/parts/footer.tt2 index ce6062860e..76c6b7a56d 100644 --- a/Open-ILS/src/templates/opac/parts/footer.tt2 +++ b/Open-ILS/src/templates/opac/parts/footer.tt2 @@ -9,7 +9,14 @@ [% l('Bottom Link 3') %]  |  [% l('Bottom Link 4') %]  |  [% l('Bottom Link 5') %] - + [% IF ctx.timing %] +
+ [% FOR event IN ctx.timing %] + At [% event.0 | format("%0.4f") %]: + [% event.1 %]
+ [% END %] +
+ [% END %] -- 2.43.2