forked from detailyang/systemtap-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio-process-top
executable file
·86 lines (63 loc) · 1.5 KB
/
io-process-top
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
#! /usr/bin/env perl
# Copyright (C) YangBingwu (detailyang)
use 5.0006001;
use strict;
use warnings;
use Getopt::Std qw ( getopts );
sub usage();
my %opts;
getopts("ha:dt:", \%opts) or die usage();
if ($opts{h}) {
print usage;
exit;
}
my $stap_args = $opts{a} || "";
my $time = $opts{t} || 5000;
my $stap_src = <<_EOC_;
global r%, w%, io%
probe begin {
warn("Collecting IO Process Top 10 with interval of ${time}ms")
}
probe vfs.write.return {
w[execname(), pid()] += bytes_written
}
probe vfs.read.return {
r[execname(), pid()] += bytes_read
}
probe timer.ms($time) {
printf("%20s%6s\t%10s\t%10s\\n", "Process Name", "", "Read(KB)", "Write(KB)")
foreach ([name, pid] in w) {
io[name, pid] += w[name, pid]
}
foreach ([name, pid] in r) {
io[name, pid] += r[name, pid]
}
foreach([name, pid] in io- limit 10) {
printf("%20s(%-6d)\t%10d\t%10d\\n", name, pid, r[name, pid]/1024, w[name, pid]/1024)
}
delete r
delete w
delete io
print("\\n")
}
_EOC_
if ($opts{d}) {
print $stap_src;
exit;
}
open my $in, "| stap $stap_args --skip-badvars -";
print $in $stap_src;
close $in;
sub usage() {
return <<'_EOC_';
Usage:
io-process-top [optoins]
Options:
-a <args> Pass extra arguments to the stap utility.
-d Dump out the systemtap script source.
-h Print this usage.
-t <time>(ms) Specify the interval time to sampling.
Examples:
io-process-top
_EOC_
}