-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGetStats.py
128 lines (90 loc) · 3.78 KB
/
GetStats.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
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
#!/usr/bin/python
import os
import sys
import igraph
from myutils import functionsGraphsDirectoryName
import split2k
import numpy as np
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
myExt = ".gml"
Koptions = [1,2,3] #,4,5
tracePrints = True
sourceNames = ['getftp',"quotearg_buffer_restyled","sub_4047A0"]
BaseDir = os.path.join("..","workset","cloneWars","ALL")
sourcesDir = os.path.join(BaseDir,"sources")
targetsDir = os.path.join(BaseDir,"targets")
#import locale
#locale.setlocale(locale.LC_ALL, 'en_US')
import re
def comma_me(intAmount):
amount = str(intAmount)
orig = amount
new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', amount)
if orig == new:
return new
else:
return comma_me(new)
def printInt(myInt):
#return locale.format("%d",myInt,grouping=True)
return comma_me(myInt)
def getStats(collection):
if len(collection) == 0:
return "EMPTY (len==0)"
else:
return " Sum:[" + printInt(sum(collection)) + "],Min:[" + printInt(min(collection)) + "],Max:[" + printInt(max(collection)) + "],Avg:[" + printInt(np.mean(collection)) + "],STD:[" + printInt(np.std(collection)) + "]"
#target tracelets info - number of tracelets
print "Sources (paper targets)\n\n"
for sourceName in sourceNames:
refGraph = igraph.read(os.path.join(sourcesDir,sourceName) + myExt)
for k in Koptions:
counter = 0
for tracelet in split2k.ksplitGraphObject(k, refGraph , True):
counter += 1
print sourceName + ": K=" + str(k) + " , count = " + str(counter)
print "\n\nTargets (paper references)\n\n"
dictK = {}
for k in Koptions:
dictK[k] = {}
for collectionName in ["traceletPerFunctionInfo","opcodePerTraceletInfo","opcodePerBasicBlock","callsPerBB","callsPerTrace"]:
dictK[k][collectionName] = []
Degrees = {"VInDegree":[],"VOutDgree":[]}
BBInGraphs = []
for exeName in os.listdir(targetsDir):
numberOfFunctionsInTarget = 0
currentExeDir = os.path.join(targetsDir,os.path.join(exeName,functionsGraphsDirectoryName))
for funcFileName in filter(lambda x:x.endswith(myExt),os.listdir(currentExeDir)):
tarGraph = igraph.read(os.path.join(currentExeDir,funcFileName))
BBInGraphs.append(len(tarGraph.vs))
continue
for v in tarGraph.vs:
Degrees['VInDegree'].append(v.indegree())
Degrees['VOutDgree'].append(v.outdegree())
for k in Koptions:
traceletPerFunction = 0
dictUsed = dictK[k]
for tracelet in split2k.ksplitGraphObject(k, tarGraph , True):
traceletPerFunction +=1
BB = []
callsBB = []
for v in tracelet.vs:
opcodesInBB = v['code'].count(";")
BB.append(opcodesInBB)
dictUsed['opcodePerBasicBlock'].append(opcodesInBB)
callsInBB = v['code'].count("call ")
callsBB.append(callsInBB)
dictUsed['callsPerBB'].append(callsInBB)
dictUsed['opcodePerTraceletInfo'].append(sum(BB))
dictUsed['callsPerTrace'].append(sum(callsBB))
dictUsed['traceletPerFunctionInfo'].append(traceletPerFunction)
print "BBInGraphs" +":",
print getStats(BBInGraphs)
return
for k in Koptions:
print "Data for K=" + str(k)
dictUsed = dictK[k]
for collectionName in ["traceletPerFunctionInfo","opcodePerTraceletInfo","opcodePerBasicBlock","callsPerBB","callsPerTrace"]:
print collectionName +":",
print getStats(dictUsed[collectionName])
for key in Degrees.keys():
print key +":",
print getStats(Degrees[key])