-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttyinfo
executable file
·118 lines (105 loc) · 2.67 KB
/
ttyinfo
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
#!/usr/bin/perl
use strict;
use warnings;
use Term::TtyRec::Plus;
my $concat = 0;
@ARGV = grep {$_ eq "-c" ? do {$concat = 1; 0} : 1} @ARGV;
sub serialize
{
my $seconds = int shift;
my $hours = int($seconds / 3600);
$seconds %= 3600;
my $minutes = int($seconds / 60);
$seconds %= 60;
return sprintf '%02d:%02d:%02d', $hours, $minutes, $seconds;
}
my $total_time = 0;
my $thresh10_time = 0;
my $thresh3_time = 0;
my $thresh10_trunc = 0;
my $thresh3_trunc = 0;
my $frame = 0;
my $data_length = 0;
my $longest_time = 0;
my $start = '';
my $end = '';
sub ttyinfo
{
my $filename = shift;
my $concat = shift;
my $ttp = new Term::TtyRec::Plus(infile => $filename);
if (not $concat)
{
$total_time = 0;
$thresh10_time = 0;
$thresh3_time = 0;
$thresh10_trunc = 0;
$thresh3_trunc = 0;
$frame = 0;
$data_length = 0;
$longest_time = 0;
$start = '';
$end = '';
}
while (my $frame_ref = $ttp->next_frame())
{
++$frame;
$start = $frame_ref->{timestamp} if $frame == 1;
$end = $frame_ref->{timestamp};
$total_time += $frame_ref->{diff};
$longest_time = $frame_ref->{diff} if $frame_ref->{diff} > $longest_time;
for ([10, \$thresh10_trunc, \$thresh10_time],
[3, \$thresh3_trunc, \$thresh3_time])
{
if ($frame_ref->{diff} > $_->[0])
{
$frame_ref->{diff} = $_->[0];
++${$_->[1]};
}
${$_->[2]} += $frame_ref->{diff};
}
$data_length += length $frame_ref->{data};
}
return "No frames in file '$filename'\n" if $frame == 0;
my $format = << "EOH";
File: %s
Frames: %d
Begin: %s
End: %s
Time: %s (%fs)
T10 time: %s (%fs) (%dt)
T3 time: %s (%fs) (%dt)
Data length: %d bytes
Total length: %d bytes
Longest time: %s (%fs)
Avg time: %s (%fs)
Avg T10 time: %s (%fs)
Avg T3 time: %s (%fs)
Avg data len: %f bytes
EOH
return sprintf $format,
$filename,
$frame,
scalar localtime($start),
scalar localtime($end),
serialize($total_time), $total_time,
serialize($thresh10_time), $thresh10_time, $thresh10_trunc,
serialize($thresh3_time), $thresh3_time, $thresh3_trunc,
$data_length,
$data_length + 12*$frame,
serialize($longest_time), $longest_time,
serialize($total_time/$frame), $total_time/$frame,
serialize($thresh10_time/$frame), $thresh10_time/$frame,
serialize($thresh3_time/$frame), $thresh10_time/$frame,
$data_length/$frame,
}
my @output = map {ttyinfo($_, $concat)} @ARGV;
if ($concat)
{
$output[-1] =~ s/File:.+\n//;
print $output[-1];
}
else
{
print join "---\n", @output;
}