Commit 3595089a authored by Leigh Stoller's avatar Leigh Stoller

Minor fix to stats code; Watch for a swapmod on a swapped out

experiment, and not count its pnodes or duration as if it was swapped
in! Thanks Kirk.

The actual fix is simple. The script to fix up the existing stats
records was a bear and took me all morning to get right! Even so, its
probably no perfect, but close enough. That script in the sql directory
and mentioned in doc/UPDATING.
parent 7d9e890f
......@@ -3777,14 +3777,15 @@ sub GatherSwapStats($$$$$;$)
local $DBQUERY_MAXTRIES = 5;
my $query_result =
DBQueryWarn("select e.gid,e.idx,s.rsrcidx,s.lastrsrc,e.expt_swap_uid ".
DBQueryWarn("select e.state,e.gid,e.idx,s.rsrcidx,s.lastrsrc, ".
" e.expt_swap_uid ".
" from experiments as e ".
"left join experiment_stats as s on e.idx=s.exptidx ".
"where e.pid='$pid' and e.eid='$eid'");
if (!$query_result || !$query_result->numrows) {
return;
}
my ($gid, $exptidx, $rsrcidx, $lastrsrc, $lastswapuid) =
my ($curstate, $gid, $exptidx, $rsrcidx, $lastrsrc, $lastswapuid) =
$query_result->fetchrow_array;
$lastswapuid = $uid
if (!defined($lastswapuid) || $lastswapuid eq "");
......@@ -3873,7 +3874,7 @@ sub GatherSwapStats($$$$$;$)
$duration = 0;
if ($mode eq TBDB_STATS_SWAPOUT ||
($mode eq TBDB_STATS_SWAPMODIFY &&
($mode eq TBDB_STATS_SWAPMODIFY && $curstate eq EXPTSTATE_ACTIVE &&
($flags & TBDB_STATS_FLAGS_PREMODIFY) == 0)) {
$query_result =
DBQueryWarn("select r.pnodes,r.vnodes, ".
......
......@@ -6,6 +6,10 @@ This file is in the same format at the FreeBSD UPDATING file, whis is
to say, in reverse chronological order, with the date of the change
in YYYYMMDD format.
20041025:
Run sql/fixstats_swapmod.pl to fix up stats records.
20040901:
New SSL version of the XMLRPC server.
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use lib "/usr/testbed/lib";
use libdb;
use libtestbed;
my %exptstats = ();
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
my $query_result =
DBQueryFatal("select *,UNIX_TIMESTAMP(end_time) as foo ".
" from testbed_stats ".
"where exitcode=0 and ".
" (UNIX_TIMESTAMP(end_time) > ".
" UNIX_TIMESTAMP('2003-05-23 10:06:02')) ".
"order by end_time,idx asc");
while (my $rowref = $query_result->fetchrow_hashref()) {
my $idx = $rowref->{"idx"};
my $uid = $rowref->{"uid"};
my $exptidx = $rowref->{"exptidx"};
my $rsrcidx = $rowref->{"rsrcidx"};
my $action = $rowref->{"action"};
my $endtime = $rowref->{"foo"};
my $curstate;
my $laststamp;
my $lastuid;
if (exists($exptstats{$exptidx})) {
($curstate,$laststamp,$lastuid) = @{ $exptstats{$exptidx} };
}
if ($action eq "preload") {
$exptstats{$exptidx} = [ "preload", $endtime, $uid ];
next;
}
if ($action eq "destroy") {
delete($exptstats{$exptidx});
next;
}
if ($action eq "start" || $action eq "swapin") {
$exptstats{$exptidx} = [ "active", $endtime, $uid ];
next;
}
if ($action eq "swapout") {
$exptstats{$exptidx} = [ "swapped", $endtime, $uid ];
next;
}
if ($action ne "swapmod") {
die("Unknown action $action for index $idx\n");
}
if (!defined($curstate)) {
#print("Unknown current state for index $exptidx. Skipping ...\n");
next;
}
$exptstats{$exptidx} = [ $curstate, $endtime, $uid ];
next
if ($curstate eq "active");
my $pnodes = 0;
my $vnodes = 0;
my $duration = ($curstate eq "preload" ? 0 : $endtime - $laststamp);
my ($pid, $eid, $gid);
my $d_result =
DBQueryFatal("select s.pid,s.eid,s.gid ".
" from experiment_stats as s ".
"where s.exptidx=$exptidx");
if ($d_result && $d_result->numrows) {
($pid,$eid,$gid) = $d_result->fetchrow_array;
}
else {
die("Could not get pid/eid/gid info for index $exptidx\n");
}
if (1) {
print("update project_stats ".
"set allexpt_duration=allexpt_duration-${duration}, ".
" allexpt_vnodes=allexpt_vnodes-${vnodes}, ".
" allexpt_pnodes=allexpt_pnodes-${pnodes}, ".
" allexpt_vnode_duration=".
" allexpt_vnode_duration-($vnodes * ${duration}), ".
" allexpt_pnode_duration=".
" allexpt_pnode_duration-($pnodes * ${duration}) ".
"where pid='$pid';\n");
print("update group_stats ".
"set allexpt_duration=allexpt_duration-${duration}, ".
" allexpt_vnodes=allexpt_vnodes-${vnodes}, ".
" allexpt_pnodes=allexpt_pnodes-${pnodes}, ".
" allexpt_vnode_duration=".
" allexpt_vnode_duration-($vnodes * ${duration}), ".
" allexpt_pnode_duration=".
" allexpt_pnode_duration-($pnodes * ${duration}) ".
"where pid='$pid' and gid='$gid';\n");
print("update user_stats ".
"set allexpt_duration=allexpt_duration-${duration}, ".
" allexpt_vnodes=allexpt_vnodes-${vnodes}, ".
" allexpt_pnodes=allexpt_pnodes-${pnodes}, ".
" allexpt_vnode_duration=".
" allexpt_vnode_duration-($vnodes * ${duration}), ".
" allexpt_pnode_duration=".
" allexpt_pnode_duration-($pnodes * ${duration}) ".
"where uid='$lastuid';\n");
print("update experiment_stats ".
"set swapin_duration=swapin_duration-${duration} ".
"where pid='$pid' and eid='$eid' and ".
" exptidx=$exptidx;\n");
}
else {
print("IDX:$exptidx ($pid,$eid,$gid,$lastuid): ".
"$duration $pnodes $vnodes\n");
}
}
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