/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Analysis/instrumentation/systap/probes.txt

  • Committer: Suren A. Chilingaryan
  • Date: 2015-08-21 03:52:00 UTC
  • Revision ID: csa@suren.me-20150821035200-xu1zh22cqlk2omcq
Profiling

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Syntax
 
2
======
 
3
    global a                                                    global variable
 
4
    "(" . string_var . ")"                                      string concatentation
 
5
    string_var = sprint(123)                                    convert integer to string
 
6
    printf("%u", var)                                           variables are untyped, but types should be specified while printing
 
7
    thread_indent(1) / thread_indent(-1)                        Indenting the output
 
8
 
 
9
    if () ... else if () ... else ...                           conditionals
 
10
    if (string_var == "test") ...                               string conditionals
 
11
 
 
12
    while (i < 5) ...                                           loops
 
13
    for (i = 0; i < 5; i++) ...                                 for
 
14
    function add(a,b) { return a + b; }                         functions
 
15
 
 
16
    global b[128]                                               array (or actually the map) with space reserved for 128 tupples
 
17
    bloabl b%[128]                                              ring-buffer style array (the old elements will be overriden when running out of space)
 
18
    b["name", 1]++                                              incrementing an element of array defined by two variables of which one is string and another integer
 
19
    if (["name", 1] in b)                                       check if element is in array
 
20
    delete(["name", 1])                                         detelete element
 
21
    foreach (x = [a,b] in foo) { ... }                          iterate over elements
 
22
    foreach (x = [a,b] in foo+ limit 5) { }                     sort by value (inc) and iterate over first 5 elements
 
23
    foreach (x = [a-,b] in foo) { }                             sort by first key (desc) and iterate
 
24
    
 
25
    var <<< latency                                             aggregates (variable collects statistical information which can be requested later wish special functions)
 
26
    @avg(var), @min, @max, @sum, @count                         statististics on aggregated variable [ per processor? ]
 
27
    @hist_linear(var,min,max,step)                              generate a histogram
 
28
    @hist_log(var)                                              logarithmic histogram
 
29
    delete var                                                  clean statistics
 
30
 
 
31
    print(var|histogram|$var|$$vars)                            print the stuff
 
32
 
 
33
Probes
 
34
======
 
35
    probe probe_spec { ... }                                    Probes are entry points of script 
 
36
    probe probe_spec if (cond) { ... }                          Conditional probe (but it will not save performance, at least as of 2015.08)
 
37
    $var                                                        the variable defined in the probe context (i.e. local variable or parameter in kernel function)
 
38
        * stap -L 'kernel.function("sys_open")'                 Get all variables at specified probe (both uprobes & krpobes)
 
39
        * stap -L 'kernel.function("*@net/socket.c")'           Show all existing probes for the specified pattern (both uprobes & kprobes)
 
40
    $$vars                                                      is used for a pretty-printed listing of all local variables in scope: print($$vars) 
 
41
    @defined($var)                                              checks if variable is define in the probe scope: if (@defined($size)) { ... }
 
42
    @cast($ptr)                                                 casts pointer to its type
 
43
    $1 $2 $3 ...                                                command line parameters
 
44
 
 
45
Probes
 
46
======
 
47
 - begin                                                        The startup of the systemtap session.
 
48
 - end                                                          The end of the systemtap session.
 
49
 - timer.profile                                                A timer that fires periodically on every CPU.
 
50
 - timer.ms(200)                                                A timer that fires every 200 milliseconds.
 
51
 - syscall.close                                                The syscall
 
52
 - syscall.close.return                                         The return from the close system call.
 
53
 - kernel.function("sys_open")                                  The entry to the function named sys_open in the kernel (only kernel, not modules)
 
54
 - kernel.function("*@net/socket.c")                            All functions in net/socket.c
 
55
 - module("ext3").statement(0xdeadbeef)                         The addressed instruction in the ext3 filesystem driver.
 
56
 - process("~/a.out").statement("*@main.c:200")                 Line 200 of the a.out program (will not resolve symbols/code from shared libraries).
 
57
 - process("~/libpcilib.so.2").function("*@kmem.c")             The same way the shared library may be probed
 
58
 - ... .function("*").return                                    Probe at return statement of the specified function
 
59
 - ... .function("*").label("fail")                             Probe at the specified label
 
60
 - procfs("status").read                                        A process trying to read a synthetic file.
 
61
 - perf.hw.cache_misses                                         A particular number of CPU cache misses have occurred.
 
62
 
 
63
 
 
64
Parameters
 
65
==========
 
66
 - target()                                                     The process pid specified with -x PID parameter
 
67
 
 
68
Configuration
 
69
=============
 
70
 - tid()                                                        The id of the current thread.
 
71
 - pid()                                                        The process (task group) id of the current thread.
 
72
 - uid()                                                        The id of the current user.
 
73
 - execname()                                                   The name of the current process.
 
74
 - cpu()                                                        The current cpu number.
 
75
 - gettimeofday_us()                                            Number of microseconds since epoch (_s, _ms as well) 
 
76
 - get_cycles()                                                 Snapshot of hardware cycle counter.
 
77
 - pp()                                                         A string describing the probe point being currently handled.
 
78
 - ppfunc()                                                     If known, the the function name in which this probe was placed.
 
79
 - print_backtrace()                                            If possible, print a kernel backtrace.
 
80
 - print_ubacktrace()                                           If possible, print a user-space backtrace.
 
81
 
 
82
Libraries
 
83
=========
 
84
 /usr/share/systemtap/tapset                                    All functions defined there can be used directly
 
85
    stap -I <dir> ...                                           Specify additional directory with tapsets
 
86
    
 
87
Embedded C
 
88
==========
 
89
    stap -g ...                                                 Disabled by default, should run in guru mode
 
90
        * Do not dereference pointers that are not known or testable valid. 
 
91
        * Do not call any kernel routine that may cause a sleep or fault. 
 
92
        * Prevent recursion, where your embedded C function calls a routine that may be the subject of a probe. 
 
93
        * If locking of a data structure is necessary, use a trylock type call to attempt to take the lock. If that fails, give up, do not block. 
 
94
            
 
95
    function test_func:int (pid:long)                           The emdedded C function should define types of all variables
 
96
    %{ ... %}                                                   Embedded C code is indicated with "%{" 
 
97
 
 
98