-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoprofile_wrapper.py
51 lines (39 loc) · 1.31 KB
/
oprofile_wrapper.py
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
import guest
import os
import arp
import subprocess
from lxml import etree
cycles = 100000
class OProfile:
def __init__(self):
os.system("opcontrol -e=LLC_REFS:%d -e=LLC_MISSES:%d -e=CPU_CLK_UNHALTED:%d -e=INST_RETIRED:%d" % ( cycles, cycles, cycles, cycles ) )
os.system("opcontrol --reset")
os.system("opcontrol --shutdown")
os.system("opcontrol --start")
def __del__(self):
os.system("opcontrol --shutdown")
def refresh(self):
os.system("opcontrol --dump")
def flush(self):
os.system("opcontrol --reset")
class OP_Data:
def __init__(self):
self.refs = 0
self.misses = 0
self.inst_retired = 0
self.cpu_clk_unhalted = 0
def get_measure(guest, mes_name):
args = ["opreport", "-l", "event:"+mes_name, "tid:"+str(guest.get_pid()), "--merge=cpu", "-X"]
p = subprocess.Popen( args, stdout = subprocess.PIPE, stderr = open( "/dev/null" ) )
p.wait()
data = ""
for line in p.stdout:
data = data + line + "\n"
try:
desc = etree.fromstring( data )
return int( desc.find("process/count").text )
except etree.XMLSyntaxError, e:
print data
return 0
if __name__ == "__main__":
oprofile = OProfile()