#!/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 systat interval argument"); &ttt_add_opt("p4descint", "[^\\d+\\\$]", 120, "p4 describe interval"); &ttt_add_opt("user", "[^]", "$user", "user to run as"); &ttt_add_opt("srv_host", "[[a-z-]+]", "p4netapp", "host to run p4 server on"); &ttt_add_opt("cli_host", "[[a-z-]+]", "localhost", "host to run p4 clients on"); } 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, $user, "vmstat"); $rbits = $rbits | $agents{$vmstat_id,"STDOUTt"} | $agents{$vmstat_id,"STDERRt"}; if ($sysstatint > 0) { $sysstat_id = &ttt_start_agent($srv_host, "rsh powermatic sysstat -x $sysstatint", 1, $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) { &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 "p4desc") { $arm_p4wd = 0; if (&mark_time("done p4 describe") > $p4wdthresh && ! $p4wd_running) { &ttt_msg("retrip", "do p4wd after probe completion\n"); $p4wd_id = &ttt_start_agent($srv_host, "p4wd 1000; top", 1, $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 == $p4desc_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 1000; top", 1, $user, "p4wd"); $rbits = $rbits | $agents{$p4wd_id,"STDOUTt"} | $agents{$p4wd_id,"STDERRt"}; $p4wd_running = 1; } if ($last_time >= 0 && ((time - $last_time) > $p4descint)) { $p4desc_id = &ttt_start_agent($cli_host, "p4 nc -s describe 90001", 1, $user, "p4desc"); &mark_time("start p4 describe", "start"); $rbits = $rbits | $agents{$p4desc_id,"STDOUTt"} | $agents{$p4desc_id,"STDERRt"}; $last_time = -1; $arm_p4wd = 1; } }