Commit 00d1cea8 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add some instrumentation code (STAMPS), and a DU routine to DU the

user directory.
parent ec5050fb
......@@ -28,6 +28,7 @@ my $TB = "@prefix@";
my $BOSSNODE = "@BOSSNODE@";
my $CONTROL = "@USERNODE@";
my $EVENTSYS = @EVENTSYS@;
my $STAMPS = @STAMPS@;
my $TEVC = "$TB/bin/tevc";
my $DBCONTROL = "$TB/sbin/opsdb_control";
my $RSYNC = "/usr/local/bin/rsync";
......@@ -36,6 +37,7 @@ my $TBPRERUN = "$TB/bin/tbprerun";
my $TBSWAP = "$TB/bin/tbswap";
my $TBREPORT = "$TB/bin/tbreport";
my $TBEND = "$TB/bin/tbend";
my $DU = "/usr/bin/du";
# Hmm, this is silly.
if ($EVENTSYS) {
......@@ -52,7 +54,10 @@ sub mysystem($)
{
my ($command) = @_;
print STDERR "Running '$command'\n"
my $cwd;
chomp($cwd = `pwd`);
print STDERR "Running '$command' in $cwd\n"
if ($debug);
return system($command);
}
......@@ -959,6 +964,7 @@ sub Report($;$$)
$options = ""
if (!defined($options));
print "Running 'tbreport $options $pid $eid'\n";
mysystem("$TBREPORT $options $pid $eid 2>&1 > $filename");
return -1
if ($?);
......@@ -1507,5 +1513,72 @@ sub InitializeEnvVariables($)
return 0;
}
#
# Record a stamp event.
#
sub Stamp($$;$$$)
{
my ($self, $type, $modifier, $aux_type, $aux_data) = @_;
return 0
if (! $STAMPS);
# Must be a real reference.
return -1
if (! ref($self));
my $exptidx = $self->idx();
my $rsrcidx = $self->rsrcidx();
$modifier = (defined($modifier) ? "'$modifier'" : "NULL");
DBQueryWarn("insert into experiment_stamps set ".
" exptidx='$exptidx', id=NULL, rsrcidx='$rsrcidx', ".
" stamp_type='$type', modifier=$modifier, ".
" stamp=UNIX_TIMESTAMP(now()) ".
(defined($aux_type) ?
",aux_type='$aux_type',aux_data='$aux_data'" : ""))
or return -1;
return 0;
}
#
# DU experiment directory
#
sub DU($$)
{
my ($self, $prval) = @_;
# Must be a real reference.
return -1
if (! ref($self));
$$prval = 0;
my $userdir = $self->UserDir();
#
# Start a subprocess that does the du, and then read it back.
#
if (!open(DU, "$DU -s -k $userdir |")) {
print STDERR "DU: Could not start du!\n";
return -1;
}
my $line;
while (<DU>) {
chomp($_);
$line = $_;
}
return -1
if (! close(DU));
if ($line =~ /^(\d+)\s+/) {
$$prval = $1;
return 0;
}
return -1;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment