Merge tag 'v3.14.25' into backport/v3.14.24-ltsi-rc1+v3.14.25/snapshot-merge.wip
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / ktap / samples / basic / function_time.kp
1 #!/usr/bin/env ktap
2
3 #Demo for thread-local variable
4 #
5 #Note this kind of function time tracing already handled concurrent issue,
6 #but not aware on the recursion problem, user need to aware this limitation,
7 #so don't use this script to trace function which could be called recursive.
8
9 self = {}
10 count_max = 0
11 count_min = 0
12 count_num = 0
13 total_time = 0
14
15 printf("measure time(us) of function vfs_read\n");
16
17 trace probe:vfs_read {
18         if (execname() == "ktap") {
19                 return
20         }
21
22         self[tid()] = gettimeofday_us()
23 }
24
25 trace probe:vfs_read%return {
26         if (execname() == "ktap") {
27                 return
28         }
29
30         if (self[tid()] == nil) {
31                 return
32         }
33
34         local durtion = gettimeofday_us() - self[tid()]
35         if (durtion > count_max) {
36                 count_max = durtion
37         }
38         local min = count_min
39         if (min == 0 || durtion < min) {
40                 count_min = durtion
41         }
42
43         count_num = count_num + 1
44         total_time = total_time + durtion
45
46         self[tid()] = nil
47 }
48
49 trace_end {
50         printf("avg\tmax\tmin\n");
51         printf("-------------------\n")
52
53         printf("%d\t%d\t%d\n", total_time/count_num,
54                 count_max, count_min)
55 }
56
57