@matheusbsbs / matheus-bagliano / commits / aa7dd05e6a
Fork 0

gitweb: Add optional "time to generate page" info in footer

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>

Jakub Narebski committed Sep 1, 2009 at 13:39 UTC aa7dd05e6a622ec17d034980c4440b0aed583c6e
2 files changed +36
gitweb/gitweb.css
+7
@@ -75,6 +75,13 @@ div.page_footer_text {
75 font-style: italic;
76 }
77
78 +div#generating_info {
79 + margin: 4px;
80 + font-size: smaller;
81 + text-align: center;
82 + color: #505050;
83 +}
84 +
85 div.page_body {
86 padding: 8px;
87 font-family: monospace;
gitweb/gitweb.perl
+29
@@ -18,6 +18,12 @@ use File::Find qw();
18 use File::Basename qw(basename);
19 binmode STDOUT, ':utf8';
20
21 +our $t0;
22 +if (eval { require Time::HiRes; 1; }) {
23 + $t0 = [Time::HiRes::gettimeofday()];
24 +}
25 +our $number_of_git_cmds = 0;
26 +
27 BEGIN {
28 CGI->compile() if $ENV{'MOD_PERL'};
29 }
@@ -394,6 +400,13 @@ our %feature = (
400 'sub' => \&feature_avatar,
401 'override' => 0,
402 'default' => ['']},
403 +
404 + # Enable displaying how much time and how many git commands
405 + # it took to generate and display page. Disabled by default.
406 + # Project specific override is not supported.
407 + 'timed' => {
408 + 'override' => 0,
409 + 'default' => [0]},
410 );
411
412 sub gitweb_get_feature {
@@ -507,6 +520,7 @@ if (-e $GITWEB_CONFIG) {
520
521 # version of the core git binary
522 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
523 +$number_of_git_cmds++;
524
525 $projects_list ||= $projectroot;
526
@@ -1955,6 +1969,7 @@ sub get_feed_info {
1969
1970 # returns path to the core git executable and the --git-dir parameter as list
1971 sub git_cmd {
1972 + $number_of_git_cmds++;
1973 return $GIT, '--git-dir='.$git_dir;
1974 }
1975
@@ -3205,6 +3220,20 @@ sub git_footer_html {
3220 }
3221 print "</div>\n"; # class="page_footer"
3222
3223 + if (defined $t0 && gitweb_check_feature('timed')) {
3224 + print "<div id=\"generating_info\">\n";
3225 + print 'This page took '.
3226 + '<span id="generating_time" class="time_span">'.
3227 + Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).
3228 + ' seconds </span>'.
3229 + ' and '.
3230 + '<span id="generating_cmd">'.
3231 + $number_of_git_cmds.
3232 + '</span> git commands '.
3233 + " to generate.\n";
3234 + print "</div>\n"; # class="page_footer"
3235 + }
3236 +
3237 if (-f $site_footer) {
3238 insert_file($site_footer);
3239 }