summaryrefslogtreecommitdiffstats
path: root/nfsdcalltimes
blob: dafa59228682c64486a5c88f09c0d5755b0dfb6e (plain)
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
#!/bin/bash
do_sort=0
sort_ave=0
sort_cnt=0
sort_min=0
sort_max=0
sort_tot=0
show_all=1
verbose=""
function usage {
	echo "Usage: nfsdcalltimes [-Aachnmtv]"
	echo "    -A - Do all possible sorting"
	echo "    -a - sort by Ave ns"
	echo "    -c - sort by Count"
	echo "    -n - sort by Min ns" 
	echo "    -m - sort by Max ns"
	echo "    -t - sort by Total ns"
	echo "    -v - turn on SystemTap debugging"
	echo "    -h - print this help text"
}
while getopts Aachnmtv option; do
	case $option in
	A) sort_ave=1;  sort_cnt=1;  sort_min=1; 
		sort_max=1;  sort_tot=1; do_sort=1;;
	a) sort_ave=1; do_sort=1;;
	c) sort_cnt=1; do_sort=1 ;;
	n) sort_min=1; do_sort=1 ;;
	m) sort_max=1; do_sort=1 ;;
	t) sort_tot=1; do_sort=1 ;;
	v) verbose="-v "$verbose ;;
	h|?|*)  usage
		exit 1;;
	esac
done

if [ $do_sort -eq 1 ]; then
	show_all=0
fi
echo "Creating and building SystemTap module..."

stap "$verbose" -e '
global timebyfunc, top
global start

probe begin {
	printf("Collecting nfsd data - type Ctrl-C to print output and exit...\n")
}

probe module("nfsd").function("*@fs/nfsd/*")
{
	start[probefunc(), tid()] = gettimeofday_ns()
}
probe module("nfsd").function("*@fs/nfsd/*").return
{
	if (!([probefunc(), tid()] in start)) next

	delta = gettimeofday_ns() -  start[probefunc(), tid()]
	timebyfunc[probefunc()] <<< delta
	
	delete start[probefunc(), tid()]
}
function print_header() {
	printf("%-26s %10s %12s %12s %12s %12s\n",
	       "Call", "Count", "Total ns",
	       "Avg ns", "Min ns", "Max ns")
}
probe end {
	if ('$sort_ave' != 0) {
		printf("\nSorted nfsd data by Avg ns \n")
		print_header()
		foreach (call in timebyfunc)
			top[call] = @avg(timebyfunc[call])
		foreach (call in top- limit 20)
			printf("%-26s %10d %12d %12d %12d %12d\n", call,
				@count(timebyfunc[call]),
				@sum(timebyfunc[call]),
				@avg(timebyfunc[call]),
				@min(timebyfunc[call]),
				@max(timebyfunc[call]))
		delete top
	}
	if ('$sort_cnt' != 0) {
		printf("\nSorted nfsd data by Count\n")
		print_header()
		foreach (call in timebyfunc)
			top[call] = @count(timebyfunc[call])
		foreach (call in top- limit 20)
			printf("%-26s %10d %12d %12d %12d %12d\n", call,
				@count(timebyfunc[call]),
				@sum(timebyfunc[call]),
				@avg(timebyfunc[call]),
				@min(timebyfunc[call]),
				@max(timebyfunc[call]))
		delete top
	}
	if ('$sort_tot' != 0) {
		printf("\nSorted nfsd data by Total ns\n")
		print_header()
		foreach (call in timebyfunc)
			top[call] = @sum(timebyfunc[call])
		foreach (call in top- limit 20)
			printf("%-26s %10d %12d %12d %12d %12d\n", call,
				@count(timebyfunc[call]),
				@sum(timebyfunc[call]),
				@avg(timebyfunc[call]),
				@min(timebyfunc[call]),
				@max(timebyfunc[call]))
		delete top
	}
	if ('$sort_min' != 0) {
		printf("\nSorted nfsd data by Min ns\n")
		print_header()
		foreach (call in timebyfunc)
			top[call] = @min(timebyfunc[call])
		foreach (call in top- limit 20)
			printf("%-26s %10d %12d %12d %12d %12d\n", call,
				@count(timebyfunc[call]),
				@sum(timebyfunc[call]),
				@avg(timebyfunc[call]),
				@min(timebyfunc[call]),
				@max(timebyfunc[call]))
		delete top
	}
	if ('$sort_max' != 0) {
		printf("\nSorted nfsd data by Max ns\n")
		print_header()
		foreach (call in timebyfunc)
			top[call] = @min(timebyfunc[call])
		foreach (call in top- limit 20)
			printf("%-26s %10d %12d %12d %12d %12d\n", call,
				@count(timebyfunc[call]),
				@sum(timebyfunc[call]),
				@avg(timebyfunc[call]),
				@min(timebyfunc[call]),
				@max(timebyfunc[call]))
		delete top
	}
	if ('$show_all' != 0) {
		print_header()
		foreach (call in timebyfunc)
			printf("%-26s %10d %12d %12d %12d %12d\n", call,
				@count(timebyfunc[call]),
				@sum(timebyfunc[call]),
				@avg(timebyfunc[call]),
				@min(timebyfunc[call]),
				@max(timebyfunc[call]))
	}
	delete timebyfunc
}'