-
Notifications
You must be signed in to change notification settings - Fork 24
/
benchmark.py
95 lines (82 loc) · 3.07 KB
/
benchmark.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
from spectrum_file import SpectrumFileReader
from scanner import Scanner
import sys
import Queue
from datetime import datetime, timedelta
import time
class AthBenchmark(object):
def __init__(self, iface):
self.scanner = Scanner(iface)
fn = '%s/spectral_scan0' % self.scanner.get_debugfs_dir()
self.file_reader = SpectrumFileReader(fn)
self.interface = iface
def get_samples(self, duration):
sps = 0
end = datetime.now() + timedelta(seconds=duration)
while datetime.now() < end:
try:
ts, samples = self.file_reader.sample_queue.get(timeout=0.1)
except Queue.Empty:
continue
sps += len(samples) / (17 + 56) # (header + payload in HT20)
print "total: %d sps" % sps
sps /= float(duration)
return sps
# count samples in chanscan
def benchmark_chanscan(self, duration=5, samplecount=8):
print "\nrun benchmark chanscan with samplecount=%d, duration=%d " % (samplecount, duration)
self.scanner.cmd_set_samplecount(samplecount)
self.scanner.mode_chanscan()
self.scanner.start()
sps = self.get_samples(duration=duration)
self.scanner.stop()
self.file_reader.flush()
print "%.2f sps, chanscan" % sps
return sps
# count samples in bg mode (w/o) load
def benchmark_background(self, duration=5):
print "\nrun benchmark background with duration=%d " % duration
self.scanner.mode_noninvasive_background()
self.scanner.dev_add_monitor()
self.scanner.start()
sps = self.get_samples(duration=duration)
self.scanner.stop()
self.file_reader.flush()
print "%.2f sps, background scan " % sps
return sps
def benchmark_manual(self, samplecount=127):
print "\nrun benchmark manual with samplecount=%d " % samplecount
self.scanner.mode_manual()
self.scanner.cmd_manual()
self.scanner.cmd_set_samplecount(samplecount)
self.scanner.dev_add_monitor()
self.scanner.cmd_trigger()
sps = 0
reread = 3
while reread:
try:
ts, samples = self.file_reader.sample_queue.get(timeout=0.1)
sps += len(samples) / (17 + 56) # (header + payload in HT20)
except Queue.Empty:
pass
reread -= 1
self.scanner.stop()
self.file_reader.flush()
print "got %d samples in manual mode" % sps
return sps
def main(self):
samplecount = [1, 10, 50, 100, 150, 200, 255]
for sc in samplecount:
sps = self.benchmark_chanscan( duration=5, samplecount=sc)
print "sps / samplecount: %.2f" % (sps / sc)
time.sleep(0.2)
self.benchmark_background(duration=5)
time.sleep(0.2)
self.benchmark_manual(samplecount=127)
time.sleep(0.2)
self.cleanup()
def cleanup(self):
# self.scanner.stop()
self.file_reader.stop()
if __name__ == '__main__':
AthBenchmark(sys.argv[1]).main()