Skip to content

Commit 6640f82

Browse files
committed
Add curvefs-fuse-bt trace tool.
1 parent ed37e90 commit 6640f82

File tree

2 files changed

+278
-0
lines changed

2 files changed

+278
-0
lines changed

trace/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Usage
3+
---
4+
5+
6+
* [curvefs-fuse-bt](curvefs-fuse-bt)
7+
8+
```shell
9+
./curvefs-fuse-bt -p 12345
10+
```

trace/curvefs-fuse-bt

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (C) Jingli Chen (Wine93)
4+
5+
############################ GLOBAL VARIABLES
6+
pid=0
7+
dump_src=0
8+
9+
############################ FUNCTIONS
10+
msg() {
11+
printf '%b' "$1" >&2
12+
}
13+
14+
die() {
15+
msg "\33[31m[✘]\33[0m ${1}${2}"
16+
exit 1
17+
}
18+
19+
gen_bpftrace_src() {
20+
local exec_path="$1"
21+
22+
cat << EOF
23+
struct fuse_file_info {
24+
int flags;
25+
unsigned int writepage : 1;
26+
unsigned int direct_io : 1;
27+
unsigned int keep_cache : 1;
28+
unsigned int flush : 1;
29+
unsigned int nonseekable : 1;
30+
unsigned int flock_release : 1;
31+
unsigned int cache_readdir : 1;
32+
unsigned int padding : 25;
33+
unsigned int padding2 : 32;
34+
uint64_t fh;
35+
uint64_t lock_owner;
36+
uint32_t poll_events;
37+
};
38+
39+
BEGIN {
40+
printf ("Start tracing fuse operation for $exec_path, Hit Ctrl-C to end.\n");
41+
}
42+
43+
uprobe:$exec_path:FuseOpLookup
44+
{
45+
printf ("%s: pid(%d) tid(%d) parent(%d) name(%s)\n",
46+
func, pid, tid, args->parent, str(args->name));
47+
}
48+
49+
uprobe:$exec_path:FuseOpGetAttr
50+
{
51+
printf ("%s: pid(%d) tid(%d) ino(%d) fi->fh(%d)\n",
52+
func, pid, tid, args->ino, args->fi->fh);
53+
}
54+
55+
uprobe:$exec_path:FuseOpSetAttr
56+
{
57+
printf ("%s: pid(%d) tid(%d) ino(%d) fi->fh(%d) to_set(%d)\n",
58+
func, pid, tid, args->ino, args->fi->fh, args->to_set);
59+
}
60+
61+
uprobe:$exec_path:FuseOpReadLink
62+
{
63+
printf ("%s: pid(%d) tid(%d) ino(%d)\n",
64+
func, pid, tid, args->ino);
65+
}
66+
67+
uprobe:$exec_path:FuseOpMkNod
68+
{
69+
printf ("%s: pid(%d) tid(%d) parent(%d) name(%s)\n",
70+
func, pid, tid, args->parent, str(args->name));
71+
}
72+
73+
uprobe:$exec_path:FuseOpMkDir
74+
{
75+
printf ("%s: pid(%d) tid(%d) parent(%d) name(%s)\n",
76+
func, pid, tid, args->parent, str(args->name));
77+
}
78+
79+
uprobe:$exec_path:FuseOpUnlink
80+
{
81+
printf ("%s: pid(%d) tid(%d) parent(%d) name(%s)\n",
82+
func, pid, tid, args->parent, str(args->name));
83+
}
84+
85+
uprobe:$exec_path:FuseOpRmDir
86+
{
87+
printf ("%s: pid(%d) tid(%d) parent(%d) name(%s)\n",
88+
func, pid, tid, args->parent, str(args->name));
89+
}
90+
91+
uprobe:$exec_path:FuseOpSymlink
92+
{
93+
printf ("%s: pid(%d) tid(%d) parent(%d) name(%s)\n",
94+
func, pid, tid, args->parent, str(args->name));
95+
}
96+
97+
uprobe:$exec_path:FuseOpRename
98+
{
99+
printf ("%s: pid(%d) tid(%d) parent(%d) name(%s) newparent(%d) newname(%s)\n",
100+
func, pid, tid, args->parent, str(args->name), args->newparent, str(args->newname));
101+
}
102+
103+
uprobe:$exec_path:FuseOpLink
104+
{
105+
printf ("%s: pid(%d) tid(%d) ino(%d) newparent(%d) newname(%s)\n",
106+
func, pid, tid, args->ino, args->newparent, str(args->newname));
107+
}
108+
109+
uprobe:$exec_path:FuseOpOpen
110+
{
111+
printf ("%s: pid(%d) tid(%d) ino(%d)\n",
112+
func, pid, tid, args->ino);
113+
}
114+
115+
uprobe:$exec_path:FuseOpRead
116+
{
117+
printf ("%s: pid(%d) tid(%d) ino(%d) size(%d) off(%d)\n",
118+
func, pid, tid, args->ino, args->size, args->off);
119+
}
120+
121+
uprobe:$exec_path:FuseOpWrite
122+
{
123+
printf ("%s: pid(%d) tid(%d) ino(%d) size(%d) off(%d)\n",
124+
func, pid, tid, args->ino, args->size, args->off);
125+
}
126+
127+
uprobe:$exec_path:FuseOpFlush
128+
{
129+
printf ("%s: pid(%d) tid(%d) ino(%d)\n",
130+
func, pid, tid, args->ino);
131+
}
132+
133+
uprobe:$exec_path:FuseOpRelease
134+
{
135+
printf ("%s: pid(%d) tid(%d) ino(%d)\n",
136+
func, pid, tid, args->ino);
137+
}
138+
139+
uprobe:$exec_path:FuseOpFsync
140+
{
141+
printf ("%s: pid(%d) tid(%d) ino(%d)\n",
142+
func, pid, tid, args->ino);
143+
}
144+
145+
uprobe:$exec_path:FuseOpOpenDir
146+
{
147+
printf ("%s: pid(%d) tid(%d) ino(%d) fi->fh(%d)\n",
148+
func, pid, tid, args->ino, args->fi->fh);
149+
}
150+
151+
uprobe:$exec_path:FuseOpReadDir
152+
{
153+
printf ("%s: pid(%d) tid(%d) ino(%d) size(%d) off(%d) fi->fh(%d)\n",
154+
func, pid, tid, args->ino, args->size, args->off, args->fi->fh);
155+
}
156+
157+
uprobe:$exec_path:FuseOpReleaseDir
158+
{
159+
printf ("%s: pid(%d) tid(%d) ino(%d)\n",
160+
func, pid, tid, args->ino);
161+
}
162+
163+
uprobe:$exec_path:FuseOpStatFs
164+
{
165+
printf ("%s: pid(%d) tid(%d) ino(%d)\n",
166+
func, pid, tid, args->ino);
167+
}
168+
169+
uprobe:$exec_path:FuseOpSetXattr
170+
{
171+
printf ("%s: pid(%d) tid(%d) ino(%d) name(%s) value(%s)\n",
172+
func, pid, tid, args->ino, str(args->name), str(args->value));
173+
}
174+
175+
uprobe:$exec_path:FuseOpGetXattr
176+
{
177+
printf ("%s: pid(%d) tid(%d) ino(%d) name(%s)\n",
178+
func, pid, tid, args->ino, str(args->name));
179+
}
180+
181+
uprobe:$exec_path:FuseOpListXattr
182+
{
183+
printf ("%s: pid(%d) tid(%d) ino(%d) size(%d)\n",
184+
func, pid, tid, args->ino, args->size);
185+
}
186+
187+
uprobe:$exec_path:FuseOpCreate
188+
{
189+
printf ("%s: pid(%d) tid(%d) parent(%d) name(%s)\n",
190+
func, pid, tid, args->parent, str(args->name));
191+
}
192+
193+
uprobe:$exec_path:FuseOpReadDirPlus
194+
{
195+
printf ("%s: pid(%d) tid(%d) ino(%d) size(%d) off(%d) fi->fh(%d)\n",
196+
func, pid, tid, args->ino, args->size, args->off, args->fi->fh);
197+
}
198+
199+
uprobe:$exec_path:FuseOpBmap
200+
{
201+
printf ("FuseOpBmap\n")
202+
}
203+
204+
EOF
205+
}
206+
207+
get_options() {
208+
while getopts "dhp:" opts
209+
do
210+
case $opts in
211+
d)
212+
dump_src=1
213+
;;
214+
h)
215+
usage
216+
exit 0
217+
;;
218+
p)
219+
pid=$OPTARG
220+
;;
221+
\?)
222+
usage
223+
exit 1
224+
;;
225+
esac
226+
done
227+
}
228+
229+
usage () {
230+
cat << _EOC_
231+
Usage:
232+
curvefs-fuse-bt [options]
233+
234+
Options:
235+
-d Dump out the bpftrace script source.
236+
-h Print this usage.
237+
-p <pid> Specify the user process pid.
238+
239+
Examples:
240+
curvefs-fuse-bt -p 12345
241+
curvefs-fuse-bt -p 12345 -d
242+
_EOC_
243+
}
244+
245+
main() {
246+
get_options "$@"
247+
248+
if [ $pid -eq 0 ]; then
249+
die "No process pid specified by the -p option.\n";
250+
fi
251+
252+
local exec_path="/proc/${pid}/root/curvefs/client/sbin/curve-fuse"
253+
if [ ! -f "$exec_path" ]; then
254+
die "Process $pid is not running or " \
255+
"you do not have enough permissions.\n"
256+
fi
257+
258+
local bpftrace_src=`gen_bpftrace_src "$exec_path"`
259+
if [ $dump_src -eq 1 ]; then
260+
echo "$bpftrace_src"
261+
exit 0
262+
fi
263+
264+
echo "$bpftrace_src" | bpftrace -
265+
}
266+
267+
############################ MAIN()
268+
main "$@"

0 commit comments

Comments
 (0)