Skip to content
Snippets Groups Projects
Commit 797da301 authored by Mikael Henriksson's avatar Mikael Henriksson :runner:
Browse files

Resource allocation drawing improvments (closes #173)

parent fc3fa764
No related branches found
No related tags found
No related merge requests found
Pipeline #89887 passed
...@@ -4,10 +4,15 @@ from typing import Dict, Iterable, List, Optional, Set, Tuple, TypeVar, Union ...@@ -4,10 +4,15 @@ from typing import Dict, Iterable, List, Optional, Set, Tuple, TypeVar, Union
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import networkx as nx import networkx as nx
from matplotlib.axes import Axes from matplotlib.axes import Axes
from matplotlib.markers import MarkerStyle
from matplotlib.ticker import MaxNLocator from matplotlib.ticker import MaxNLocator
from b_asic._preferences import LATENCY_COLOR
from b_asic.process import Process from b_asic.process import Process
# Default latency coloring RGB tuple
_LATENCY_COLOR = tuple(c / 255 for c in LATENCY_COLOR)
# #
# Human-intuitive sorting: # Human-intuitive sorting:
# https://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python # https://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
...@@ -129,6 +134,11 @@ class ProcessCollection: ...@@ -129,6 +134,11 @@ class ProcessCollection:
self, self,
ax: Optional[Axes] = None, ax: Optional[Axes] = None,
show_name: bool = True, show_name: bool = True,
bar_color: Union[str, Tuple[float, ...]] = _LATENCY_COLOR,
marker_color: Union[str, Tuple[float, ...]] = "black",
marker_read: str = "X",
marker_write: str = "o",
show_markers: bool = True,
): ):
""" """
Use matplotlib.pyplot to generate a process variable lifetime chart from this process collection. Use matplotlib.pyplot to generate a process variable lifetime chart from this process collection.
...@@ -140,6 +150,16 @@ class ProcessCollection: ...@@ -140,6 +150,16 @@ class ProcessCollection:
this method will return a new axes object on return. this method will return a new axes object on return.
show_name : bool, default: True show_name : bool, default: True
Show name of all processes in the lifetime chart. Show name of all processes in the lifetime chart.
bar_color : color, optional
Bar color in lifetime chart.
marker_color : color, default 'black'
Color for read and write marker.
marker_write : str, default 'x'
Marker at write time in the lifetime chart.
marker_read : str, default 'o'
Marker at read time in the lifetime chart.
show_markers : bool, default True
Show markers at read and write times.
Returns Returns
------- -------
...@@ -170,39 +190,42 @@ class ProcessCollection: ...@@ -170,39 +190,42 @@ class ProcessCollection:
bar_end = ( bar_end = (
process.start_time + process.execution_time process.start_time + process.execution_time
) % self._schedule_time ) % self._schedule_time
if process.execution_time == 0: bar_end = self._schedule_time if bar_end == 0 else bar_end
# Process has no execution time, draw a tick if show_markers:
_ax.scatter(x=bar_start, y=i + 1, marker='X', color='blue') _ax.scatter(
elif bar_end > bar_start: x=bar_start,
y=i + 1,
marker=marker_write,
color=marker_color,
zorder=10,
)
_ax.scatter(
x=bar_end,
y=i + 1,
marker=marker_read,
color=marker_color,
zorder=10,
)
if bar_end >= bar_start:
_ax.broken_barh( _ax.broken_barh(
[(PAD_L + bar_start, bar_end - bar_start - PAD_L - PAD_R)], [(PAD_L + bar_start, bar_end - bar_start - PAD_L - PAD_R)],
(i + 0.55, 0.9), (i + 0.55, 0.9),
color=bar_color,
) )
else: # bar_end < bar_start else: # bar_end < bar_start
if bar_end != 0: _ax.broken_barh(
_ax.broken_barh( [
[ (
( PAD_L + bar_start,
PAD_L + bar_start, self._schedule_time - bar_start - PAD_L,
self._schedule_time - bar_start - PAD_L, )
) ],
], (i + 0.55, 0.9),
(i + 0.55, 0.9), color=bar_color,
) )
_ax.broken_barh([(0, bar_end - PAD_R)], (i + 0.55, 0.9)) _ax.broken_barh(
else: [(0, bar_end - PAD_R)], (i + 0.55, 0.9), color=bar_color
_ax.broken_barh( )
[
(
PAD_L + bar_start,
self._schedule_time
- bar_start
- PAD_L
- PAD_R,
)
],
(i + 0.55, 0.9),
)
if show_name: if show_name:
_ax.annotate( _ax.annotate(
str(process), str(process),
......
test/baseline/test_draw_matrix_transposer_4.png

21 KiB | W: | H:

test/baseline/test_draw_matrix_transposer_4.png

26.8 KiB | W: | H:

test/baseline/test_draw_matrix_transposer_4.png
test/baseline/test_draw_matrix_transposer_4.png
test/baseline/test_draw_matrix_transposer_4.png
test/baseline/test_draw_matrix_transposer_4.png
  • 2-up
  • Swipe
  • Onion skin
test/baseline/test_draw_process_collection.png

14.7 KiB | W: | H:

test/baseline/test_draw_process_collection.png

14.7 KiB | W: | H:

test/baseline/test_draw_process_collection.png
test/baseline/test_draw_process_collection.png
test/baseline/test_draw_process_collection.png
test/baseline/test_draw_process_collection.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -13,7 +13,7 @@ class TestProcessCollectionPlainMemoryVariable: ...@@ -13,7 +13,7 @@ class TestProcessCollectionPlainMemoryVariable:
@pytest.mark.mpl_image_compare(style='mpl20') @pytest.mark.mpl_image_compare(style='mpl20')
def test_draw_process_collection(self, simple_collection): def test_draw_process_collection(self, simple_collection):
fig, ax = plt.subplots() fig, ax = plt.subplots()
simple_collection.draw_lifetime_chart(ax=ax) simple_collection.draw_lifetime_chart(ax=ax, show_markers=False)
return fig return fig
def test_draw_proces_collection(self, simple_collection): def test_draw_proces_collection(self, simple_collection):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment