-
Notifications
You must be signed in to change notification settings - Fork 25
/
hires_cxreport.pl
executable file
·130 lines (116 loc) · 3.89 KB
/
hires_cxreport.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl
package main;
if (defined $ENV{DEBUG}) {
use strict;
use warnings;
use diagnostics;
use Carp;
use Data::Dumper;
}
use Time::HiRes qw(usleep ualarm gettimeofday stat lstat utime);
#use Time::Format qw/%time/;
# use lib prepends to @INC, so put lower priority first
# This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts';
use lib "./";
use LANforge::Utils;
use Net::Telnet ();
use Getopt::Long;
our $quiet = 1;
my $report_filename = "/tmp/hires_report.txt";
my $duration_sec = 60;
my $cx = "rdtest";
our $lfmgr_host = 'localhost';
our $lfmgr_port = 4001;
$| = 1;
my $t = new Net::Telnet(Prompt => '/default\@btbits\>\>/',
Timeout => 60);
$t->open(Host => $::lfmgr_host,
Port => $::lfmgr_port,
Timeout => 10);
$t->max_buffer_length(16 * 1024 * 1000); # 16 MB buffer
$t->waitfor("/btbits\>\>/");
# Configure our utils.
our $utils = new LANforge::Utils();
$::utils->telnet($t); # Set our telnet object.
if ($::utils->isQuiet()) {
if (defined $ENV{'LOG_CLI'} && $ENV{'LOG_CLI'} ne "") {
$::utils->cli_send_silent(0);
}
else {
$::utils->cli_send_silent(1); # Do not show input to telnet
}
$::utils->cli_rcv_silent(1); # Repress output from telnet
}
else {
$::utils->cli_send_silent(0); # Show input to telnet
$::utils->cli_rcv_silent(0); # Show output from telnet
}
#$::utils->log_cli("# $0 ".`date "+%Y-%m-%d %H:%M:%S"`);
$SIG{'INT'} = sub {
$::utils->doCmd("set_cx_state all $cx STOPPED");
exit 0;
};
# start rdtest
my %times = ();
$times{gettimeofday().'_before_set_cx_state'} = gettimeofday() ." before_start_cx 0 0";
$::utils->doCmd("set_cx_report_timer all $cx 250");
$::utils->doCmd("set_cx_state all $cx RUNNING");
$times{gettimeofday().'_after_set_cx_state'} = gettimeofday() ." after_start_cx 0 0";
my $timelimit = $duration_sec + time();
my $show_cx_str = '';
my $lastline = '';
my $lasttime = 0;
my @hunks = ();
my $delta = 0;
my $tod = gettimeofday();
my $last_a = 0;
my $last_b = 0;
my $step_a = 0;
my $step_b = 0;
while ($tod < $timelimit) {
# the command below does not indicate last reported timestamp, skip it
# $show_cx_str = $::utils->doAsyncCmd("show_cxe all $cx");
# $times{gettimeofday()."_show_cxe"} = $show_cx_str;
$tod = gettimeofday();
$lastline=`tail -1 /home/lanforge/lf_reports/${cx}-A*`;
@hunks = split(',', $lastline);
$hunks[0] = $hunks[0]/1000 if ($hunks[0] > 0);
$last_a = $hunks[0] if ($last_a == 0);
if ($hunks[0] gt $last_a){
print "\nnew report A entry!\n";
$step_a = $hunks[0] - $last_a;
$last_a = $hunks[0];
$delta = $tod - $hunks[0];
$times{"${tod}_tail_csv-A"} = "$hunks[0] $hunks[1] $step_a $delta";
}
$lastline=`tail -1 /home/lanforge/lf_reports/${cx}-B*`;
@hunks = split(',', $lastline);
$hunks[0] = $hunks[0]/1000 if ($hunks[0] > 0);
$last_b = $hunks[0] if ($last_b == 0);
if ($hunks[0] gt $last_b) {
print "\nnew report B entry!\n";
$step_b = $hunks[0] - $last_b;
$last_b = $hunks[0];
$delta = $tod - $hunks[0];
$times{"${tod}_tail_csv-B"} = "$hunks[0] $hunks[1] $step_b $delta";
}
usleep(125);
if (time() gt $lasttime) {
print "\r".($timelimit - time())." sec remaining ";
$lasttime = time();
}
} #~while
$::utils->doCmd("set_cx_state all $cx STOPPED");
print "...collected.\n";
die unless open(my $fh, ">", $report_filename);
#print $fh "TimeKeyInput csv_record_tstampsecs endpoint sec_since_last_report seconds_lag_since_last_report\n";
print $fh "clock csv_tstamp_secs endpoint sec_btwn_reports tstamp_lag_sec\n";
foreach $key (sort {$a cmp $b} (keys %times)) {
my ($clock) = $key =~ m/^([^_]+)/;
@hunks = split(' ', $times{$key});
print$fh sprintf "%14.3f %15.3f %18s %20.3f %15.3f\n", 0.0+$clock, $hunks[0], $hunks[1], $hunks[2], $hunks[3];
}
close $fh;
print "View the report at $report_filename\n";
#eof