File: parse_sample.py

package info (click to toggle)
libtorrent-rasterbar 2.0.11-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 18,304 kB
  • sloc: cpp: 190,670; python: 7,142; makefile: 1,374; ansic: 574; sh: 317; xml: 104
file content (162 lines) | stat: -rwxr-xr-x 4,269 bytes parent folder | download | duplicates (4)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

import sys

# to use this script, first run 'sample' to sample your libtorrent based process
# the output can then be passed to this script to auto-fold call stacks at
# relevant depths and to filter out low sample counts
f = open(sys.argv[1])


def parse_line(line):
    indentation = 0
    while indentation < len(line) and line[indentation] == ' ':
        indentation += 1
    if indentation == 0:
        return (0, 0, '')

    line = line.strip().split(' ')
    samples = int(line[0])
    fun = ' '.join(line[1:])

    return (indentation, samples, fun)


fold = -1

try:
    sample_limit = int(sys.argv[2])
except Exception:
    sample_limit = 5

fun_samples = {}

for line in f:
    if 'Sort by top of stack' in line:
        break

    indentation, samples, fun = parse_line(line)
    if samples < sample_limit:
        continue
    if fold != -1 and indentation > fold:
        continue
    fold = -1

    if '__gnu_cxx::__normal_iterator<' in fun:
        fold = indentation - 1
        continue

    if 'boost::_bi::bind_t' in fun:
        continue
    if 'boost::_bi::list' in fun:
        continue
    if 'boost::_mfi::mf' in fun:
        continue
    if 'boost::_bi::storage' in fun:
        continue

# should only add leaves
    if fun in fun_samples:
        fun_samples[fun] += samples
    else:
        fun_samples[fun] = samples

    output = '%s%-4d %s' % (' ' * (indentation / 2), samples, fun)
    if len(output) > 200:
        output = output[0:200]
    print(output)

    if 'invariant_checker_impl' in fun:
        fold = indentation
    if 'free_multiple_buffers' in fun:
        fold = indentation
    if 'libtorrent::condition::wait' in fun:
        fold = indentation
    if 'allocate_buffer' in fun:
        fold = indentation
    if '::find_POD' in fun:
        fold = indentation
    if 'SHA1_Update' in fun:
        fold = indentation
    if 'boost::detail::function::basic_vtable' in fun:
        fold = indentation
    if 'operator new' in fun:
        fold = indentation
    if 'malloc' == fun:
        fold = indentation
    if 'free' == fun:
        fold = indentation
    if 'std::_Rb_tree' in fun:
        fold = indentation
    if 'pthread_cond_wait' in fun:
        fold = indentation
    if 'mp_exptmod' == fun:
        fold = indentation
    if '::check_invariant()' in fun:
        fold = indentation
    if 'libtorrent::condition::wait' in fun:
        fold = indentation
    if '_sigtramp' in fun:
        fold = indentation
    if 'time_now_hires' in fun:
        fold = indentation
    if 'libtorrent::sleep' in fun:
        fold = indentation
    if 'puts' == fun:
        fold = indentation
    if 'boost::asio::basic_stream_socket' in fun:
        fold = indentation
    if 'recvmsg' == fun:
        fold = indentation
    if 'sendmsg' == fun:
        fold = indentation
    if 'semaphore_signal_trap' == fun:
        fold = indentation
    if 'boost::detail::atomic_count::operator' in fun:
        fold = indentation
    if 'pthread_mutex_lock' == fun:
        fold = indentation
    if 'pthread_mutex_unlock' == fun:
        fold = indentation
    if '>::~vector()' == fun:
        fold = indentation
    if 'szone_free_definite_size' == fun:
        fold = indentation
    if 'snprintf' == fun:
        fold = indentation
    if 'usleep' == fun:
        fold = indentation
    if 'pthread_mutex_lock' == fun:
        fold = indentation
    if 'pthread_mutex_unlock' == fun:
        fold = indentation
    if 'std::string::append' in fun:
        fold = indentation
    if 'getipnodebyname' == fun:
        fold = indentation
    if '__gnu_debug::_Safe_iterator<std::' in fun:
        fold = indentation
    if 'fflush' == fun:
        fold = indentation
    if 'vfprintf' == fun:
        fold = indentation
    if 'fprintf' == fun:
        fold = indentation
    if 'BN_mod_exp' == fun:
        fold = indentation
    if 'BN_CTX_free' == fun:
        fold = indentation
    if 'cerror' == fun:
        fold = indentation
    if '0xffffffff' == fun:
        fold = indentation

list = []
for k in fun_samples:
    list.append((fun_samples[k], k))

list = sorted(list, reverse=True)

for i in list:
    print('%-4d %s' % (i[0], i[1]))