Skip to content

Commit

Permalink
gitweb: Add optional "time to generate page" info in footer
Browse files Browse the repository at this point in the history
Add "This page took XXX seconds and Y git commands to generate"
to page footer, if global feature 'timed' is enabled (disabled
by default).  Requires Time::HiRes installed for high precision
'wallclock' time.

Note that Time::HiRes is being required unconditionally; this is
because setting $t0 variable needs to be done fairly early to have
running time of the whole script.  If Time::HiRes module were required
only if 'timed' feature is enabled, the earliest place where starting
time ($t0) could be calculated would be after reading gitweb config,
making "time to generate page" info inaccurate.

This code is based on example code by Petr 'Pasky' Baudis.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jakub Narebski authored and Junio C Hamano committed Sep 1, 2009
1 parent aef3768 commit aa7dd05
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gitweb/gitweb.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ div.page_footer_text {
font-style: italic;
}

div#generating_info {
margin: 4px;
font-size: smaller;
text-align: center;
color: #505050;
}

div.page_body {
padding: 8px;
font-family: monospace;
Expand Down
29 changes: 29 additions & 0 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
use File::Basename qw(basename);
binmode STDOUT, ':utf8';

our $t0;
if (eval { require Time::HiRes; 1; }) {
$t0 = [Time::HiRes::gettimeofday()];
}
our $number_of_git_cmds = 0;

BEGIN {
CGI->compile() if $ENV{'MOD_PERL'};
}
Expand Down Expand Up @@ -394,6 +400,13 @@ BEGIN
'sub' => \&feature_avatar,
'override' => 0,
'default' => ['']},

# Enable displaying how much time and how many git commands
# it took to generate and display page. Disabled by default.
# Project specific override is not supported.
'timed' => {
'override' => 0,
'default' => [0]},
);

sub gitweb_get_feature {
Expand Down Expand Up @@ -507,6 +520,7 @@ sub filter_snapshot_fmts {

# version of the core git binary
our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
$number_of_git_cmds++;

$projects_list ||= $projectroot;

Expand Down Expand Up @@ -1955,6 +1969,7 @@ sub get_feed_info {

# returns path to the core git executable and the --git-dir parameter as list
sub git_cmd {
$number_of_git_cmds++;
return $GIT, '--git-dir='.$git_dir;
}

Expand Down Expand Up @@ -3205,6 +3220,20 @@ sub git_footer_html {
}
print "</div>\n"; # class="page_footer"

if (defined $t0 && gitweb_check_feature('timed')) {
print "<div id=\"generating_info\">\n";
print 'This page took '.
'<span id="generating_time" class="time_span">'.
Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).
' seconds </span>'.
' and '.
'<span id="generating_cmd">'.
$number_of_git_cmds.
'</span> git commands '.
" to generate.\n";
print "</div>\n"; # class="page_footer"
}

if (-f $site_footer) {
insert_file($site_footer);
}
Expand Down

0 comments on commit aa7dd05

Please sign in to comment.