-
Notifications
You must be signed in to change notification settings - Fork 15
/
sc_stats_multi.py
executable file
·78 lines (73 loc) · 2.19 KB
/
sc_stats_multi.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
#!/usr/bin/env python
#
# Program: $Id: $
# Author: Robert Beverly <rbeverly@nps.edu>
# Description: Multiprocessor version of sc_stats
#
import sys, os
import time
from sc_stats import WartsStats
from multiprocessing import Pool, Manager, Lock
def init():
global results, lock, dsts, ints, edges
manager = Manager()
lock = manager.Lock()
results = manager.dict()
results['files'] = 0
results['probes'] = 0
results['tvalmax'] = 0
results['tvalmin'] = 9999999999
dsts = manager.dict()
ints = manager.dict()
edges = manager.dict()
def dictadd(d,k,v=1):
if k not in d:
d[k] = 0
d[k]+=v
def doone(infile, _verbose=False):
print >> sys.stderr, "Doing:", infile
w = WartsStats(infile, verbose=_verbose)
(one_dsts, one_ints, one_edges, cnt) = w.stats(verbose=_verbose)
with lock:
print >> sys.stderr, "assimilating", infile
results['files']+=1
results['probes']+=cnt
if w.ts_end > results['tvalmax']: results['tvalmax'] = w.ts_end
if w.ts_begin < results['tvalmin']: results['tvalmin'] = w.ts_begin
with lock:
for i in one_dsts:
dictadd(dsts, i)
with lock:
for i in one_ints:
dictadd(ints, i)
with lock:
for i in one_edges:
dictadd(edges, i)
print >> sys.stderr, "done assimilating", infile
if __name__ == "__main__":
assert len(sys.argv) == 2
indir = sys.argv[1]
wartsfiles = []
if os.path.isdir(indir):
for root, subdirs, files in os.walk(indir):
for filename in sorted(files):
wartsfile = os.path.join(root, filename)
if wartsfile.find('.warts') != -1:
wartsfiles.append(wartsfile)
else:
print >> sys.stderr, "%s is not a directory." % indir
sys.exit(-1)
init()
pool = Pool()
pool.map(doone, wartsfiles)
pool.close()
pool.join()
print "Wartsfiles parsed: %d" % results['files']
print "Traces executed: %d" % results['probes']
print "Unique targets: %d" % (len(dsts))
print "Interfaces discovered: %d" % (len(ints))
print "Edges discovered: %d" % (len(edges))
print "Trace start: %s end: %s (%2.6f sec)" % \
(WartsStats.epochtostr(results['tvalmin']),
WartsStats.epochtostr(results['tvalmax']),
results['tvalmax'] - results['tvalmin'])