-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvfs_summary.stp
More file actions
executable file
·192 lines (175 loc) · 4.16 KB
/
Copy pathvfs_summary.stp
File metadata and controls
executable file
·192 lines (175 loc) · 4.16 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/stap -g
# This script summarizes filesystem and disk activity
%{
#include <linux/file.h>
%}
# init
global path_prefix;
global bio_times[8192];
global inum_times;
global filenames;
global vfs_br;
global vfs_bw;
global blk_br;
global blk_bw;
global inum_proc;
global fd_inum;
global count = 0;
global show_header = 1;
# let's do some checks up-front
probe begin {
if ($# != 1) {
printf("Specify a path component to monitor\n");
exit();
}
if (@1 == ".") {
path_prefix = "";
} else {
path_prefix = @1;
}
printf("Script running...\n");
}
# get inode number (if exists) from file descriptor
function __fd_inum:long(fd:long) %{ /* unprivileged */
struct file* file;
struct dentry* dentry;
struct inode* inode;
unsigned long inum;
THIS->__retvalue = 0;
file = fget(THIS->fd);
if (file) {
dentry = kread(&(file->f_dentry));
if (dentry) {
inode = kread(&(dentry->d_inode));
if (inode) {
THIS->__retvalue = kread(&(inode->i_ino));
}
}
}
CATCH_DEREF_FAULT();
%}
# anytime a file descriptor is dup'd, we need to update our tables
# to track the new FD
function dup_fixup(pid:long,old:long,new:long) {
fd_inum[pid,new] = fd_inum[pid,old];
delete fd_inum[pid,old];
}
probe syscall.dup.return {
old = $fildes;
new = returnval();
if (fd_inum[pid(),old]) {
dup_fixup(pid(), old, new);
}
}
probe syscall.dup2.return {
old = $oldfd;
new = $newfd;
if (fd_inum[pid(),old]) {
dup_fixup(pid(), old, new);
}
}
probe ioblock.request {
if ([ino] in filenames) {
bio_times[$bio] = gettimeofday_us();
if (BIO_READ == bio_rw_num(rw)) {
blk_br[ino] <<< size;
} else {
blk_bw[ino] <<< size;
}
}
}
probe ioblock.end {
if ([ino] in filenames) {
# collect the IO time for this inode
inum_times[ino] <<< (gettimeofday_us() - bio_times[$bio]);
delete bio_times[$bio];
}
}
probe syscall.open.return {
# only track filenames that the user asked for
filename = user_string($filename);
fd = returnval();
if (1 == isinstr(filename, path_prefix)) {
inum = __fd_inum(fd);
filenames[inum] = filename;
inum_proc[inum] = execname();
fd_inum[pid(),fd] = inum;
}
}
probe syscall.read.return, syscall.readv.return {
if ([pid(),$fd] in fd_inum) {
if (0 < returnval()) {
vfs_br[fd_inum[pid(),$fd]] <<< returnval();
}
}
}
probe syscall.write.return, syscall.writev.return {
if ([pid(),$fd] in fd_inum) {
if (0 < returnval()) {
vfs_bw[fd_inum[pid(),$fd]] <<< returnval();
}
}
}
probe syscall.sendfile.return {
if ([pid(),$in_fd] in fd_inum) {
if (0 < returnval()) {
vfs_br[fd_inum[pid(),$in_fd]] <<< returnval();
}
}
}
probe syscall.close.return {
delete fd_inum[pid(),$fd];
}
function b_to_kb(bytes:long) {
return bytes / 1024;
}
function us_to_ms(usec:long) {
return usec / 1000;
}
probe timer.s(1) {
if ((count % 10 == 0) && (show_header == 1)) {
if (count == 0) {
count++;
}
printf("\n");
printf("%6s %6s %6s %6s %6s %6s %4s\n",
"BIO_MS", "BIO_KR", "BIO_KW", "VFS_KR", "VFS_KW", "RD_HIT", "PATH");
printf("%6s %6s %6s %6s %6s %6s %s\n", "======", "======", "======",
"======", "======", "======", "======");
show_header = 0;
}
foreach ([inum] in filenames) {
sum_blk_br_inum = @sum(blk_br[inum]);
sum_blk_bw_inum = @sum(blk_bw[inum]);
sum_vfs_br_inum = @sum(vfs_br[inum]);
sum_vfs_bw_inum = @sum(vfs_bw[inum]);
# sometimes the bytes read from the block device are more than what
# was requested from VFS. this isn't an issue, but our calcs need to
# account for it.
if (sum_vfs_br_inum - sum_blk_br_inum < 0) {
cached_bytes = 0;
} else {
cached_bytes = sum_vfs_br_inum - sum_blk_br_inum;
}
cache_hit_ratio = 0;
if (sum_vfs_br_inum > 0) {
cache_hit_ratio = (200 * cached_bytes + 1) / (sum_vfs_br_inum * 2);
}
if (0 < sum_blk_br_inum + sum_blk_bw_inum +
sum_vfs_br_inum + sum_vfs_bw_inum) {
printf("%6d %6d %6d %6d %6d %6d %.38s\n",
us_to_ms(@sum(inum_times[inum])),
b_to_kb(sum_blk_br_inum), b_to_kb(sum_blk_bw_inum),
b_to_kb(sum_vfs_br_inum), b_to_kb(sum_vfs_bw_inum),
cache_hit_ratio,
filenames[inum]);
count++;
show_header = 1;
}
}
delete inum_times;
delete blk_br;
delete blk_bw;
delete vfs_br;
delete vfs_bw;
}