Commit d9f7e20a authored by Joanne Hugé's avatar Joanne Hugé

Update parse-saleae-measures script

parent 7431d748
#!/usr/bin/python
import sys
import argparse
def line_to_ts(l):
ts_float = float(l.split(",")[0])
ts_ns = int(ts_float * 10**9)
def parseLine(l):
return ts_ns
(ts, ch0, ch1, *x) = l.split(", ")
if len(sys.argv) < 2:
print("You need to specify the csv file")
#tts = int(float(ts) * 10**9)
#if tts == 413415271100:
# print(ts)
# exit()
ts = int(float(ts) * 10**9)
return (ts, int(ch0), int(ch1))
def parsePulses(filename):
with open(filename, "r") as f:
lines = [l for l in f]
lines = lines[1:]
ch0Ts = []
ch1Ts = []
prevCh0Ts = -1
prevCh1Ts = -1
for l in lines:
(ts, ch0, ch1) = parseLine(l)
if ch0 == 1:
# Aggregate close timestamps as they represent the same pulse
if prevCh0Ts == -1 or (ts - prevCh0Ts) > 9000 * 1000:
ch0Ts.append(ts)
prevCh0Ts = ts
if ch1 == 1:
if prevCh1Ts == -1 or (ts - prevCh1Ts) > 9000 * 1000:
#if ts == 413415775140:
# print(prevCh1Ts)
# exit()
ch1Ts.append(ts)
prevCh1Ts = ts
# If there is an offset
if abs(ch0Ts[0] - ch1Ts[0]) > abs(ch0Ts[0] - ch1Ts[1]):
ch1Ts = ch1Ts[1:]
elif abs(ch0Ts[0] - ch1Ts[0]) > abs(ch0Ts[1] - ch1Ts[0]):
ch0Ts = ch0Ts[1:]
deltas = []
for i in range(min(len(ch0Ts), len(ch1Ts))):
deltas.append(ch0Ts[i] - ch1Ts[i])
max_d = max(deltas)
#for i in range(min(len(ch0Ts), len(ch1Ts))):
# if (ch0Ts[i] - ch1Ts[i]) == max_d:
# print((ch0Ts[i], ch1Ts[i]))
# exit()
return deltas
print("IO error")
exit()
filename=sys.argv[1]
def parseToggles(filename):
with open(filename, "r") as f:
with open(filename, "r") as f:
lines = [l for l in f]
lines = lines[1:]
values = [ line_to_ts(l) for l in lines]
......@@ -32,20 +86,50 @@ with open(filename, "r") as f:
exit()
deltas.append(values[i] - values[i-1])
return deltas
print("IO error")
exit()
def generateHistogram(deltas):
deltas = [abs(int(d / 1000)) for d in deltas]
min_d = min(deltas)
max_d = max(deltas)
avg_d = sum(deltas) / len(deltas)
for i in range(len(deltas)):
if deltas[i] == max_d:
print("Maximum delta at line {}".format(i))
histogram = [0 for i in range(max_d+1)]
for d in deltas:
histogram[d] += 1
for i,h in enumerate(histogram):
print("{:06d} {:15d}".format(i,h))
print("# Min: {}".format(min_d))
print("# Max: {}".format(max_d))
print("# Avg: {}".format(avg_d))
def parse_args():
parser = argparse
parser = argparse.ArgumentParser(description='Measure analysis')
parser.add_argument('-t', nargs=1, required=False, help='import json measures')
parser.add_argument('-p', nargs=1, required=False, help='import json measures')
args = parser.parse_args()
if args.t is not None:
print("# Shuttle-A20 synchronization histogram")
filename = args.t[0]
deltas = parseToggles(filename)
if args.p is not None:
filename = args.p[0]
print("# Shuttle synchronization histogram")
deltas = parsePulses(filename)
generateHistogram(deltas)
min_d = min_d / 1000
max_d = max_d / 1000
avg_d = avg_d / 1000
print("Min: {}us\n"
"Max: {}us\n"
"Avg: {}us".format(min_d,
max_d,
avg_d))
parse_args()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment