gitolite/src/gl-time

52 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl
# this program is a performance measurement wrapper around anything that it is
# called with; it's arg-1 becomes the program being measured, with arg-2
# onwards being arg-1's arguments
# sorta like the "time" command... hence the name :-)
use strict;
use warnings;
# ----------------------------------------------------------------------------
# find the rc file, then pull the libraries
# ----------------------------------------------------------------------------
# see notes on this code in gl-auth-command
BEGIN {
# find and set bin dir
$0 =~ m|^(/)?(.*)/| and $ENV{GL_BINDIR} = ($1 || "$ENV{PWD}/") . $2;
}
use lib $ENV{GL_BINDIR};
use gitolite_rc;
use gitolite_env;
use gitolite qw(log_it);
use Time::HiRes qw(gettimeofday tv_interval);
# ----------------------------------------------------------------------------
# start...
# ----------------------------------------------------------------------------
# rc file
do "$ENV{HOME}/.gitolite.rc";
# this file is always in a fixed place; code in the main gitolite that
# seems to indicate it is not, is obsolete and needs to be fixed.
# ---------------------------------------------------------------
my $starttime = [gettimeofday];
my $pgm = shift;
my $returncode = system($pgm, @ARGV);
$returncode >>= 8;
$ENV{GL_USER} = shift;
my $elapsedtime = tv_interval($starttime);
$ENV{GL_LOG} = get_logfilename($GL_PERFLOGT);
# log_it logs to $ENV{GL_LOG}
log_it("", "$elapsedtime\trc=$returncode");