Debian Codegraph @

tapset/indent.stp

raw
1 /* <tapsetdescription>
2 * The indent tapset provides functions to generate indented lines for
3 * nested kinds of trace messages. Each line contains a relative
4 * timestamp, and the process name / pid. The timestamp is as per
5 * provided by the __indent_timestamp function, which by default
6 * measures microseconds.
7 * </tapsetdescription>
8 */
9
10 @__private30 global _indent_counters, _indent_timestamps
11
12 @__private30 function _generic_indent_depth:long (idx, delta)
13 {
14 # pre-increment for positive delta and post-decrement for negative delta
15 x = _indent_counters[idx] + (delta > 0 ? delta : 0)
16 _indent_counters[idx] += delta
17
18 return (x>0 ? x-1 : 0)
19 }
20
21 @__private30 function _generic_indent (idx, desc, delta)
22 {
23 ts = __indent_timestamp ()
24 if (! _indent_counters[idx]) _indent_timestamps[idx] = ts
25
26 depth = _generic_indent_depth(idx, delta)
27
28 return sprintf("%6d %s:%-*s", (ts - _indent_timestamps[idx]), desc, depth, "")
29 }
30
31 /**
32 * sfunction thread_indent - returns an amount of space with the current task information
33 *
34 * @delta: the amount of space added/removed for each call
35 *
36 * Description: This function returns a string with appropriate
37 * indentation for a thread. Call it with a small positive or
38 * matching negative delta. If this is the real outermost,
39 * initial level of indentation, then the function resets the
40 * relative timestamp base to zero. The timestamp is as per
41 * provided by the __indent_timestamp function, which by default
42 * measures microseconds.
43 */
44 function thread_indent:string (delta:long)
45 {
46 return _generic_indent (tid(), sprintf("%s(%d)", execname(), tid()), delta)
47 }
48
49 /**
50 * sfunction thread_indent_depth - returns the nested-depth of the current task
51 *
52 * @delta: the amount of depth added/removed for each call
53 *
54 * Description: This function returns an integer equal to the nested
55 * function-call depth starting from the outermost initial level. This function
56 * is useful for saving space (consumed by whitespace) in traces with long
57 * nested function calls. Use this function in a similar fashion to
58 * thread_indent(), i.e., in call-probe, use thread_indent_depth(1) and in
59 * return-probe, use thread_indent_depth(-1)
60 */
61 function thread_indent_depth:long (delta:long)
62 {
63 return _generic_indent_depth (tid(), delta)
64 }
65
66 /**
67 * sfunction indent - returns an amount of space to indent
68 *
69 * @delta: the amount of space added/removed for each call
70 *
71 * Description: This function returns a string with appropriate
72 * indentation. Call it with a small positive or matching negative
73 * delta. Unlike the thread_indent function, the indent does not
74 * track individual indent values on a per thread basis.
75 */
76 function indent:string (delta:long){
77 return _generic_indent(-1, "", delta)
78 }
79
80 /**
81 * sfunction indent_depth - returns the global nested-depth
82 *
83 * @delta: the amount of depth added/removed for each call
84 *
85 * Description: This function returns a number for appropriate indentation,
86 * similar to indent(). Call it with a small positive or matching negative
87 * delta. Unlike the thread_indent_depth function, the indent does not track
88 * individual indent values on a per thread basis.
89 */
90 function indent_depth:long (delta:long)
91 {
92 return _generic_indent_depth (-1, delta)
93 }
94
95 /* The following example uses thread_indent() to trace the functions
96 * called in the drivers/usb/core kernel source. It prints a relative
97 * timestamp and the name and ID of the current process, followed by
98 * the appropriate indent and the function name. Note that
99 * 'char' swapper(0) indicates the kernel is running in interrupt
100 * context and there is no valid current process.
101 *
102 * probe kernel.function("*@drivers/usb/core/*") {
103 * printf("%s -> %s\n, thread_indent(1), probefunc())
104 * }
105 * probe kernel.function("*@drivers/usb/core/*").return {
106 * printf("%s <- %s\n", thread_indent(-1), probefunc())
107 * }
108 *
109 * //This prints:
110 * 0 swapper(0): -> usb_hcd_irq
111 * 8 swapper(0): <- usb_hcd_irq
112 * 0 swapper(0): -> usb_hcd_irq
113 * 10 swapper(0): -> usb_hcd_giveback_urb
114 * 16 swapper(0): -> urb_unlink
115 * 22 swapper(0): <- usb_unlink
116 * 29 swapper(0): -> usb_free_urb
117 * 35 swapper(0): <- usb_hcd_urb
118 * 39 swapper(0): <- usb_hcd_giveback_urb
119 * 45 swapper(0): <- usb_hcd_irq
120 * 0 usb-storage(1338): -> usb_submit_urb
121 * 6 usb-storage(1338): -> usb_hcd_submit_urb
122 * 12 usb-storage(1338): -> usb_get_urb
123 * 18 usb-storage(1338): <- usb_get_urb
124 * 25 usb-storage(1338): <- usb_hcd_submit_urb
125 * 29 usb-storage(1338): -> usb_submit_urb
126 * 0 swapper(0): -> usb_hcd_irq
127 * 7 swapper(0): <- usb_hcd_irq
128 */