[go: up one dir, main page]

File: replay.lua

package info (click to toggle)
uftrace 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,212 kB
  • sloc: ansic: 53,313; python: 9,846; makefile: 838; asm: 703; cpp: 602; sh: 560; javascript: 191
file content (57 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download
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
function uftrace_begin(ctx)
    print('# DURATION     TID     FUNCTION')
end

function uftrace_entry(ctx)
    local _tid = ctx['tid']
    local _depth = ctx['depth']
    local _symname = ctx['name']

    local indent = _depth * 2
    local space = string.rep(' ', indent)

    local buf = string.format(' %10s [%6d] | %s%s() {', '', _tid, space, _symname)
    print(buf)
end

function uftrace_exit(ctx)
    local _tid = ctx['tid']
    local _depth = ctx['depth']
    local _symname = ctx['name']
    local _duration = ctx['duration']

    local indent = _depth * 2
    local space = string.rep(' ', indent)

    local time_and_unit = get_time_and_unit(_duration)
    local time = time_and_unit[1]
    local unit = time_and_unit[2]
    local buf = string.format(' %7.3f %s [%6d] | %s}', time, unit, _tid, space)
    local buf = string.format('%s /* %s */', buf, _symname)
    print(buf)
end

function uftrace_end()
end

function get_time_and_unit(duration)
    local duration = duration
    local time_unit = ''
    local divider

    if duration < 100 then
        divider = 1
        time_unit = 'ns'
    elseif duration < 1000000 then
        divider = 1000
        time_unit = 'us'
    elseif duration < 1000000000 then
        divider = 1000000
        time_unit = 'ms'
    else
        divider = 1000000000
        time_unit = ' s'
    end

    return {duration / divider, time_unit}
end