Class Trace
Declare a new class "Trace" into Lua global table
This class is a helper-class to manage low-level probes and tracing in a
user friendlier way.
The fundamental friendliness is based of the concept of
selections (see method sel below).
See also:
Tables
| trace.mt | Assisting Meta-table |
Methods
| trace:version () | version |
| trace:listall () | listall
Prints to console a list of all probes. |
| trace:p_sel ([filename][, funcname][, kind]) | p_sel
Print a selection. |
| trace:p_stat ([filename][, funcname][, kind]) | p_stat
Print status for a selection of probes. |
| trace:stat ([filename][, funcname][, kind]) | stat
Return a table of status for a selection of probes. |
| trace:whatis (Probe) | whatis
Look-up code reference for a certain probe-ID. |
| trace:set ([s=self], ctrl[, cntr[, ts=0]]) | set
Set ctrl bit-mask for a selection of probe(s) and optionally it's/their counter and time-stamp values. |
| trace:sel ([Instance], filename, funcname, kind[, idx1[, idx2]]) | sel
Return a selection of probes in a table based a human-readable specifiers of source-code references. |
| trace:sub ([s=self], idx1[, idx2]) | sub |
| trace:dprobe (dep[, own=self]) | dprobe
Set up a low level probe-dependency using high-level code references When the owner-probe is passed, a difference in both number of passed and time is calculated. |
| trace:cast (elem) | cast |
| trace:new (arg1, funcname, kind[, idx1[, idx2]]) |
new Selection or copy/cast CTOR
|
Metamethods
| trace:__add (rhs) | Operator + (join)
Returns the "set theory" join of two Trace objects, for example
A + B. |
| trace:__sub (rhs) | Operator - (subtracted intersection) |
| trace:__mod (rhs) | Operator % (intersection) |
| trace:__lt (rhs) |
Operator true or false if LHS is fully confined in RHS
In other words, for
|
| trace:__lte (rhs) | Operator <= (contained by) |
| trace:__eq (rhs) | Operator == (equal) |
Tables
- trace.mt
-
Assisting Meta-table Operators
Fields:
- __index
- __tostring
- return
- l
- end
- __add
- l
- l
- __sub
- l
- k
- l
- k
- __mod
- k
- l
- k
- __lt
- __lte
- __eq
Methods
- trace:version ()
-
version Returns (1) version string
Returns:
-
String
version
Usage:
Trace:version() -- utrace <0.3.4-8269c16>
- trace:listall ()
-
listall
Prints to console a list of all probes. Note that LOG-probes are included as even if a LOG is muted/inactive, it's still also a trace-point "probe".
Returns:
-
Integer
Total number of probes
- trace:p_sel ([filename][, funcname][, kind])
-
p_sel
Print a selection. Usually for interactive use before acting upon it to make sure the conditions are covering the intended probe/probes.
Normally used interactively to determine enough specific criteria for a probe", not several probes.
Note that the function is not returning the list for Lua-VM. It's printing to console for either interactive use or for RPC use.
Print is a columns of: ID, kind, filename, funcname, line
Arguments are the same as sel (follow "See also") OR one Trace instance with a selection.
Parameters:
- filename String -OR- Trace instance (optional)
- funcname String (optional)
- kind String (optional)
Returns:
-
Integer
Number of probes fitting selection
See also:
- trace:p_stat ([filename][, funcname][, kind])
-
p_stat
Print status for a selection of probes. This is handy for determining if one or several probes are live or not. I.e. it's "passed-counters" and "latest time-stamps" are changing.
The list is the same as p_sel with regards to order order and ID, just that the 3 last columns "file", "function" and "line" are replaced with "control", "counter" and "time-stamp".
Note that the function is not returning the list for Lua-VM. It's printing to console for either interactive use or for RPC use.
Print is a columns of: ID ,kind ,filename ,func-name ,line [,d-time ,d-counts ,linked-probe-ID]
Note that the last three columns are conditional and depends of if probe is diff-event linked to another or not (see utrace-probe.setdprobe)
Arguments are the same as sel (follow "See also") OR one Trace instance with a selection.
Parameters:
- filename String -OR- Trace instance (optional)
- funcname String (optional)
- kind String (optional)
Returns:
-
Integer
Number of probes fitting selection
See also:
- trace:stat ([filename][, funcname][, kind])
-
stat
Return a table of status for a selection of probes. Identical to p_stat except that nothing is printed and the return is a table. Note that the table is not live, i.e. Function needs to be re-iterated for current values.
Parameters:
- filename String -OR- Trace instance (optional)
- funcname String (optional)
- kind String (optional)
Returns:
-
Table
of statuses
See also:
Usage:
a = Trace('test_main.c','thread_A',nil,1) b = Trace('test_main.c','thread_A',nil,2) Trace:set(a + b, 1) -- 2 Trace:dprobe(b, a) -- Establish relation t = Trace:stat(a + b) -- Table with probes and stats print("Time between probes: " .. t[2][5]/1E6 .. " (mS)") -- Time between probes: 5.05918 (mS)
- trace:whatis (Probe)
-
whatis
Look-up code reference for a certain probe-ID. Note: not selection (sel) based but ID-specific. Useful after determining which probe is live p_stat like in the example below.
Parameters:
- Probe Integer -ID (address)
Returns:
- String kind What kind of probe is it (T="trace", L="log")
- String filename File name
- String funcname Function name
- Number lineno Line number
- Integer Linked Probe-ID (conditional)
Usage:
-- Enable probes of selection defined by arguments Trace:set({Trace:sel("test_main.c","thread_A")}, 1) -- 1 94651015758336 T 1 0 0 -- 2 94651015758400 T 1 0 0 -- Print statuses of selection defined by arguments Trace:p_stat("test_main.c") -- 1 94376905458432 T 0 0 0 -- 2 94376905458496 T 0 0 0 -- 3 94376905458304 T 0 0 0 -- 4 94376905458368 T 0 0 0 -- 5 94376905458176 T 1 405 96874004698502 -- 6 94376905458240 T 1 406 96874009765001 -- Look-up one of the probes from the list above Trace:whatis(94376905458240) -- T test_main.c thread_A 59
- trace:set ([s=self], ctrl[, cntr[, ts=0]])
-
set
Set ctrl bit-mask for a selection of probe(s) and optionally it's/their counter and time-stamp values.
First argument can be either a table of size and selection as returned by sel or just the selection as size is implicit in the selection's base-type/class (table)
It can also be omitted, in which case the selection in
selfis assumed and the rest of the arguments starts at second argument.Central operation about method is operating on groups of probes, i.e. selections. An instance of Trace can have a selection (from
CTORor appended), therefore it can operate onselfParameters:
- s Table Trace instance or Trace-selection table (default self)
- ctrl Integer Control (bit-mask). Required
- cntr Integer Counter. (optional)
- ts Integer Time-stamp. (default 0)
Returns:
- Integer Number of probes fitting selection
- Integer Number of probes changed
See also:
Usage:
-- Class static tps = Trace('test_main.c','thread_A') Trace:set(tps, 1) Trace:p_stat(tps)
-- Object instances tps = Trace('test_main.c','thread_A') tps:set(1) tps:p_stat() tps:set(1, 0) -- Continue counting, reset counters but not timestamps tps:p_stat()
- trace:sel ([Instance], filename, funcname, kind[, idx1[, idx2]])
-
sel
Return a selection of probes in a table based a human-readable specifiers of source-code references.
Arguments are used to define a "selection". A "selection" is one or a group of probe-ID's having the search (or "selection") criteria in common. All arguments are optional (varargs).
- No arguments returns all probes in a process.
- Arguments of
String-type are matched using Lua regular expressions and don't need to be exact matches. This enables generalized scripting for variants of same or similar code.
Positional argument order matters. I.e. if any preceding arguments don't need specifying (in this method meaning: "include all of what that arguments specifier stands for"), it/they still have to be passed but with the value
nil.Sub-selection argument(s) (optional): * If only one is given: A 1-element sub-selection at that index of the overall selection is returned * If both: The sub-selection is the range between the two indexes * If first index greater than last: The sub-selection is the range between the two indexes, but in reversed order.
Return is number of probes fitting selection and corresponding table with following key-values:
ptr (Integer) Address of probe used as unique ID kind (String) "T"=trace-probe, "L"=log-probe etc filename (String) File-name funcname (String) Function-name line (Integer) Line-numberParameters:
- Instance Trace with selection (optional)
- filename String
- funcname String
- kind String
- idx1 Integer Start of sub-selection (optional)
- idx2 Integer End of sub-selection (optional)
Returns:
- Integer Number of matches for selection
- Table {ID, kind, filename, funcname, line}
See also:
Usage:
-- Make a trial selection. No or all
nilarguments returns all probes Trace:sel() -- { -- {93935255593696, "T", "test_main.c", "main", 131}, -- {93935255593632, "T", "test_main.c", "main", 134}, -- {93935255593568, "T", "test_main.c", "thread_B", 69}, -- {93935255593504, "T", "test_main.c", "thread_B", 71}, -- {93935255593440, "T", "test_main.c", "thread_A", 57}, -- {93935255593376, "T", "test_main.c", "thread_A", 59}, -- {93935255594976, "T", "test_extra_thread.c", "thread_C", 38}, -- {93935255594912, "T", "test_extra_thread.c", "thread_C", 39}, -- {93935255594848, "T", "test_extra_thread.c", "thread_C", 40}, -- {93935255594784, "T", "test_extra_thread.c", "thread_C", 41}, -- {93935255594720, "T", "test_extra_thread.c", "thread_C", 42}, -- {93935255594656, "T", "test_extra_thread.c", "thread_C", 43}, -- {93935255594592, "T", "test_extra_thread.c", "thread_C", 44}, -- {93935255594528, "T", "test_extra_thread.c", "thread_C", 45}, -- {93935255594464, "T", "test_extra_thread.c", "thread_C", 46}, -- {93935255594400, "T", "test_extra_thread.c", "thread_C", 47} -- } -- t = Trace:sel() -- Repeat but this time assign the result, then print the first one -- Note that the table returned is a 2D index-table of data-dictionaries print(t[1].filename, t[1].funcname, t[1].line) -- test_main.c thread_A 56 - trace:sub ([s=self], idx1[, idx2])
-
sub Sub-selection of instance-selection from index range, or singular probe
still as instance of Trace, for singular index.
Parameters:
- s Trace Use selection from Trace-instance (default self)
- idx1 Integer Start of sub-selection
- idx2 Integer End of sub-selection (optional)
Returns:
-
Trace
New instance with sub-selection
Usage:
-- Sub-select functions from file-selection m = Trace('.*main.c') A = m:sub(1, 2) B = m:sub(4) R = m:sub(6, 5) -- reversed print(A + B + R) -- { -- {106297695531040, "T", "test_main.c", "thread_A", 57}, -- {106297695531104, "T", "test_main.c", "thread_A", 59}, -- {106297695531232, "T", "test_main.c", "thread_B", 71}, -- {106297695531360, "T", "test_main.c", "main", 134}, -- {106297695531296, "T", "test_main.c", "main", 131} -- }
-- Class-static usage m = Trace('.*main.c') D = Trace:sub(m, 2) print(D) -- { -- {110968930517088, "T", "test_main.c", "thread_A", 59} -- }
- trace:dprobe (dep[, own=self])
-
dprobe
Set up a low level probe-dependency using high-level code references
When the owner-probe is passed, a difference in both number of passed and time is calculated. I.e. the second probe (the owner) also drives the event to perform the diff-operation.
Function one or two Trace instance arguments,
dep(dependent) andown(owner). If one argument (dependent), the other (owner) is impliedself. Both instances is a symbolic selection containing exactly one probe each.Parameters:
Returns:
-
Boolean
success
Usage:
-- Using static class a = Trace('test_main.c','thread_A',nil,1) b = Trace('test_main.c','thread_A',nil,2) Trace:set(a + b, 1) -- Enable both Trace:dprobe(a, b) -- Establish relation Trace:p_stat(a + b) -- Print current status of both -- 1 94660412502144 T 1 68615 3021884646707045 -- 2 94660412502208 T 1 68615 3021884651775924 5068879 0 94660412502144 -- 2
-- Equivalent with instances a = Trace('test_main.c','thread_A',nil,1) b = Trace('test_main.c','thread_A',nil,2) (a + b):set(1) -- Enable both a:dprobe(b) -- Establish relation (a + b):p_stat() -- Print current status of both -- 1 94660412502144 T 1 68615 3021884646707045 -- 2 94660412502208 T 1 68615 3021884651775924 5068879 0 94660412502144 -- 2
- trace:cast (elem)
-
cast Conditionally upcast if possible and needed
For a selection element
- Sub-scope it as a sub.table
- Decorate that table with a Trace meta-table, effectively making into a Trace-instance of 1
Parameters:
- elem Table A selection element
Returns:
-
Trace
An upcast Trace object
See also:
Usage:
A = Trace('.*','thread_A') a1 = A[1] print(A:cast(a1) -- { -- {100250159223264, "T", "test_main.c", "thread_A", 57} -- })
- trace:new (arg1, funcname, kind[, idx1[, idx2]])
-
new
Selection or copy/cast CTOR
- Return a new Trace object of selected probes. Identical to sel except that the return-type is a Trace-object for which methods can be applied
- If 1:st argument is a table, return a copy, optionally with sub-selected selection
Parameters:
- arg1 String
- funcname String
- kind String
- idx1 Integer Selection start index (optional)
- idx2 Integer Selection end index (optional)
Returns:
-
Trace
A Trace object instance
See also:
Usage:
-- Instance of a selection a = Trace('test_main.c','thread_A',nil,1) b = Trace('test_main.c','thread_A',nil,2) print(a + b) -- { -- {94660412502144, "T", "test_main.c", "thread_A", 56}, -- {94660412502208, "T", "test_main.c", "thread_A", 59} -- }
-- Instance of a sub-selection of selection A = Trace('.*main.c', nil, nil, 1, 2) print( A ) -- { -- {106297695531040, "T", "test_main.c", "thread_A", 57}, -- {106297695531104, "T", "test_main.c", "thread_A", 59} -- }
-- First probe from all threads matching filenames th = Trace('.*' , 'thread.*') p = Trace(th, '.*extra.*'):sub(1) print(p) -- { -- {106297695531808, "T", "test_extra_thread.c", "thread_C", 38} -- }
Metamethods
- trace:__add (rhs)
-
Operator
Returns the "set theory" join of two Trace objects, for example+(join)A+B.- Note: A
joinadds only elements fromBthat does not already exist inA.
Parameters:
Returns:
-
Trace
resulting union
Usage:
-- Trace objects J = Trace('test_main.c','thread_A') + Trace('test_main.c','thread_B') print(J) -- { -- {97803631514080, "T", "test_main.c", "thread_A", 57}, -- {97803631514016, "T", "test_main.c", "thread_A", 59}, -- {97803631514208, "T", "test_main.c", "thread_B", 69}, -- {97803631514144, "T", "test_main.c", "thread_B", 71} -- } print(J + J) -- Confirm that join of equal sets is the same as each set -- { -- {97803631514080, "T", "test_main.c", "thread_A", 57}, -- {97803631514016, "T", "test_main.c", "thread_A", 59}, -- {97803631514208, "T", "test_main.c", "thread_B", 69}, -- {97803631514144, "T", "test_main.c", "thread_B", 71} -- }
-- Indices of Trace objects A2 = Trace('.*','thread_A'):sub(2) B = Trace('.*','thread_B') print(A2 + B[2]) -- { -- {109638656360864, "T", "test_main.c", "thread_A", 59}, -- {109638656360992, "T", "test_main.c", "thread_B", 71} -- }
-- Indices (and instances) are added conditionally T = Trace('.*','thread_.*'):sub(1,6)-- Set of first 6 TP's from all threads C = Trace('.*','thread_C') -- All C's print(T + C[3]) -- C[3] is not part of T means set is -- allowed to grow -- { -- {99462699311712, "T", "test_main.c", "thread_B", 69}, -- {99462699311648, "T", "test_main.c", "thread_B", 71}, -- {99462699311584, "T", "test_main.c", "thread_A", 57}, -- {99462699311520, "T", "test_main.c", "thread_A", 59}, -- {99462699313120, "T", "test_extra_thread.c", "thread_C", 38}, -- {99462699313056, "T", "test_extra_thread.c", "thread_C", 39}, -- {99462699312992, "T", "test_extra_thread.c", "thread_C", 40} -- } -- -- I.e. to confirm: print(#T) -- 6 print(#(T + C[2])) -- 6 - C[2] is part of T, not allowed print(#(T + C[3])) -- 7 - C[3] is not of T, allowed
-- Either LHS or RHS can be a selection element A = Trace('.*','thread_A') B = Trace('.*','thread_B') print(A + B[1]) -- { -- {93935255593440, "T", "test_main.c", "thread_A", 57}, -- {93935255593376, "T", "test_main.c", "thread_A", 59}, -- {93935255593568, "T", "test_main.c", "thread_B", 69} -- } print(A[1] + B) -- { -- {93935255593440, "T", "test_main.c", "thread_A", 57}, -- {93935255593568, "T", "test_main.c", "thread_B", 69}, -- {93935255593504, "T", "test_main.c", "thread_B", 71} -- -- But not both print(A[1] + B[1]) --< ERROR
- Note: A
- trace:__sub (rhs)
-
Operator
-(subtracted intersection) Returns the "set theory" subtracted intersection of two Trace objects.Parameters:
Returns:
-
Trace
resulting set with subtracted intersection
Usage:
-- Trace objects S = Trace('test_main.c') - Trace('.*','thread_A') - Trace('.*','thread_B') print(S) -- { -- {97803631514336, "T", "test_main.c", "main", 131}, -- {97803631514272, "T", "test_main.c", "main", 134} -- }
-- Indices of Trace objects A = Trace('.*','thread_A') print(A - A[1]) -- { -- {109638656360864, "T", "test_main.c", "thread_A", 59} -- } -- -- Confirm correctness -- Note: technically not the same operation print(A:sub(2)) -- { -- {109638656360864, "T", "test_main.c", "thread_A", 59} -- }
- trace:__mod (rhs)
-
Operator
%(intersection) Returns the "set theory" true intersectionIn other words, the return is the set of elements that exists in both
LHSandRHSParameters:
Returns:
-
Trace
resulting true intersection
Usage:
-- Trace objects I = Trace('.*') % Trace('.*','thread_*') print(I) -- { -- {106856274690656, "T", "test_main.c", "thread_B", 69}, -- {106856274690592, "T", "test_main.c", "thread_B", 71}, -- {106856274690528, "T", "test_main.c", "thread_A", 57}, -- {106856274690464, "T", "test_main.c", "thread_A", 59}, -- {106856274692064, "T", "test_extra_thread.c", "thread_C", 38}, -- {106856274692000, "T", "test_extra_thread.c", "thread_C", 39}, -- {106856274691936, "T", "test_extra_thread.c", "thread_C", 40}, -- {106856274691872, "T", "test_extra_thread.c", "thread_C", 41}, -- {106856274691808, "T", "test_extra_thread.c", "thread_C", 42}, -- {106856274691744, "T", "test_extra_thread.c", "thread_C", 43}, -- {106856274691680, "T", "test_extra_thread.c", "thread_C", 44}, -- {106856274691616, "T", "test_extra_thread.c", "thread_C", 45}, -- {106856274691552, "T", "test_extra_thread.c", "thread_C", 46}, -- {106856274691488, "T", "test_extra_thread.c", "thread_C", 47} -- }
-- Indices of Trace objects -- -- This example may seem silly. Use-case is to check for existence -- T = Trace('.*','tread_.*'):sub(1,6) -- Set of first 6 TP's from all threads B = Trace('.*','thread_B') -- All B's C = Trace('.*','thread_C') -- All C's #(T % A[2]) -- 1 #(T % B[2]) -- 1 #(T % C[2]) -- 1 #(T % C[3]) -- 0 No, not part of T
- trace:__lt (rhs)
-
Operator
<(strictly contained) ReturnstrueorfalseifLHSis fully confined inRHSIn other words, for
A<Bto be true:- All elements of
Aexist inB - There MUST exist more elements in
Bthan inA - I.e.
AandBare guaranteed to NOT be equal when the expression evaluates to true (see __eq)
Note: Order in the compared sets does not matter
Parameters:
Returns:
-
Boolean
result
See also:
Usage:
T = Trace('.*', 'thread_.*'):sub(1,6) B = Trace('.*','thread_B') C = Trace('.*','thread_C') A = Trace('.*','thread_A') B < T -- true : B is fully part of T C < T -- false : C is not contained in T -- Either RHS or LHS can be a indexed selection, but not both C[1] < T -- true : C's 1'st element is C[3] < T -- false : C's 3'rd is not C[2] < T -- true : C's 2'nd is -- RHS indexed selection can only be true for LHS of one element T:sub(1) < B[1] -- true : T's 1's element is in B[1] T:sub(1) < B[2] -- false : ... but not in B[2] -- Strictly containd, i.e. but RHS has more B < T:sub(1,3) -- true B < T:sub(1,2) -- false : Because the're equal -- As can be seen in subtracted intersection T:sub(1,3) - B -- { -- {98855735558624, "T", "test_main.c", "thread_A", 57} -- }
- All elements of
- trace:__lte (rhs)
-
Operator
<=(contained by) ReturnstrueorfalseifLHSis fully confined inRHSIn other words, for
A<=Bto be true:- All elements of
Aexist inB AandBCOULD be equal (see __eq)
Note: Order in the compared sets does not matter
Parameters:
Returns:
-
Boolean
result
See also:
Usage:
T = Trace('.*', 'thread_.*'):sub(1,6) B = Trace('.*','thread_B') C = Trace('.*','thread_C') A = Trace('.*','thread_A') B <= T -- true : B is fully part of T C <= T -- false : C is not contained in T -- Either RHS or LHS can be a indexed selection, but not both C[1] <= T -- true : C's 1'st element is C[3] <= T -- false : C's 3'rd is not C[2] <= T -- true : C's 2'nd is -- RHS indexed selection can only be true for LHS of one element T:sub(1) <= B[1] -- true : T's 1's element is in B[1] T:sub(1) <= B[2] -- false : ... but not in B[2] -- At least containd, i.e. but RHS could be equal to LHS B <= T:sub(1,3) -- true B <= T:sub(1,2) -- true : Could be equal -- As can be seen in subtracted intersection T:sub(1,2) == B -- { -- {98855735558624, "T", "test_main.c", "thread_A", 57} -- }
- All elements of
- trace:__eq (rhs)
-
Operator
==(equal) Returnstrueorfalseif the setsLHSare equal toRHSIn other words, for
A==Bto be true:- All elements of
Aexist inB AandBare of same size
Note: Order in the compared sets does not matter
Parameters:
Returns:
-
Boolean
result
See also:
Usage:
T = Trace('.*', 'thread_.*'):sub(6,1) -- Reversed order on purpose B = Trace('.*','thread_B') C = Trace('.*','thread_C'):sub(1,2) T:sub(1,2) == C -- true Claimed equal despite order T:sub(1,2) == B -- false Nothing in common T:sub(1,3) == C -- false RHS is subset of LHS but larger T:sub(1) == C -- false Sizes differ -- Confirm equality: print(T:sub(1,2)) -- { -- {98946397284256, "T", "test_extra_thread.c", "thread_C", 39}, -- {98946397284320, "T", "test_extra_thread.c", "thread_C", 38} -- } print(C) -- Note the order -- { -- {98946397284320, "T", "test_extra_thread.c", "thread_C", 38}, -- {98946397284256, "T", "test_extra_thread.c", "thread_C", 39} -- }
- All elements of