| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| 3 |
]> |
| 4 |
|
| 5 |
|
| 6 |
<section id="countcallssect"> |
| 7 |
<title>Counting Function Calls Made</title> |
| 8 |
<indexterm> |
| 9 |
<primary>script examples</primary> |
| 10 |
<secondary>tallying function calls</secondary> |
| 11 |
</indexterm> |
| 12 |
|
| 13 |
<indexterm> |
| 14 |
<primary>examples of SystemTap scripts</primary> |
| 15 |
<secondary>tallying function calls</secondary> |
| 16 |
</indexterm> |
| 17 |
|
| 18 |
<indexterm> |
| 19 |
<primary>tallying function calls</primary> |
| 20 |
<secondary>examples of SystemTap scripts</secondary> |
| 21 |
</indexterm> |
| 22 |
|
| 23 |
|
| 24 |
<indexterm> |
| 25 |
<primary>counting function calls</primary> |
| 26 |
<secondary>examples of SystemTap scripts</secondary> |
| 27 |
</indexterm> |
| 28 |
|
| 29 |
<indexterm> |
| 30 |
<primary>function calls, tallying</primary> |
| 31 |
<secondary>examples of SystemTap scripts</secondary> |
| 32 |
</indexterm> |
| 33 |
|
| 34 |
|
| 35 |
<remark> |
| 36 |
WAR STORY: Function call count http://sourceware.org/systemtap/wiki/WSFunctionCallCount?highlight=((WarStories)) |
| 37 |
</remark> |
| 38 |
|
| 39 |
<remark> |
| 40 |
no script in examples |
| 41 |
</remark> |
| 42 |
|
| 43 |
|
| 44 |
<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> |
| 45 |
|
| 46 |
<formalpara id="countcalls"> |
| 47 |
<title>functioncallcount.stp</title> |
| 48 |
<para> |
| 49 |
<programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/profiling/functioncallcount.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting> |
| 50 |
</para> |
| 51 |
</formalpara> |
| 52 |
|
| 53 |
<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> |
| 54 |
<indexterm> |
| 55 |
<primary>script examples</primary> |
| 56 |
<secondary>timer.ms(), sample usage</secondary> |
| 57 |
</indexterm> |
| 58 |
|
| 59 |
<indexterm> |
| 60 |
<primary>examples of SystemTap scripts</primary> |
| 61 |
<secondary>timer.ms(), sample usage</secondary> |
| 62 |
</indexterm> |
| 63 |
|
| 64 |
<indexterm> |
| 65 |
<primary>timer.ms(), sample usage</primary> |
| 66 |
<secondary>examples of SystemTap scripts</secondary> |
| 67 |
</indexterm> |
| 68 |
|
| 69 |
<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> |
| 70 |
|
| 71 |
|
| 72 |
<example id="countcallsoutput"> |
| 73 |
<title><xref linkend="countcalls"/> Sample Output</title> |
| 74 |
<screen>[...] |
| 75 |
__vma_link 97 |
| 76 |
__vma_link_file 66 |
| 77 |
__vma_link_list 97 |
| 78 |
__vma_link_rb 97 |
| 79 |
__xchg 103 |
| 80 |
add_page_to_active_list 102 |
| 81 |
add_page_to_inactive_list 19 |
| 82 |
add_to_page_cache 19 |
| 83 |
add_to_page_cache_lru 7 |
| 84 |
all_vm_events 6 |
| 85 |
alloc_pages_node 4630 |
| 86 |
alloc_slabmgmt 67 |
| 87 |
anon_vma_alloc 62 |
| 88 |
anon_vma_free 62 |
| 89 |
anon_vma_lock 66 |
| 90 |
anon_vma_prepare 98 |
| 91 |
anon_vma_unlink 97 |
| 92 |
anon_vma_unlock 66 |
| 93 |
arch_get_unmapped_area_topdown 94 |
| 94 |
arch_get_unmapped_exec_area 3 |
| 95 |
arch_unmap_area_topdown 97 |
| 96 |
atomic_add 2 |
| 97 |
atomic_add_negative 97 |
| 98 |
atomic_dec_and_test 5153 |
| 99 |
atomic_inc 470 |
| 100 |
atomic_inc_and_test 1 |
| 101 |
[...]</screen> |
| 102 |
</example> |
| 103 |
<!--probe kernel.function(@1) { # probe function passed as argument from stdin |
| 104 |
called[probefunc()] <<< 1 # add a count efficiently |
| 105 |
} |
| 106 |
global called |
| 107 |
probe end,timer.ms(30000) { |
| 108 |
foreach (fn+ in called) # Sort by function name |
| 109 |
# (fn in called-) # Sort by call count (in decreasing order) |
| 110 |
printf("%s %d\n", fn, @count(called[fn])) |
| 111 |
exit() |
| 112 |
}--> |
| 113 |
|
| 114 |
</section> |
| 115 |
|