Skip to content

Commit

Permalink
add render_header parameter to tree() (#66)
Browse files Browse the repository at this point in the history
- toggle tree header on/off
- update tests
  • Loading branch information
slabasan authored Oct 17, 2022
1 parent 057ce70 commit 7f5932b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hatchet/external/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def __init__(self, unicode=False, color=False):
self.visited = []

def render(self, roots, dataframe, **kwargs):
result = self.render_preamble()
self.render_header = kwargs["render_header"]

if self.render_header:
result = self.render_preamble()
else:
result = ""

if roots is None:
result += "The graph is empty.\n\n"
Expand Down
2 changes: 2 additions & 0 deletions hatchet/graphframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ def tree(
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
):
"""Format this graphframe as a tree and return the resulting string."""
color = sys.stdout.isatty()
Expand Down Expand Up @@ -934,6 +935,7 @@ def tree(
highlight_name=highlight_name,
colormap=colormap,
invert_colormap=invert_colormap,
render_header=render_header,
)

def to_dot(self, metric=None, name="name", rank=0, thread=0, threshold=0.0):
Expand Down
2 changes: 2 additions & 0 deletions hatchet/tests/caliper.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def test_tree(lulesh_caliper_json):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "121489.000 main" in output
assert "663.000 LagrangeElements" in output
Expand All @@ -195,6 +196,7 @@ def test_tree(lulesh_caliper_json):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "662712.000 EvalEOSForElems" in output
assert "2895319.000 LagrangeNodal" in output
Expand Down
2 changes: 2 additions & 0 deletions hatchet/tests/cprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_tree(hatchet_cycle_pstats):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "g pstats_reader_test.py" in output
assert "<method 'disable' ...Profiler' objects> ~" in output
Expand All @@ -62,6 +63,7 @@ def test_tree(hatchet_cycle_pstats):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "f pstats_reader_test.py" in output
assert re.match("(.|\n)*recursive(.|\n)*recursive", output)
8 changes: 8 additions & 0 deletions hatchet/tests/graphframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from hatchet.graph import Graph
from hatchet.node import Node
from hatchet.external.console import ConsoleRenderer
from hatchet.version import __version__


def test_copy(mock_graph_literal):
Expand Down Expand Up @@ -721,10 +722,12 @@ def test_tree(mock_graph_literal):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "0.000 foo" in output
assert "10.000 waldo" in output
assert "15.000 garply" in output
assert "v" + __version__ in output

output = ConsoleRenderer(unicode=True, color=False).render(
gf.graph.roots,
Expand All @@ -740,9 +743,11 @@ def test_tree(mock_graph_literal):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=False,
)
assert "55.000 waldo" in output
assert "15.000 garply" in output
assert "v" + __version__ not in output


def test_to_dot(mock_graph_literal):
Expand Down Expand Up @@ -798,6 +803,7 @@ def test_sub_decorator(small_mock1, small_mock2, small_mock3):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "0.000 C" in output
assert u"nan D ▶" in output
Expand Down Expand Up @@ -827,6 +833,7 @@ def test_sub_decorator(small_mock1, small_mock2, small_mock3):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "15.000 A" in output
assert u"5.000 C ◀" in output
Expand Down Expand Up @@ -861,6 +868,7 @@ def test_div_decorator(small_mock1, small_mock2):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "1.000 C" in output
assert "inf B" in output
Expand Down
2 changes: 2 additions & 0 deletions hatchet/tests/hpctoolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def test_tree(calc_pi_hpct_db):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "0.000 <program root> <unknown file>" in output
assert (
Expand All @@ -136,6 +137,7 @@ def test_tree(calc_pi_hpct_db):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "17989.000 interp.c:0 interp.c" in output
assert (
Expand Down
2 changes: 2 additions & 0 deletions hatchet/tests/pyinstrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_tree(hatchet_pyinstrument_json):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "0.000 <module> examples.py" in output
assert "0.025 read hatchet/readers/caliper_reader.py" in output
Expand All @@ -109,6 +110,7 @@ def test_tree(hatchet_pyinstrument_json):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "0.478 <module> examples.py" in output
assert "0.063 from_caliper_json hatchet/graphframe.py" in output
Expand Down
2 changes: 2 additions & 0 deletions hatchet/tests/tau.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_tree(tau_profile_dir):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "449.000 .TAU application" in output
assert "4458.000 MPI_Finalize()" in output
Expand All @@ -63,6 +64,7 @@ def test_tree(tau_profile_dir):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)
assert "419.000 .TAU application" in output
assert "4894.000 MPI_Finalize()" in output
Expand Down
2 changes: 2 additions & 0 deletions hatchet/tests/timemory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_tree(timemory_json_data):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)

print(output)
Expand All @@ -76,6 +77,7 @@ def test_tree(timemory_json_data):
highlight_name=False,
colormap="RdYlGn",
invert_colormap=False,
render_header=True,
)

print(output)
Expand Down

0 comments on commit 7f5932b

Please sign in to comment.