-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_itrace_vec
executable file
·47 lines (43 loc) · 1.1 KB
/
get_itrace_vec
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
#!/usr/bin/env python2.7
import tempfile
import numpy as np
import subprocess
import argparse
import json
import sys
import os
PIN_COMMAND = 'pin -t itrace -- %s%s'
class GetMap(object):
def __init__(self, p):
self.p = p
def __call__(self, x):
o = open('/dev/null', 'r')
f = tempfile.mkdtemp()
subprocess.call(PIN_COMMAND % (self.p, x), shell=True, cwd=f,stdout=o,stderr=subprocess.STDOUT)
nm = "%s/%s" % (f,"itrace.out")
u = open(nm, 'r')
buf = u.read()
u.close()
os.remove(nm)
os.rmdir(f)
return (x,buf)
def main(args):
infile,m = GetMap(args.program)(args.file)
maps_as_dicts = []
dmap = {}
for l in m.split("\n"):
lu = l.strip().rstrip()
if len(lu) > 0 and lu != "#eof":
a,b = lu.split(":")
dmap[str(a)] = int(b)
umap = {}
umap['file'] = args.file
umap['tuples'] = dmap
print json.dumps(umap)
return 0
if __name__ == '__main__':
parser = argparse.ArgumentParser("getstacks")
parser.add_argument("program", type=str)
parser.add_argument("file", type=str, help="input file")
args = parser.parse_args()
sys.exit(main(args))