-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess-sar-W
executable file
·102 lines (84 loc) · 1.94 KB
/
process-sar-W
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
#!/usr/bin/perl -w
#
# 03:35:01 PM pswpin/s pswpout/s
# 03:45:01 PM 61.31 52.17
# 03:55:01 PM 14.89 0.00
# 04:05:01 PM 9.87 0.00
# Average: 733.72 215.86
#
use strict;
my %collapsed;
my $headerlines = 3;
sub remember_stack {
my ($stack, $count) = @_;
$collapsed{$stack} += $count;
}
my $nr = 0;
my @stack;
my $snap = 5 ;
my $last = 0;
my $count = 0;
my $total_count = 0;
my $unfinished = 0 ;
my %completed ;
my $min_time = 0;
my $max_time = 0;
my $time = 0;
my @flags = qw ();
my $flag ;
while (<>) {
chomp ;
next if /Average/;
($time) = /^([\d\.]+)\s/ ;
if ( /Flags \[([SFRP\.]+)\]/ ) {
if ($1 eq 'S') {
$flag = 'SYN';
} elsif ($1 eq 'S.') {
$flag = 'SYN-ACK';
} elsif ($1 eq 'F.') {
$flag = 'FIN';
} else {
next;
}
} else {
die ("unexpected flag at $_");
}
# printf("debug: %d %s\n", $time, $flag);
$time = int($time / $snap) * $snap;
if ($time > $max_time) {
$max_time = $time;
}
if ($min_time == 0) {
$min_time = $time;
}
$completed{$time}{$flag} ++ ;
=snip
if ($time ne $last) {
if ($last != 0) {
printf("%d %d\n", $time, $count);
$count = 1;
$last = $time;
} else {
$last = $time;
$count = 1;
}
} else {
$count ++ ;
}
=cut
}
printf("# parsed total %d syscalls, %d unfinished\n", $total_count, $unfinished);
printf("# time, date, %s\n", join(',',@flags));
for (my $idx = $min_time ; $idx < $max_time + $snap; $idx = $idx + $snap) {
if (!exists($completed{$idx})) {
printf("%s,%s,%s\n",
$idx, scalar gmtime($idx),
join(',', map { 0 } @flags));
next;
}
printf("%d,%s", $idx, scalar gmtime($idx));
foreach my $flag (@flags) {
printf(",%d", $completed{$idx}{$flag} || 0);
}
printf("\n");
}