forked from aayasin/perf-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlbr_stats
executable file
·56 lines (50 loc) · 1.58 KB
/
lbr_stats
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
#!/usr/bin/env python
# stats re path to precise events
# Author: Ahmad Yasin
# edited: Sep. 2021
#
from __future__ import print_function
__author__ = 'ayasin'
from lbr import *
import common as C
dump_only = 0
c = {x: 0 for x in ('loop_head', 'loop_seq', 'loop_jmp2mid', 'loop_jmp2head', 'sequential', 'total')}
# usage: perf script -F +brstackinsn [--xed] | ./lbr_stats [ip-of-sample=ALL] [ip-of-loop=0]
ip = C.arg(1, 'ALL')
filter = None
if ip not in ('ALL', '-'):
filter = '%x'%int(ip, 16) #asserts in hexa
c['ip'] = '0x'+filter
loop = int(C.arg(2, '0'), 16)
while True:
sample = read_sample(ip_filter=filter, min_lines=2, loop_ipc=loop)
if not sample: break
assert len(sample) > 2, 'invalid sample: ' + str(sample)
if dump_only:
print_sample(sample, 0)
continue
c['total'] += 1
if not is_taken(sample[-2]): c['sequential'] += 1
if is_loop(sample[-1]):
c['loop_head'] += 1
if not is_taken(sample[-2]): c['loop_seq'] += 1
elif is_taken(sample[-2]) and is_jmp_next(get_taken(sample, -1)): c['loop_jmp2head'] += 1
br = get_taken(sample, -2)
ip = line_ip(sample[-1])
if br['to'] > ip and br['to'] <= get_loop(ip)['back']:
c['loop_jmp2mid'] += 1
continue
print_sample(sample, 22)
print_loop(ip)
print_br(br)
print(c)
print(stat)
exit(0)
if not dump_only:
print(c, C.ratio('sequential', c), C.ratio('loop_seq', c, 'loop_head'),
C.ratio('loop_jmp2mid', c, 'loop_head'), C.ratio('loop_jmp2head', c, 'loop_head'), sep=', ')
if filter:
print_loop(ip)
print(stat)
else:
print_all(loop_ipc=loop)