File: Useful_Scripts-functioncalls.xml

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (115 lines) | stat: -rw-r--r-- 3,421 bytes parent folder | download | duplicates (8)
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
<?xml version='1.0'?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
]>


	<section id="countcallssect">
		<title>Counting Function Calls Made</title>
<indexterm>
<primary>script examples</primary>
<secondary>tallying function calls</secondary>
</indexterm>

<indexterm>
<primary>examples of SystemTap scripts</primary>
<secondary>tallying function calls</secondary>
</indexterm>

<indexterm>
<primary>tallying function calls</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>


<indexterm>
<primary>counting function calls</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>

<indexterm>
<primary>function calls, tallying</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>


<remark>
	WAR STORY: Function call count http://sourceware.org/systemtap/wiki/WSFunctionCallCount?highlight=((WarStories))
</remark>

<remark>
no script in examples
</remark>


	<para>This section describes how to identify how many times the system called a specific kernel function in a 30-second sample. Depending on the use of wildcards, you can also use this script to target multiple kernel functions.</para>

<formalpara id="countcalls">
	<title>functioncallcount.stp</title>
<para>
<programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/profiling/functioncallcount.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
</para>
</formalpara>

<para><xref linkend="countcalls"/> takes the targeted kernel function as an argument. The argument supports wildcards, which enables you to target multiple kernel functions up to a certain extent.</para>
<indexterm>
<primary>script examples</primary>
<secondary>timer.ms(), sample usage</secondary>
</indexterm>

<indexterm>
<primary>examples of SystemTap scripts</primary>
<secondary>timer.ms(), sample usage</secondary>
</indexterm>

<indexterm>
<primary>timer.ms(), sample usage</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>

<para>The output of <xref linkend="countcalls"/> contains the name of the function called and how many times it was called during the sample time (in alphabetical order). <xref linkend="countcallsoutput"/> contains an excerpt from the output of <command>stap functioncallcount.stp "*@mm/*.c"</command>:</para>


<example id="countcallsoutput">
	<title><xref linkend="countcalls"/> Sample Output</title>
<screen>[...]
__vma_link 97
__vma_link_file 66
__vma_link_list 97
__vma_link_rb 97
__xchg 103
add_page_to_active_list 102
add_page_to_inactive_list 19
add_to_page_cache 19
add_to_page_cache_lru 7
all_vm_events 6
alloc_pages_node 4630
alloc_slabmgmt 67
anon_vma_alloc 62
anon_vma_free 62
anon_vma_lock 66
anon_vma_prepare 98
anon_vma_unlink 97
anon_vma_unlock 66
arch_get_unmapped_area_topdown 94
arch_get_unmapped_exec_area 3
arch_unmap_area_topdown 97
atomic_add 2
atomic_add_negative 97
atomic_dec_and_test 5153
atomic_inc 470
atomic_inc_and_test 1
[...]</screen>
</example>
<!--probe kernel.function(@1) {  # probe function passed as argument from stdin
called[probefunc()] &lt;&lt;&lt; 1  # add a count efficiently
}
global called
probe end,timer.ms(30000) {
foreach (fn+ in called)  # Sort by function name
#       (fn in called-)  # Sort by call count (in decreasing order)
printf("%s %d\n", fn, @count(called[fn]))
exit()
}-->

	</section>