cpu-time command -> CpuTime trigger module...

...now that triggers are not restricted to external programs and can be
perl code called by gitolite-shell (thus in the same PID), there's no
need to compute and pass along the times() array.

This also changes the arguments to POST_GIT; they're now the same as
PRE_GIT's.
redis
Sitaram Chamarty 2012-04-06 06:27:34 +05:30
parent de40461d9a
commit e1c7e546aa
8 changed files with 65 additions and 57 deletions

View File

@ -5,6 +5,5 @@ alternatives exist.
### gl-time for performance measurement
Take a look at the 'cpu-time' program that you can set to run from the
`POST_GIT` trigger. Just set it to run as the last program in that sequence
so it covers all previous programs.
Take a look at the 'CpuTime' trigger module shipped. Comments within, and
comments in the default rc file that contain the word "cpu", should be useful.

View File

@ -36,9 +36,8 @@ The `PRE_GIT` triggers are:
The `POST_GIT` triggers are:
* cpu-time -- post-git triggers, if you check the [triggers][] doc, receive
4 CPU time numbers from the main shell program. Treat this code as sample
and do do with them as you please to do with as you please.
* CpuTime, which is only a sample because it only prints the CPU times data.
In reality you will want to do something else with it.
The `POST_COMPILE` triggers are:

View File

@ -78,7 +78,8 @@ description of when the trigger runs:
* the ref being updated (e.g., 'refs/heads/master')
* result (see above)
* `PRE_GIT` runs just before running the git command. Arguments:
* `PRE_GIT` and `POST_GIT` run just before and after the git command.
Arguments:
* repo
* user
* 'R' or 'W'
@ -86,17 +87,6 @@ description of when the trigger runs:
* the git command ('git-receive-pack', 'git-upload-pack', or
'git-upload-archive') being invoked.
* `POST_GIT` runs after the git command returns. Arguments:
* repo
* user
* 'R' or 'W'
* 'any'
* the git command ('git-receive-pack', 'git-upload-pack', or
These are followed by the output of the perl function "times" (i.e., 4 CPU
times: user, system, cumulative user, cumulative system) so that's 9
arguments in total
* `PRE_CREATE` and `POST_CREATE` run just before and after a new "[wild][]"
repo is created by user action. Arguments:
* repo

View File

@ -259,9 +259,9 @@ __DATA__
# settings used by external programs; uncomment and change as needed. You
# can add your own variables for use in your own external programs; take a
# look at the cpu-time and desc commands for perl and shell samples.
# look at the info and desc commands for perl and shell samples.
# used by the cpu-time command
# used by the CpuTime trigger
# DISPLAY_CPU_TIME => 1,
# CPU_TIME_WARN_LIMIT => 0.1,
# used by the desc command
@ -335,9 +335,10 @@ __DATA__
# these will run in sequence after the git command returns
POST_GIT =>
[
# if you use this, make this the last item in the list
# 'cpu-time',
# 'Mirroring::post_git',
# if you use this, make this the last item in the list
# 'CpuTime::post_git',
],
# comment out or uncomment as needed

View File

@ -0,0 +1,38 @@
package Gitolite::Triggers::CpuTime;
use Gitolite::Rc;
use Gitolite::Common;
use strict;
use warnings;
# ----------------------------------------------------------------------
sub post_git {
_warn "something wrong with the invocation of CpuTime::post_git" if $ENV{GL_TID} ne $$;
my ( $trigger, $repo, $user, $aa, $ref, $verb ) = @_;
my ( $utime, $stime, $cutime, $cstime ) = times();
gl_log( 'cputime', $utime, $stime, $cutime, $cstime );
# now do whatever you want with the data; the following is just an example.
# Ideally, you will (a) write your own code with a different filename so later
# gitolite upgrades won't overwrite your copy, (b) add appropriate variables
# to the rc file, and (c) change your rc file to call your program at the
# end of the POST_GIT list.
if ( my $limit = $rc{CPU_TIME_WARN_LIMIT} ) {
my $total = $utime + $cutime + $stime + $cstime;
# some code to send an email or whatever...
say2 "limit = $limit, actual = $total" if $total > $limit;
}
if ( $rc{DISPLAY_CPU_TIME} ) {
say2 "perf stats for $verb on repo '$repo':";
say2 " user CPU time: " . ( $utime + $cutime );
say2 " sys CPU time: " . ( $stime + $cstime );
}
}
1;

View File

@ -106,7 +106,7 @@ sub main {
trigger( 'PRE_GIT', $repo, $user, $aa, 'any', $verb );
my $repodir = "'$rc{GL_REPO_BASE}/$repo.git'";
_system( "git", "shell", "-c", "$verb $repodir" );
trigger( 'POST_GIT', $repo, $user, $aa, 'any', $verb, times() );
trigger( 'POST_GIT', $repo, $user, $aa, 'any', $verb );
}
# ----------------------------------------------------------------------

View File

@ -1,28 +0,0 @@
#!/usr/bin/perl
use strict;
use warnings;
use lib $ENV{GL_BINDIR};
use Gitolite::Easy;
my ( $trigger, $repo, $user, $aa, $ref, $verb, $utime, $stime, $cutime, $cstime ) = @ARGV;
# now do whatever you want with this data; the following is just an example.
# Ideally, you will (a) write your own code with a different filename so later
# gitolite upgrades won't overwrite your copy, (b) add appropriate variables
# to the rc file, and (c) change your rc file to call your program at the end
# of the POST_GIT list.
if ( my $limit = $rc{CPU_TIME_WARN_LIMIT} ) {
my $total = $utime + $cutime + $stime + $cstime;
# some code to send an email or whatever...
say2 "limit = $limit, actual = $total" if $total > $limit;
}
if ( $rc{DISPLAY_CPU_TIME} ) {
say2 "perf stats for $verb on repo '$repo':";
say2 " user CPU time: " . ( $utime + $cutime );
say2 " sys CPU time: " . ( $stime + $cstime );
}

View File

@ -7,6 +7,8 @@
# (Tip: perl allows a comma after the last item in a list also!)
%RC = (
# if you're using mirroring, you need a hostname. This is *one* simple
# word, not a full domain name. See documentation if in doubt
HOSTNAME => '%HOSTNAME',
UMASK => 0077,
GIT_CONFIG_KEYS => '',
@ -16,9 +18,9 @@
# settings used by external programs; uncomment and change as needed. You
# can add your own variables for use in your own external programs; take a
# look at the cpu-time and desc commands for perl and shell samples.
# look at the info and desc commands for perl and shell samples.
# used by the cpu-time command
# used by the CpuTime trigger
# DISPLAY_CPU_TIME => 1,
# CPU_TIME_WARN_LIMIT => 0.1,
# used by the desc command
@ -70,7 +72,7 @@
],
# comment out or uncomment as needed
# these will run in sequence at the start, before a git operation has started
# these will run in sequence just before the actual git command is invoked
PRE_GIT =>
[
# if you use this, make this the first item in the list
@ -89,12 +91,19 @@
],
# comment out or uncomment as needed
# these will run in sequence at the end, after a git operation has ended
# these will run in sequence after the git command returns
POST_GIT =>
[
# if you use this, make this the last item in the list
# 'cpu-time',
'Mirroring::post_git',
# if you use this, make this the last item in the list
# 'CpuTime::post_git',
],
# comment out or uncomment as needed
# these will run in sequence before a new wild repo is created
PRE_CREATE =>
[
],
# comment out or uncomment as needed