Commit 495f6803 authored by Leigh Stoller's avatar Leigh Stoller

Big update to the stats gathering code ...

This change attempts to make the stats gathering code more reliable by
not relying on the testbed_stats records to reconstruct usage
statistics.  The main source of errors and total confusion in the
current stats code is that testbed_stats includes all the errors and
transitions, from which I have to reconstruct what happened in order
to determine usage by a project or user.

The new stats code still generates the testbed_stats code, but actual
usage is recorded as it happens, in the experiment_resources table, as
swapins, swapouts, and swapmods occur. Its also much faster to compute
the data for the tables in the web interface, not having to scan a
zillion testbed_stats records in php.

There is a time consuming update to the records that takes place with
a lot of tables locked.
parent cf64f716
This diff is collapsed.
...@@ -788,6 +788,60 @@ sub MemberList($$;$$) ...@@ -788,6 +788,60 @@ sub MemberList($$;$$)
return 0; return 0;
} }
#
# Update the aggregate stats.
#
sub UpdateStats($$$$$)
{
my ($self, $mode, $duration, $pnodes, $vnodes) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $gid_idx = $self->gid_idx();
DBQueryWarn("update group_stats ".
"set expt${mode}_count=expt${mode}_count+1, ".
" expt${mode}_last=now(), ".
" 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 gid_idx='$gid_idx'");
if ($mode eq TBDB_STATS_SWAPIN || $mode eq TBDB_STATS_START) {
DBQueryWarn("update groups set ".
" expt_last=now(),expt_count=expt_count+1 ".
"where gid_idx='$gid_idx'");
}
$self->Refresh();
return 0;
}
#
# Bump last activity
#
sub BumpActivity($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $gid_idx = $self->gid_idx();
DBQueryWarn("update group_stats set last_activity=now() ".
"where gid_idx='$gid_idx'");
return 0;
}
############################################################################ ############################################################################
package Group::MemberShip; package Group::MemberShip;
...@@ -1046,3 +1100,4 @@ sub ModifyTrust($$) ...@@ -1046,3 +1100,4 @@ sub ModifyTrust($$)
# _Always_ make sure that this 1 is at the end of the file... # _Always_ make sure that this 1 is at the end of the file...
1; 1;
...@@ -563,5 +563,60 @@ sub GroupList($$) ...@@ -563,5 +563,60 @@ sub GroupList($$)
return 0; return 0;
} }
#
# Update the aggregate stats.
#
sub UpdateStats($$$$$)
{
my ($self, $mode, $duration, $pnodes, $vnodes) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $pid_idx = $self->pid_idx();
DBQueryWarn("update project_stats ".
"set expt${mode}_count=expt${mode}_count+1, ".
" expt${mode}_last=now(), ".
" 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_idx='$pid_idx'");
if ($mode eq TBDB_STATS_SWAPIN || $mode eq TBDB_STATS_START) {
DBQueryWarn("update projects set ".
" expt_last=now(),expt_count=expt_count+1 ".
"where pid_idx='$pid_idx'");
}
$self->Refresh();
return 0;
}
#
# Bump last activity
#
sub BumpActivity($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $pid_idx = $self->pid_idx();
DBQueryWarn("update project_stats set last_activity=now() ".
"where pid_idx='$pid_idx'");
return 0;
}
# _Always_ make sure that this 1 is at the end of the file... # _Always_ make sure that this 1 is at the end of the file...
1; 1;
...@@ -24,6 +24,7 @@ use overload ('""' => 'Stringify'); ...@@ -24,6 +24,7 @@ use overload ('""' => 'Stringify');
use Project; use Project;
use vars qw($NEWUSER_FLAGS_PROJLEADER $NEWUSER_FLAGS_WIKIONLY use vars qw($NEWUSER_FLAGS_PROJLEADER $NEWUSER_FLAGS_WIKIONLY
$NEWUSER_FLAGS_WEBONLY $NEWUSER_FLAGS_ARCHIVED $NEWUSER_FLAGS_WEBONLY $NEWUSER_FLAGS_ARCHIVED
$NEWUSER_FLAGS_NOUUID
$USERSTATUS_ACTIVE $USERSTATUS_FROZEN $USERSTATUS_ACTIVE $USERSTATUS_FROZEN
$USERSTATUS_UNAPPROVED $USERSTATUS_UNVERIFIED $USERSTATUS_UNAPPROVED $USERSTATUS_UNVERIFIED
$USERSTATUS_NEWUSER $USERSTATUS_ARCHIVED $USERSTATUS_NEWUSER $USERSTATUS_ARCHIVED
...@@ -48,6 +49,7 @@ $NEWUSER_FLAGS_PROJLEADER = 0x01; ...@@ -48,6 +49,7 @@ $NEWUSER_FLAGS_PROJLEADER = 0x01;
$NEWUSER_FLAGS_WIKIONLY = 0x02; $NEWUSER_FLAGS_WIKIONLY = 0x02;
$NEWUSER_FLAGS_WEBONLY = 0x04; $NEWUSER_FLAGS_WEBONLY = 0x04;
$NEWUSER_FLAGS_ARCHIVED = 0x08; $NEWUSER_FLAGS_ARCHIVED = 0x08;
$NEWUSER_FLAGS_NOUUID = 0x80;
# Status values. # Status values.
$USERSTATUS_ACTIVE = "active"; $USERSTATUS_ACTIVE = "active";
...@@ -60,6 +62,7 @@ $USERSTATUS_ARCHIVED = "archived"; ...@@ -60,6 +62,7 @@ $USERSTATUS_ARCHIVED = "archived";
# Why, why, why? # Why, why, why?
@EXPORT_OK = qw($NEWUSER_FLAGS_PROJLEADER $NEWUSER_FLAGS_WIKIONLY @EXPORT_OK = qw($NEWUSER_FLAGS_PROJLEADER $NEWUSER_FLAGS_WIKIONLY
$NEWUSER_FLAGS_WEBONLY $NEWUSER_FLAGS_ARCHIVED $NEWUSER_FLAGS_WEBONLY $NEWUSER_FLAGS_ARCHIVED
$NEWUSER_FLAGS_NOUUID
$USERSTATUS_ACTIVE $USERSTATUS_FROZEN $USERSTATUS_ACTIVE $USERSTATUS_FROZEN
$USERSTATUS_UNAPPROVED $USERSTATUS_UNVERIFIED $USERSTATUS_UNAPPROVED $USERSTATUS_UNVERIFIED
$USERSTATUS_NEWUSER $USERSTATUS_ARCHIVED); $USERSTATUS_NEWUSER $USERSTATUS_ARCHIVED);
...@@ -263,11 +266,13 @@ sub LookupByEmail($$) ...@@ -263,11 +266,13 @@ sub LookupByEmail($$)
sub Create($$$$) sub Create($$$$)
{ {
my ($class, $uid, $flags, $argref) = @_; my ($class, $uid, $flags, $argref) = @_;
my $uuid;
my $isleader = ($flags & $NEWUSER_FLAGS_PROJLEADER ? 1 : 0); my $isleader = ($flags & $NEWUSER_FLAGS_PROJLEADER ? 1 : 0);
my $wikionly = ($flags & $NEWUSER_FLAGS_WIKIONLY ? 1 : 0); my $wikionly = ($flags & $NEWUSER_FLAGS_WIKIONLY ? 1 : 0);
my $webonly = ($flags & $NEWUSER_FLAGS_WEBONLY ? 1 : 0); my $webonly = ($flags & $NEWUSER_FLAGS_WEBONLY ? 1 : 0);
my $archived = ($flags & $NEWUSER_FLAGS_ARCHIVED ? 1 : 0); my $archived = ($flags & $NEWUSER_FLAGS_ARCHIVED ? 1 : 0);
my $nouuid = ($flags & $NEWUSER_FLAGS_NOUUID ? 1 : 0);
# #
# If no uid, we need to generate a unique one for the user. # If no uid, we need to generate a unique one for the user.
...@@ -406,11 +411,14 @@ sub Create($$$$) ...@@ -406,11 +411,14 @@ sub Create($$$$)
# And a verification key. # And a verification key.
my $verify_key = TBGenSecretKey(); my $verify_key = TBGenSecretKey();
# And a UUID (universally unique identifier). if (! $nouuid) {
my $uuid = NewUUID(); # And a UUID (universally unique identifier).
if (!defined($uuid)) { $uuid = NewUUID();
print "*** WARNING: Could not generate a UUID!\n"; if (!defined($uuid)) {
return undef; print "*** WARNING: Could not generate a UUID!\n";
return undef;
}
push(@insert_data, "uid_uuid='$uuid'");
} }
# Now tack on other stuff we need. # Now tack on other stuff we need.
...@@ -424,7 +432,6 @@ sub Create($$$$) ...@@ -424,7 +432,6 @@ sub Create($$$$)
push(@insert_data, "unix_uid=$unix_uid"); push(@insert_data, "unix_uid=$unix_uid");
push(@insert_data, "mailman_password='$mailman_password'"); push(@insert_data, "mailman_password='$mailman_password'");
push(@insert_data, "verify_key='$verify_key'"); push(@insert_data, "verify_key='$verify_key'");
push(@insert_data, "uid_uuid='$uuid'");
push(@insert_data, "uid_idx='$uid_idx'"); push(@insert_data, "uid_idx='$uid_idx'");
push(@insert_data, "uid='$uid'"); push(@insert_data, "uid='$uid'");
...@@ -448,8 +455,14 @@ sub Create($$$$) ...@@ -448,8 +455,14 @@ sub Create($$$$)
DBQueryWarn("insert into users set " . join(",", @insert_data)) DBQueryWarn("insert into users set " . join(",", @insert_data))
or return undef; or return undef;
if (! DBQueryWarn("insert into user_stats (uid, uid_idx, uid_uuid) ". # And the stats record.
"VALUES ('$uid', $uid_idx, '$uuid')")) { @insert_data = ();
push(@insert_data, "uid_idx='$uid_idx'");
push(@insert_data, "uid='$uid'");
push(@insert_data, "uid_uuid='$uuid'")
if (!$nouuid);
if (! DBQueryWarn("insert into user_stats set ".join(",", @insert_data))) {
DBQueryFatal("delete from users where uid_idx='$uid_idx'"); DBQueryFatal("delete from users where uid_idx='$uid_idx'");
return undef; return undef;
} }
...@@ -789,6 +802,54 @@ sub FlipTo($$) ...@@ -789,6 +802,54 @@ sub FlipTo($$)
return 0; return 0;
} }
#
# Update aggregate stats.
#
sub UpdateStats($$$$$)
{
my ($self, $mode, $duration, $pnodes, $vnodes) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $uid_idx = $self->uid_idx();
DBQueryWarn("update user_stats ".
"set expt${mode}_count=expt${mode}_count+1, ".
" expt${mode}_last=now(), ".
" 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_idx='$uid_idx'");
$self->Refresh();
return 0;
}
#
# Bump last activity
#
sub BumpActivity($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $uid_idx = $self->uid_idx();
DBQueryWarn("update user_stats set last_activity=now() ".
"where uid_idx='$uid_idx'");
return 0;
}
# _Always_ make sure that this 1 is at the end of the file... # _Always_ make sure that this 1 is at the end of the file...
1; 1;
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2006 University of Utah and the Flux Group. # Copyright (c) 2000-2007 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -297,6 +297,37 @@ if ($query_result->numrows) { ...@@ -297,6 +297,37 @@ if ($query_result->numrows) {
print "\n"; print "\n";
} }
#
# Look for inconsistent resource records.
#
if (! ($query_result =
DBQueryWarn("select e.idx,r.idx,e.pid,e.eid,".
" e.expt_head_uid,UNIX_TIMESTAMP(r.swapin_time) ".
" from experiment_resources as r ".
"left join experiments as e on e.idx=r.exptidx ".
" where e.state='swapped' and swapin_time!=0 and ".
" swapout_time=0 and swapmod_time=0 and pnodes>0"))){
fatal("Error accessing the database.");
}
if ($query_result->numrows) {
print "\n";
print "----------------------------------------------------------------\n";
print "\n";
print "Experiments with inconsistent experiment_resource records:\n";
printf("%-12s %-12s %-8s %-12s %-22s %s\n",
"PID", "EID", "IDX", "Creator", "Started", "RIDX");
print "------------ ------------ -------- ------------ ------------ ".
"---------------------- -------\n";
while (my ($exptidx,$idx,$pid,$eid,$creator,$swapin_time) =
$query_result->fetchrow()) {
printf("%-12s %-12s %-8s %-12s %-22s %s\n",
$pid, $eid, $exptidx, $creator, $swapin_time, $idx);
}
}
# #
# Age any login entries that have timed out. # Age any login entries that have timed out.
# #
......
This diff is collapsed.
...@@ -516,6 +516,12 @@ CREATE TABLE `experiment_resources` ( ...@@ -516,6 +516,12 @@ CREATE TABLE `experiment_resources` (
`exptidx` int(10) unsigned NOT NULL default '0', `exptidx` int(10) unsigned NOT NULL default '0',
`lastidx` int(10) unsigned default NULL, `lastidx` int(10) unsigned default NULL,
`tstamp` datetime default NULL, `tstamp` datetime default NULL,
`uid_idx` mediumint(8) unsigned NOT NULL default '0',
`swapin_time` int(10) unsigned NOT NULL default '0',
`swapout_time` int(10) unsigned NOT NULL default '0',
`swapmod_time` int(10) unsigned NOT NULL default '0',
`byswapmod` tinyint(1) unsigned default '0',
`byswapin` tinyint(1) unsigned default '0',
`vnodes` smallint(5) unsigned default '0', `vnodes` smallint(5) unsigned default '0',
`pnodes` smallint(5) unsigned default '0', `pnodes` smallint(5) unsigned default '0',
`wanodes` smallint(5) unsigned default '0', `wanodes` smallint(5) unsigned default '0',
......
...@@ -4067,3 +4067,23 @@ last_net_act,last_cpu_act,last_ext_act); ...@@ -4067,3 +4067,23 @@ last_net_act,last_cpu_act,last_ext_act);
PRIMARY KEY (`node_id`) PRIMARY KEY (`node_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
4.123: Improvements to stats gathering code for experiments.
alter table experiment_resources
add `uid_idx` mediumint(8) unsigned NOT NULL default '0'
after tstamp,
add `swapin_time` int(10) unsigned NOT NULL default '0'
after uid_idx,
add `swapout_time` int(10) unsigned NOT NULL default '0'
after swapin_time,
add `swapmod_time` int(10) unsigned NOT NULL default '0'
after swapout_time,
add `byswapmod` tinyint(1) unsigned default '0'
after swapmod_time;
add `byswapin` tinyint(1) unsigned default '0'
after byswapmod;
The run the following script. It is better if the testbed is
not in use at the time!
./resources.pl
This diff is collapsed.
...@@ -485,12 +485,12 @@ if (system("$parser -n $zeeopt $pid $gid $eid $nsfile") != 0) { ...@@ -485,12 +485,12 @@ if (system("$parser -n $zeeopt $pid $gid $eid $nsfile") != 0) {
# Gather statistics; start the clock ticking. # Gather statistics; start the clock ticking.
# #
if ($frontend || $batchmode) { if ($frontend || $batchmode) {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_PRELOAD, 0, $experiment->PreSwap($this_user, TBDB_STATS_PRELOAD) == 0 or
TBDB_STATS_FLAGS_START); fatal("Preswap failed!");
} }
else { else {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_START, 0, $experiment->PreSwap($this_user, TBDB_STATS_START) == 0 or
TBDB_STATS_FLAGS_START); fatal("Preswap failed!");
} }
goto skiplog goto skiplog
...@@ -625,7 +625,7 @@ if (! ($frontend || $batchmode)) { ...@@ -625,7 +625,7 @@ if (! ($frontend || $batchmode)) {
$experiment->SetState(EXPTSTATE_ACTIVATING) == 0 $experiment->SetState(EXPTSTATE_ACTIVATING) == 0
or fatal("Failed to set experiment state to ". EXPTSTATE_ACTIVATING()); or fatal("Failed to set experiment state to ". EXPTSTATE_ACTIVATING());
if ($experiment->Swap("in") != 0) { if ($experiment->Swap($Experiment::EXPT_SWAPIN) != 0) {
$errorstat = $? >> 8; $errorstat = $? >> 8;
fatal({type => 'secondary', severity => SEV_SECONDARY, fatal({type => 'secondary', severity => SEV_SECONDARY,
error => ['tbswap_in_failed']}, error => ['tbswap_in_failed']},
...@@ -701,13 +701,16 @@ if (! defined($template)) { ...@@ -701,13 +701,16 @@ if (! defined($template)) {
} }
# #
# Gather statistics. # Gather statistics. This is not likely to fail, but if it does I want to
# bail cause the inconsistent records are a pain in the ass to deal with!
# #
if ($frontend || $batchmode) { if ($frontend || $batchmode) {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_PRELOAD, 0); $experiment->PostSwap($this_user, TBDB_STATS_PRELOAD) == 0 or
fatal("Postswap failed!");
} }
else { else {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_START, 0); $experiment->PostSwap($this_user, TBDB_STATS_START) == 0 or
fatal("Postswap failed!");
} }
# #
...@@ -827,12 +830,11 @@ sub cleanup() ...@@ -827,12 +830,11 @@ sub cleanup()
# Gather statistics. # Gather statistics.
# #
if ($frontend) { if ($frontend) {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_PRELOAD, $errorstat); $experiment->SwapFail($this_user, TBDB_STATS_PRELOAD, $errorstat);
} }
else { else {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_START, $errorstat); $experiment->SwapFail($this_user, TBDB_STATS_START, $errorstat);
} }
$experiment->Refresh();
# #
# Must clean up the experiment if it made it our of NEW state. # Must clean up the experiment if it made it our of NEW state.
...@@ -858,10 +860,8 @@ sub cleanup() ...@@ -858,10 +860,8 @@ sub cleanup()
} }
$experiment->SetState(EXPTSTATE_TERMINATED); $experiment->SetState(EXPTSTATE_TERMINATED);
# # Old swap gathering stuff.
# Okay, we *are* going to terminate the experiment. $experiment->GatherSwapStats($this_user, TBDB_STATS_TERMINATE, 0);
#
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_TERMINATE, 0);
# Clear the logfile so the webpage stops. # Clear the logfile so the webpage stops.
$experiment->CloseLogFile(); $experiment->CloseLogFile();
......
...@@ -426,33 +426,32 @@ if ($waitmode) { ...@@ -426,33 +426,32 @@ if ($waitmode) {
# Sanity check states in case someone changes something. # Sanity check states in case someone changes something.
# #
if ($estate eq EXPTSTATE_ACTIVE) { if ($estate eq EXPTSTATE_ACTIVE) {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPOUT, 0, $experiment->PreSwap($this_user, TBDB_STATS_SWAPOUT) == 0 or
TBDB_STATS_FLAGS_START); fatal("Preswap failed!");
if ($experiment->Swap("out") != 0) { if ($experiment->Swap($Experiment::EXPT_SWAPOUT) != 0) {
fatal({type => 'secondary', severity => SEV_SECONDARY, fatal({type => 'secondary', severity => SEV_SECONDARY,
error => ['tbswap_out_failed']}, error => ['tbswap_out_failed']},
"tbswap out failed!"); "tbswap out failed!");
} }
$experiment->PostSwap($this_user, TBDB_STATS_SWAPOUT) == 0 or
fatal("PostSwap failed!");
$experiment->SetState(EXPTSTATE_TERMINATING) == 0 $experiment->SetState(EXPTSTATE_TERMINATING) == 0
or fatal("Failed to set experiment state to " . or fatal("Failed to set experiment state to " .
EXPTSTATE_TERMINATING()); EXPTSTATE_TERMINATING());
$estate = EXPTSTATE_SWAPPED; $estate = EXPTSTATE_SWAPPED;
#
# Gather statistics for the swapout.
#
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPOUT, 0);
# Commit the archive after swapout. Easier to use the script. # Commit the archive after swapout. Easier to use the script.
system("$archcontrol -t endexp commit $pid $eid"); system("$archcontrol -t endexp commit $pid $eid");
} }
if ($estate eq EXPTSTATE_SWAPPED || if ($estate eq EXPTSTATE_SWAPPED ||
$estate eq EXPTSTATE_QUEUED) { $estate eq EXPTSTATE_QUEUED) {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_TERMINATE, 0, $experiment->GatherSwapStats($this_user, TBDB_STATS_TERMINATE, 0,
TBDB_STATS_FLAGS_START); TBDB_STATS_FLAGS_START)
== 0 or fatal("GatherSwapStats failed");
if ($experiment->End() != 0) { if ($experiment->End() != 0) {
fatal("tbend failed!\n"); fatal("tbend failed!\n");
...@@ -465,7 +464,8 @@ if ($estate eq EXPTSTATE_SWAPPED || ...@@ -465,7 +464,8 @@ if ($estate eq EXPTSTATE_SWAPPED ||
# #
# Gather statistics for the swapout. # Gather statistics for the swapout.
# #
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_TERMINATE, 0); $experiment->GatherSwapStats($this_user, TBDB_STATS_TERMINATE)
== 0 or fatal("GatherSwapStats failed");
} }
# We better be here ... # We better be here ...
......
...@@ -874,16 +874,16 @@ $SIG{QUIT} = 'DEFAULT'; ...@@ -874,16 +874,16 @@ $SIG{QUIT} = 'DEFAULT';
# Gather stats; start clock ticking # Gather stats; start clock ticking
# #
if ($inout eq "in") { if ($inout eq "in") {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPIN, 0, $experiment->PreSwap($this_user, TBDB_STATS_SWAPIN) == 0 or
TBDB_STATS_FLAGS_START); fatal("Preswap failed!");
} }
elsif ($inout eq "out") { elsif ($inout eq "out") {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPOUT, 0, $experiment->PreSwap($this_user, TBDB_STATS_SWAPOUT) == 0 or
TBDB_STATS_FLAGS_START); fatal("Preswap failed!");
} }
elsif ($inout eq "modify") { elsif ($inout eq "modify") {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPMODIFY, 0, $experiment->PreSwap($this_user, TBDB_STATS_SWAPMODIFY) == 0 or
TBDB_STATS_FLAGS_START); fatal("Preswap failed!");
} }
# #
...@@ -899,7 +899,7 @@ if ($inout ne "restart" && -e $repfile) { ...@@ -899,7 +899,7 @@ if ($inout ne "restart" && -e $repfile) {
if ($inout eq "out") { if ($inout eq "out") {
my $optarg = (($force || $idleswap) ? "-force" : ""); my $optarg = (($force || $idleswap) ? "-force" : "");
if ($experiment->Swap("out", $optarg) != 0) { if ($experiment->Swap($Experiment::EXPT_SWAPOUT, $optarg) != 0) {
$errorstat = $? >> 8; $errorstat = $? >> 8;
fatal({type => 'secondary', severity => SEV_SECONDARY, fatal({type => 'secondary', severity => SEV_SECONDARY,
error => ['tbswap_out_failed']}, error => ['tbswap_out_failed']},
...@@ -937,14 +937,11 @@ if ($inout eq "out") { ...@@ -937,14 +937,11 @@ if ($inout eq "out") {
or fatal("Failed to clear the panic bit!"); or fatal("Failed to clear the panic bit!");
} }
elsif ($inout eq "in") { elsif ($inout eq "in") {
GatherSwapStats($pid, $eid, $user_uid,
TBDB_STATS_SWAPIN, 0, TBDB_STATS_FLAGS_PRESWAPIN);
# Set the swapper now so that nodes use the proper uid. If the swapin # Set the swapper now so that nodes use the proper uid. If the swapin
# fails, we leave the swapper as is, since its harmless and informative. # fails, we leave the swapper as is, since its harmless and informative.
$experiment->SetSwapper($this_user); $experiment->SetSwapper($this_user);
if ($experiment->Swap("in") != 0) { if ($experiment->Swap($Experiment::EXPT_SWAPIN) != 0) {
$errorstat = $? >> 8; $errorstat = $? >> 8;
fatal({type => 'secondary', severity => SEV_SECONDARY, fatal({type => 'secondary', severity => SEV_SECONDARY,
error => ['tbswap_in_failed']}, error => ['tbswap_in_failed']},
...@@ -969,9 +966,6 @@ elsif ($inout eq "modify") { ...@@ -969,9 +966,6 @@ elsif ($inout eq "modify") {
} }
} }
GatherSwapStats($pid, $eid, $user_uid,
TBDB_STATS_SWAPMODIFY, 0, TBDB_STATS_FLAGS_PREMODIFY);
# Gather up some firewall state for later comparison. # Gather up some firewall state for later comparison.
if (GatherFWinfo() < 0) { if (GatherFWinfo() < 0) {
fatal("Could not gather firewall info; cannot safely continue!"); fatal("Could not gather firewall info; cannot safely continue!");
...@@ -1053,7 +1047,7 @@ elsif ($inout eq "modify") { ...@@ -1053,7 +1047,7 @@ elsif ($inout eq "modify") {
$optarg .= ($eventsys_restart ? " -eventsys_restart" : ""); $optarg .= ($eventsys_restart ? " -eventsys_restart" : "");
} }
if ($experiment->Swap("update", $optarg) == 0) { if ($experiment->Swap($Experiment::EXPT_SWAPMOD, $optarg) == 0) {
# #
# Success. Set the state back to active cause thats where it # Success. Set the state back to active cause thats where it
# started. # started.
...@@ -1201,14 +1195,17 @@ if (!$template_mode) { ...@@ -1201,14 +1195,17 @@ if (!$template_mode) {
# Gather stats. # Gather stats.
# #
if ($inout eq "in") { if ($inout eq "in") {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPIN, 0); $experiment->PostSwap($this_user, TBDB_STATS_SWAPIN) == 0 or
fatal("PostSwap failed!");
} }
elsif ($inout eq "out") { elsif ($inout eq "out") {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPOUT, 0, $experiment->PostSwap($this_user, TBDB_STATS_SWAPOUT,
($idleswap ? TBDB_STATS_FLAGS_IDLESWAP() : 0)); ($idleswap ? TBDB_STATS_FLAGS_IDLESWAP() :0)) == 0 or
fatal("PostSwap failed!");
} }
elsif ($inout eq "modify") { elsif ($inout eq "modify") {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPMODIFY, 0); $experiment->PostSwap($this_user, TBDB_STATS_SWAPMODIFY) == 0 or
fatal("PostSwap failed!");
} }
# Accounting info. For swapout, must be after its done with. # Accounting info. For swapout, must be after its done with.
...@@ -1296,7 +1293,7 @@ sub cleanup() ...@@ -1296,7 +1293,7 @@ sub cleanup()
# Gather stats. # Gather stats.
# #
if ($inout eq "in") { if ($inout eq "in") {
GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPIN, $errorstat); $experiment->SwapFail($this_user, TBDB_STATS_SWAPIN, $errorstat);
# #
# Must clean up the experiment if it managed to swap in. # Must clean up the experiment if it managed to swap in.
...@@ -1304,13 +1301,13 @@ sub cleanup() ...@@ -1304,13 +1301,13 @@ sub cleanup()
$estate = $experiment->state(); $estate = $experiment->state();
if ($estate eq EXPTSTATE_ACTIVE) { if ($estate eq EXPTSTATE_ACTIVE) {
if ($experiment->Swap("out", "-force") != 0) { if ($experiment->Swap($Experiment::EXPT_SWAPOUT, "-force") != 0) {
print "tbswap out failed!\n"; print "tbswap out failed!\n";
} }
}