git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Petr Baudis <pasky@suse.cz>, Fredrik Kuivinen <frekui@gmail.com>,
	Giuseppe Bilotta <giuseppe.bilotta@gmail.com>,
	Luben Tuikov <ltuikov@yahoo.com>,
	Martin Koegler <mkoegler@auto.tuwien.ac.at>,
	Jakub Narebski <jnareb@gmail.com>
Subject: [PATCH 08/10] gitweb: Add optional "time to generate page" info in footer
Date: Sat, 25 Jul 2009 00:44:08 +0200	[thread overview]
Message-ID: <1248475450-5668-9-git-send-email-jnareb@gmail.com> (raw)
In-Reply-To: <1248475450-5668-1-git-send-email-jnareb@gmail.com>

Add "This page took XXXs 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.

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

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch was extracted from 5/3 patch implementing interactive
blame, and modified to be conditional on 'timed' feature, and to show
also number of git commands used.

Note that setting $t0 variable should be fairly early to have running
time of the whole script.  The same for $number_of_git_cmds.

Current formatting is very basic, just like before.  It simply uses 
'page_footer' style.

Variable names and name of feature is up to debate.

 gitweb/gitweb.perl |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 0d91ac7..bd77b31 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -18,6 +18,12 @@ use File::Find qw();
 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'};
 }
@@ -394,6 +400,13 @@ our %feature = (
 		'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 {
@@ -507,6 +520,7 @@ if (-e $GITWEB_CONFIG) {
 
 # version of the core git binary
 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
+$number_of_git_cmds++;
 
 $projects_list ||= $projectroot;
 
@@ -1956,6 +1970,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;
 }
 
@@ -3206,6 +3221,20 @@ sub git_footer_html {
 	}
 	print "</div>\n"; # class="page_footer"
 
+	if (defined $t0 && gitweb_check_feature('timed')) {
+		print "<div id=\"generate_info\" class=\"page_footer\">\n";
+		print 'This page took '.
+		      '<span id="generate_time" class="time_span">'.
+		      Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).'s'.
+		      '</span>'.
+		      ' and '.
+		      '<span id="generate_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);
 	}
-- 
1.6.3.3

  parent reply	other threads:[~2009-07-24 22:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-24 22:44 [PATCHv2 00/10] gitweb: 'blame' view improvements Jakub Narebski
2009-07-24 22:44 ` [PATCH 01/10] gitweb: Make .error style generic Jakub Narebski
2009-07-24 22:44 ` [PATCH 02/10] gitweb: Mark boundary commits in 'blame' view Jakub Narebski
2009-07-25  0:13   ` Junio C Hamano
2009-07-25  0:32     ` Jakub Narebski
2009-07-25  0:39       ` Junio C Hamano
2009-07-24 22:44 ` [PATCHv2 03/10] gitweb: Use "previous" header of git-blame -p " Jakub Narebski
2009-07-24 22:44 ` [PATCH 04/10] gitweb: Mark commits with no "previous" " Jakub Narebski
2009-07-24 22:44 ` [PATCHv2 05/10] gitweb: Add author initials in 'blame' view, a la "git gui blame" Jakub Narebski
2009-07-24 22:44 ` [PATCH/RFC 06/10] gitweb: Use light/dark for class names also in 'blame' view Jakub Narebski
2009-07-24 22:44 ` [PATCH 07/10] gitweb: Add -partial_query option to href() subroutine Jakub Narebski
2009-07-24 22:44 ` Jakub Narebski [this message]
2009-07-24 22:44 ` [PATCHv2/RFC 09/10] gitweb: Incremental blame (proof of concept) Jakub Narebski
2009-07-25 19:28   ` Jakub Narebski
2009-07-24 22:44 ` [PATCH/RFC 10/10] gitweb: Create links leading to 'blame_incremental' using JavaScript Jakub Narebski
2009-07-25 10:46   ` Martin Koegler
2009-07-26 10:06     ` Jakub Narebski
2009-07-27 18:10       ` Martin Koegler
2009-07-27 19:06         ` Jakub Narebski
2009-07-24 23:47 ` [PATCHv2 00/10] gitweb: 'blame' view improvements Junio C Hamano
2009-07-25  0:10   ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1248475450-5668-9-git-send-email-jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=frekui@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=giuseppe.bilotta@gmail.com \
    --cc=ltuikov@yahoo.com \
    --cc=mkoegler@auto.tuwien.ac.at \
    --cc=pasky@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).