Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LARN
X-Lap
Commits
d4a0d13b
Commit
d4a0d13b
authored
Feb 14, 2018
by
Andreas Schmidt
Browse files
Improve latency code (graphviz, filtering, reformat).
parent
2ffc0736
Changes
1
Hide whitespace changes
Inline
Side-by-side
xlap/analyse/latency.py
View file @
d4a0d13b
...
...
@@ -4,6 +4,7 @@ from xlap.analyse.util import get_outlier_threshold, extract_durations, box
from
scipy.stats.stats
import
pearsonr
import
numpy
as
np
import
sys
import
graphviz
def
_get_thread_for_event
(
config
,
e
):
...
...
@@ -14,6 +15,7 @@ def _get_thread_for_event(config, e):
print
(
"Cannot find %s"
.
format
(
name
),
file
=
sys
.
stderr
)
return
None
def
_happens_before
(
df
,
a
,
b
,
config
):
"""
check if a happens-before b in the trace
...
...
@@ -35,12 +37,14 @@ def _happens_before(df, a, b, config):
# If in doubt, a and b are concurrent.
return
not
(
df
[
a
]
>=
df
[
b
]).
any
()
def
_fast_happens_before
(
df
,
a
,
b
,
hb
):
"""
check if a happens-before b, using a pre-computed relation
"""
return
any
(
r
[
'Start'
]
==
str
(
a
)
and
r
[
'End'
]
==
str
(
b
)
for
r
in
hb
)
def
_happens_directly_before
(
df
,
a
,
b
,
hb
):
"""
check if a happens-directly-before b in the trace
...
...
@@ -55,6 +59,7 @@ def _happens_directly_before(df, a, b, hb):
return
False
return
True
def
_locally_happens_directly_before
(
df
,
a
,
b
,
hb
,
config
):
"""
check if a happens-directly-before b in the trace but, be a little bit more
...
...
@@ -101,20 +106,19 @@ def _locally_happens_directly_before(df, a, b, hb, config):
else
:
return
_happens_directly_before
(
df
,
a
,
b
,
hb
)
def
_plot_controlflow_graph
(
df
,
hdb
):
"""
print
the control flow graph
in a format that dot understands
generate
the control flow graph
using dot
"""
print
(
"Digraph G {"
)
for
event1
in
df
:
if
not
str
(
event1
).
endswith
(
"_T"
):
continue
print
(
"
\t
_node__"
+
str
(
event1
)
+
"[label=
\"
"
+
str
(
event1
)[:
-
2
]
+
"
\"
]"
)
t_columns
=
[
x
for
x
in
df
.
columns
if
x
.
endswith
(
"_T"
)]
d
=
graphviz
.
Digraph
(
filename
=
"graph"
,
format
=
"pdf"
)
for
event1
in
df
[
t_columns
]:
d
.
node
(
str
(
event1
)[:
-
2
])
for
edge
in
hdb
:
print
(
"
\t
_node__"
+
edge
[
'Start'
]
+
" -> _node__"
+
edge
[
'End'
]
+
";"
)
#for edge in hdb:
# print("\t_node__"+edge['Start'] + " -> _node__"+edge['End'] + "[label=\""+str(edge['Correlation'])+"\"];")
print
(
"}"
)
d
.
edge
(
edge
[
"Start"
][:
-
2
],
edge
[
"End"
][:
-
2
])
d
.
render
()
# saves to graph.pdf in local folder
return
d
# Taken from: http://composition.al/blog/2015/11/29/a-better-way-to-add-labels-to-bar-charts-with-matplotlib/
...
...
@@ -133,7 +137,7 @@ def autolabel(rects, ax, labels):
# If we can fit the label above the column, do that;
# otherwise, put it inside the column.
if
p_width
>
0.50
:
# arbitrary; 95% looked good to me.
if
p_width
>
0.50
:
# arbitrary; 95% looked good to me.
label_position
=
width
-
(
x_width
)
+
0.7
color
=
"white"
align
=
"right"
...
...
@@ -143,64 +147,58 @@ def autolabel(rects, ax, labels):
ax
.
text
(
label_position
,
rect
.
get_y
(),
labels
[
i
],
ha
=
align
,
va
=
'bottom'
,
rotation
=
0
,
color
=
color
)
def
_plot_critical_regions
(
df
,
hdb
):
def
_plot_critical_regions
(
df
,
hdb
):
"""
plot regions, sorted by latency criticality
"""
plt
.
rcParams
[
"font.family"
]
=
"serif"
for
region
in
sorted
(
hdb
,
key
=
lambda
x
:
-
x
[
'Correlation'
]):
print
(
"%-10f %10s -> %10s"
%
(
region
[
'Correlation'
],
region
[
'Start'
],
region
[
'End'
]),
file
=
sys
.
stderr
)
relevant
=
sorted
([
x
for
x
in
hdb
if
x
[
'Correlation'
]
>
0
],
key
=
lambda
x
:
-
x
[
'Correlation'
],
reverse
=
True
)
x
=
np
.
arange
(
len
(
relevant
))
correlations
=
list
(
map
(
lambda
x
:
x
[
'Correlation'
],
relevant
))
ticks
=
list
(
map
(
lambda
x
:
"%s-%s"
%
(
x
[
'Start'
][:
-
2
],
x
[
'End'
][:
-
2
]),
relevant
))
fig
,
ax
=
plt
.
subplots
()
rects
=
ax
.
barh
(
x
,
correlations
,
align
=
"center"
,
tick_label
=
""
)
autolabel
(
rects
,
ax
,
ticks
)
# TODO: find a more elegant solution for the label text
plt
.
tight_layout
()
plt
.
savefig
(
"latency-criticality.pdf"
)
plt
.
close
()
def
analyse
(
df
,
config
):
hb
=
[]
for
event1
in
df
:
if
not
str
(
event1
).
endswith
(
"_T"
):
continue
print
(
str
(
event1
)
+
" ..."
,
file
=
sys
.
stderr
)
for
event2
in
df
:
if
not
str
(
event2
).
endswith
(
"_T"
):
continue
if
str
(
event1
)
==
str
(
event2
):
continue
if
_happens_before
(
df
,
event1
,
event2
,
config
):
hb
+=
[{
'Start'
:
str
(
event1
),
'End'
:
str
(
event2
)}]
hdb
=
[]
e2e
=
list
(
df
[
'EndToEnd_D'
])
for
event1
in
df
:
if
not
str
(
event1
).
endswith
(
"_T"
):
continue
for
event2
in
df
:
if
not
str
(
event2
).
endswith
(
"_T"
):
continue
if
str
(
event1
)
==
str
(
event2
):
continue
#if _locally_happens_directly_before(df, event1, event2, hb, config):
if
_happens_directly_before
(
df
,
event1
,
event2
,
hb
):
# compute the correlation between e2e latency and event1-event2 latency
l3
=
list
(
df
[
event2
]
-
df
[
event1
])
if
any
(
map
(
lambda
x
:
x
!=
0
,
l3
)):
correlation
=
pearsonr
(
l3
,
e2e
)[
0
]
else
:
correlation
=
0
hdb
+=
[{
'Start'
:
str
(
event1
),
'End'
:
str
(
event2
),
'Correlation'
:
correlation
}]
_plot_controlflow_graph
(
df
,
hdb
)
_plot_critical_regions
(
df
,
hdb
)
for
region
in
sorted
(
hdb
,
key
=
lambda
x
:
-
x
[
'Correlation'
]):
print
(
"%-10f %10s -> %10s"
%
(
region
[
'Correlation'
],
region
[
'Start'
],
region
[
'End'
]),
file
=
sys
.
stderr
)
relevant
=
sorted
([
x
for
x
in
hdb
if
x
[
'Correlation'
]
>
0
],
key
=
lambda
x
:
-
x
[
'Correlation'
],
reverse
=
True
)
x
=
np
.
arange
(
len
(
relevant
))
correlations
=
list
(
map
(
lambda
x
:
x
[
'Correlation'
],
relevant
))
ticks
=
list
(
map
(
lambda
x
:
"%s-%s"
%
(
x
[
'Start'
][:
-
2
],
x
[
'End'
][:
-
2
]),
relevant
))
fig
,
ax
=
plt
.
subplots
()
rects
=
ax
.
barh
(
x
,
correlations
,
align
=
"center"
,
tick_label
=
""
)
autolabel
(
rects
,
ax
,
ticks
)
plt
.
tight_layout
()
plt
.
savefig
(
"latency-criticality.pdf"
)
plt
.
close
()
def
analyse
(
df
,
config
):
hb
=
[]
events
=
[
column
for
column
in
df
.
columns
if
column
.
endswith
(
"_T"
)]
for
event1
in
df
[
events
]:
for
event2
in
df
[
events
]:
if
str
(
event1
)
==
str
(
event2
):
continue
if
_happens_before
(
df
,
event1
,
event2
,
config
):
hb
+=
[{
'Start'
:
str
(
event1
),
'End'
:
str
(
event2
)}]
hdb
=
[]
e2e
=
list
(
df
[
'EndToEnd_D'
])
for
event1
in
df
[
events
]:
for
event2
in
df
[
events
]:
if
str
(
event1
)
==
str
(
event2
):
continue
# if _locally_happens_directly_before(df, event1, event2, hb, config):
if
_happens_directly_before
(
df
,
event1
,
event2
,
hb
):
# compute the correlation between e2e latency and event1-event2 latency
l3
=
list
(
df
[
event2
]
-
df
[
event1
])
if
any
(
map
(
lambda
x
:
x
!=
0
,
l3
)):
correlation
=
pearsonr
(
l3
,
e2e
)[
0
]
else
:
correlation
=
0
hdb
+=
[{
'Start'
:
str
(
event1
),
'End'
:
str
(
event2
),
'Correlation'
:
correlation
}]
cfg
=
_plot_controlflow_graph
(
df
,
hdb
)
_plot_critical_regions
(
df
,
hdb
)
return
{
"cfg"
:
cfg
}
Write
Preview
Supports
Markdown
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