2012-04-06 02:57:34 +02:00
|
|
|
package Gitolite::Triggers::CpuTime;
|
|
|
|
|
2012-04-07 15:36:02 +02:00
|
|
|
use Time::HiRes;
|
|
|
|
|
2012-04-06 02:57:34 +02:00
|
|
|
use Gitolite::Rc;
|
|
|
|
use Gitolite::Common;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2012-04-07 15:36:02 +02:00
|
|
|
# cpu and elapsed times for gitolite+git operations
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# 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 instead.
|
|
|
|
|
2012-04-06 02:57:34 +02:00
|
|
|
# ----------------------------------------------------------------------
|
2012-04-07 15:36:02 +02:00
|
|
|
my $start_time;
|
|
|
|
|
|
|
|
# this trigger is not yet documented; it gets called at the start and does not
|
|
|
|
# receive any arguments.
|
|
|
|
sub input {
|
|
|
|
_warn "something wrong with the invocation of CpuTime::input" if $ENV{GL_TID} ne $$;
|
|
|
|
$start_time = [ Time::HiRes::gettimeofday() ];
|
|
|
|
}
|
2012-04-06 02:57:34 +02:00
|
|
|
|
|
|
|
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();
|
2012-04-07 15:36:02 +02:00
|
|
|
my $elapsed = Time::HiRes::tv_interval($start_time);
|
2012-04-06 02:57:34 +02:00
|
|
|
|
2012-04-07 15:36:02 +02:00
|
|
|
gl_log( 'times', $utime, $stime, $cutime, $cstime, $elapsed );
|
2012-04-06 02:57:34 +02:00
|
|
|
|
2012-04-07 15:36:02 +02:00
|
|
|
# now do whatever you want with the data; the following is just an example.
|
2012-04-06 02:57:34 +02:00
|
|
|
|
|
|
|
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 );
|
2012-04-07 15:36:02 +02:00
|
|
|
say2 " elapsed time: " . $elapsed;
|
2012-04-06 02:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|