From e1c7e546aad445763f581d9c31d9df98cd077737 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Fri, 6 Apr 2012 06:27:34 +0530 Subject: [PATCH] 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. --- doc/g2alt.mkd | 5 ++--- doc/non-core.mkd | 5 ++--- doc/triggers.mkd | 14 ++---------- src/Gitolite/Rc.pm | 9 ++++---- src/Gitolite/Triggers/CpuTime.pm | 38 ++++++++++++++++++++++++++++++++ src/gitolite-shell | 2 +- src/triggers/cpu-time | 28 ----------------------- t/mirror-test-rc | 21 +++++++++++++----- 8 files changed, 65 insertions(+), 57 deletions(-) create mode 100755 src/Gitolite/Triggers/CpuTime.pm delete mode 100755 src/triggers/cpu-time diff --git a/doc/g2alt.mkd b/doc/g2alt.mkd index a578805..ac10c71 100644 --- a/doc/g2alt.mkd +++ b/doc/g2alt.mkd @@ -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. diff --git a/doc/non-core.mkd b/doc/non-core.mkd index 7583b66..095cc3b 100644 --- a/doc/non-core.mkd +++ b/doc/non-core.mkd @@ -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: diff --git a/doc/triggers.mkd b/doc/triggers.mkd index 4517564..5ae8609 100644 --- a/doc/triggers.mkd +++ b/doc/triggers.mkd @@ -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 diff --git a/src/Gitolite/Rc.pm b/src/Gitolite/Rc.pm index c7390eb..96d638f 100644 --- a/src/Gitolite/Rc.pm +++ b/src/Gitolite/Rc.pm @@ -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 diff --git a/src/Gitolite/Triggers/CpuTime.pm b/src/Gitolite/Triggers/CpuTime.pm new file mode 100755 index 0000000..6ef566e --- /dev/null +++ b/src/Gitolite/Triggers/CpuTime.pm @@ -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; diff --git a/src/gitolite-shell b/src/gitolite-shell index 4d201c7..442ae9e 100755 --- a/src/gitolite-shell +++ b/src/gitolite-shell @@ -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 ); } # ---------------------------------------------------------------------- diff --git a/src/triggers/cpu-time b/src/triggers/cpu-time deleted file mode 100755 index c7ca8f7..0000000 --- a/src/triggers/cpu-time +++ /dev/null @@ -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 ); -} - diff --git a/t/mirror-test-rc b/t/mirror-test-rc index c5752bb..23cd108 100644 --- a/t/mirror-test-rc +++ b/t/mirror-test-rc @@ -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