#!/usr/local/bin/perl
# -*-Fundamental-*-
#
# Copyright (c) 1996 Network Appliance, Inc.
#
# You may distribute under the terms of the Artistic License, as
# specified in the README file included in the ttt distribution.
#
# $Id: //depot/tools/main/p4bench/p4watch#2 $
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );
my $t0;
sub mark_time
{
my($msg, $init) = @_;
if ($init eq "start")
{
&ttt_msg("mark_st", "$msg\n");
$t0 = [gettimeofday];
return;
}
$e = tv_interval ($t0);
my @t1 = times;
my $times = sprintf "%8.2f seconds", $e;
&ttt_msg("mark_tm", "$times : $msg\n");
$t0 = [gettimeofday];
@t0 = @t1;
return $e;
}
sub opts
{
&ttt_add_opt("p4wdthresh", "^\\\\d+\\\$", 5, "threshold above which to run p4wd");
&ttt_add_opt("vmstatint", "^\\\\d+\\\$", 10, "vmstat interval argument");
&ttt_add_opt("sysstatint", "^\\\\d+\\\$", 10, "filer sysstat interval argument");
&ttt_add_opt("p4cmd", ".*", "p4 describe 1", "the short running p4 command to run as a probe");
&ttt_add_opt("p4wd", ".*", "p4wd", "the p4wd command to execute");
&ttt_add_opt("p4cmdint", "^\\\\d+\\\$", 120, "p4 describe interval");
&ttt_add_opt("srv_host", "^", "localhost", "host p4d is running on");
&ttt_add_opt("srv_port", "^\\\\d+\\\$", "1666", "port p4d is listening on");
&ttt_add_opt("srv_user", "^", "$user", "user to run as on srv_host");
&ttt_add_opt("cli_host", "^", "localhost", "host to run p4cmd probes on");
&ttt_add_opt("cli_user", "^", "$user", "user to run as on cli_host");
&ttt_add_opt("filer", "^", "filer", "the hostname of the filer");
&ttt_add_opt("filer_user", "^", "$user", "user to run as on the filer");
}
sub prereqchk { 1; }
##### Begin ttt standard preamble - do not change this code! #####
$UNIX = 1;
sub dirname
{ local($dir) = @_; $dir =~ s%^$%.%; $dir = "$dir/";
if ($dir =~ m"^/[^/]*//*$") { return "/"; }
if ($dir =~ m"^.*[^/]//*[^/][^/]*//*$")
{ $dir =~ s"^(.*[^/])//*[^/][^/]*//*$"$1"; { return $dir; } } #" [for cpp]
return "."; }
$ttt_here = `/bin/pwd`; chop $ttt_here; chdir &dirname($0);
$tttroot = `/bin/pwd`; chop $tttroot; chdir $ttt_here;
require "$tttroot/tttLib.pl";
##### End ttt standard preamble - do not change the above code! #####
&ttt_rexec($srv_host, "uname -a");
&ttt_rexec($cli_host, "uname -a");
#===== record configuration information for posterity
&ttt_msg("config", "srv_host $srv_host\n");
&ttt_msg("config", "cli_host $cli_host\n");
#===== loopy
$vmstat_id = &ttt_start_agent($srv_host, "vmstat $vmstatint", 1, $srv_user, "vmstat");
$rbits = $rbits | $agents{$vmstat_id,"STDOUTt"} | $agents{$vmstat_id,"STDERRt"};
if ($sysstatint > 0)
{
$sysstat_id = &ttt_start_agent($srv_host, "rsh -l $filer_user $filer sysstat -x $sysstatint", 1, $srv_user, "sysstat");
$rbits = $rbits | $agents{$sysstat_id,"STDOUTt"} | $agents{$sysstat_id,"STDERRt"};
}
$last_time = 0;
$p4wd_running;
while (1)
{
($line,$agentid,$stream) = &ttt_readline_agents($rbits, 1);
if (defined ($line))
{
if ($line)
{
if ($agentid == $vmstat_id
|| $agentid == $sysstat_id
|| $line =~ /^exit: /
|| $agentid == $p4wd_id
# || $agentid == $p4cmd_id
)
{ &ttt_msg($agents{$agentid,"name"}, "$stream: $line"); }
}
}
else
{
$rbits = $rbits ^ $agents{$agentid, $stream."t"};
&ttt_msg($agents{$agentid,"name"}, "$stream: EOF\n");
if (! (vec($rbits, $agents{$agentid, "STDERRf"}, 1) || vec($rbits, $agents{$agentid, "STDOUTf"}, 1)))
{
my $name = $agents{$agentid,"name"};
if ($name eq "p4cmd")
{
$arm_p4wd = 0;
if (&mark_time("done $p4cmd") > $p4wdthresh && ! $p4wd_running)
{
&ttt_msg("retrip", "do p4wd after probe completion\n");
$p4wd_id = &ttt_start_agent($srv_host, $p4wd, 1, $srv_user, "p4wd");
$rbits = $rbits | $agents{$p4wd_id,"STDOUTt"} | $agents{$p4wd_id,"STDERRt"};
$p4wd_running = 1;
}
}
elsif ($name eq "p4wd")
{ $p4wd_running = 0; }
$status = &ttt_close_agent($agentid);
&ttt_msg($name, "exit status = $status\n");
if ($agentid == $p4cmd_id) { $last_time = time; }
}
}
$e = tv_interval ($t0);
if ($arm_p4wd && $last_time == -1 && ($e > $p4wdthresh) && ! $p4wd_running)
{
$arm_p4wd = 0;
&ttt_msg("trip", "do p4wd after waiting $e seconds\n");
$p4wd_id = &ttt_start_agent($srv_host, $p4wd, 1, $srv_user, "p4wd");
$rbits = $rbits | $agents{$p4wd_id,"STDOUTt"} | $agents{$p4wd_id,"STDERRt"};
$p4wd_running = 1;
}
if ($last_time >= 0 && ((time - $last_time) > $p4cmdint))
{
$p4cmd_id = &ttt_start_agent($cli_host, "p4 -p $srv_host:$srv_port $p4cmd", 1, $cli_user, "p4cmd");
&mark_time("start $p4cmd", "start");
$rbits = $rbits | $agents{$p4cmd_id,"STDOUTt"} | $agents{$p4cmd_id,"STDERRt"};
$last_time = -1;
$arm_p4wd = 1;
}
}
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #3 | 897 | Richard Geiger | Another increment towards making this plausible usable elsewhere | ||
| #2 | 895 | Richard Geiger |
Mainly these changes are for "genericizing" p4watch bit, on the road to making it generally useful. |
||
| #1 | 799 | Richard Geiger |
The first version of "p4bench", scripts used to implement a crude Perforce benchmarking system, as mentioned in http://maillist.perforce.com/pipermail/perforce-user/2001-February/005288.html Beware, it's not pretty and there's no documentation, but it's a starting point for bigger and better things. |