Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MessdatenSilo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lennard Kloock
MessdatenSilo
Commits
dca944df
Commit
dca944df
authored
Jun 9, 2022
by
Lennard
Browse files
Options
Downloads
Patches
Plain Diff
Update measure.py
parent
8647a313
No related branches found
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
measure.py
+25
-15
25 additions, 15 deletions
measure.py
with
25 additions
and
15 deletions
measure.py
+
25
−
15
View file @
dca944df
...
...
@@ -33,34 +33,38 @@ prof_logger.addHandler(handler)
install_mp_handler
(
prof_logger
)
def
log_event
(
**
kwargs
):
prof_logger
.
debug
(
json
.
dumps
(
kwargs
))
def
time_usec
()
->
int
:
return
int
(
round
(
1e6
*
time
.
time
()))
base_info
=
{
"
pid
"
:
os
.
getpid
(),
"
tid
"
:
threading
.
current_thread
().
ident
,
}
def
log_profile
(
category
:
str
=
None
):
def
decorator
(
f
):
@wraps
(
f
)
def
wrapper
(
*
args
,
**
kwargs
):
# format compatible with chrome://tracing
# info: https://www.gamasutra.com/view/news/176420/Indepth_Using_Chrometracing_to_view_your_inline_profiling_data.php
base_info
=
{
"
name
"
:
f
.
__name__
,
"
pid
"
:
os
.
getpid
(),
"
tid
"
:
threading
.
current_thread
().
ident
,
"
cat
"
:
category
,
}
def
log_event
(
**
kwargs
):
prof_logger
.
debug
(
json
.
dumps
(
kwargs
))
def
time_usec
():
return
int
(
round
(
1e6
*
time
.
time
()))
args_str
=
{
i
:
f
"
{
arg
}
"
for
i
,
arg
in
enumerate
(
args
)}
start_time
=
time_usec
()
log_event
(
ph
=
"
B
"
,
ts
=
start_time
,
**
base_info
)
log_event
(
ph
=
"
B
"
,
ts
=
start_time
,
name
=
f
.
__name__
,
cat
=
category
,
args
=
args_str
,
**
base_info
)
result
=
f
(
*
args
,
**
kwargs
)
end_time
=
time_usec
()
duration
=
end_time
-
start_time
# TODO: duration could possibly be computed afterwards (if we can pair the events correctly)
log_event
(
ph
=
"
E
"
,
ts
=
end_time
,
duration
=
duration
,
**
base_info
)
log_event
(
ph
=
"
E
"
,
ts
=
end_time
,
duration
=
duration
,
name
=
f
.
__name__
,
cat
=
category
,
args
=
args_str
,
**
base_info
)
return
result
...
...
@@ -75,10 +79,15 @@ def convert_log_to_trace(log_file, trace_file):
json
.
dump
({
"
traceEvents
"
:
events
},
output
)
@log_profile
(
"
compute
"
)
@log_profile
(
"
read_value
"
)
def
read_value
(
connection
:
serial
.
Serial
)
->
bytes
:
return
connection
.
readline
()
@log_profile
(
"
read
"
)
def
read
(
connection
:
serial
.
Serial
):
for
_
in
range
(
4
):
recv1
=
connection
.
readline
(
)
recv1
=
read_value
(
connection
)
float
(
convert
(
recv1
))
...
...
@@ -112,6 +121,7 @@ def get_data(con1: serial.Serial, con2: serial.Serial):
except
(
TypeError
,
ValueError
):
# may occur if no data was read over serial
log_event
(
ph
=
"
I
"
,
ts
=
time_usec
(),
name
=
"
NoData
"
,
cat
=
"
NoData
"
,
**
base_info
)
print
(
"
Didn
'
t receive data from arduino
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment