Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
tsn-measures
Commits
d9f7e20a
Commit
d9f7e20a
authored
Aug 27, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update parse-saleae-measures script
parent
7431d748
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
32 deletions
+116
-32
scripts/parse-saleae-measures.py
scripts/parse-saleae-measures.py
+116
-32
No files found.
scripts/parse-saleae-measures.py
View file @
d9f7e20a
#!/usr/bin/python
#!/usr/bin/python
import
sys
import
sys
import
argparse
def
line_to_ts
(
l
):
def
parseLine
(
l
):
ts_float
=
float
(
l
.
split
(
","
)[
0
])
ts_ns
=
int
(
ts_float
*
10
**
9
)
return
ts_ns
(
ts
,
ch0
,
ch1
,
*
x
)
=
l
.
split
(
", "
)
if
len
(
sys
.
argv
)
<
2
:
#tts = int(float(ts) * 10**9)
print
(
"You need to specify the csv file"
)
#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
()
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
=
[
l
for
l
in
f
]
lines
=
lines
[
1
:]
lines
=
lines
[
1
:]
values
=
[
line_to_ts
(
l
)
for
l
in
lines
]
values
=
[
line_to_ts
(
l
)
for
l
in
lines
]
...
@@ -32,20 +86,50 @@ with open(filename, "r") as f:
...
@@ -32,20 +86,50 @@ with open(filename, "r") as f:
exit
()
exit
()
deltas
.
append
(
values
[
i
]
-
values
[
i
-
1
])
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
)
min_d
=
min
(
deltas
)
max_d
=
max
(
deltas
)
max_d
=
max
(
deltas
)
avg_d
=
sum
(
deltas
)
/
len
(
deltas
)
avg_d
=
sum
(
deltas
)
/
len
(
deltas
)
for
i
in
range
(
len
(
deltas
)):
histogram
=
[
0
for
i
in
range
(
max_d
+
1
)]
if
deltas
[
i
]
==
max_d
:
print
(
"Maximum delta at line {}"
.
format
(
i
))
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
"
parse_args
()
"Max: {}us
\
n
"
"Avg: {}us"
.
format
(
min_d
,
max_d
,
avg_d
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment