From 4de80e7c4db612a98c4c5fde122a2965281fe8ea Mon Sep 17 00:00:00 2001 From: Tomas Fiedor Date: Thu, 20 Jun 2024 17:34:10 +0200 Subject: [PATCH 1/4] Fix sizes in flamegraphs and sankeys --- perun/profile/convert.py | 14 +++++++++----- perun/utils/common/common_kit.py | 20 ++++++++++++++++++++ perun/view/flamegraph/flamegraph.py | 24 ++++++++++++++---------- perun/view/flamegraph/run.py | 19 +++++-------------- perun/view_diff/flamegraph/run.py | 18 ++++-------------- perun/view_diff/report/run.py | 18 +++++++++++++----- tests/test_diff_views.py | 3 ++- tests/test_flame_graph.py | 3 ++- 8 files changed, 69 insertions(+), 50 deletions(-) diff --git a/perun/profile/convert.py b/perun/profile/convert.py index 9d5ac984e..90bb79f21 100644 --- a/perun/profile/convert.py +++ b/perun/profile/convert.py @@ -103,7 +103,9 @@ def models_to_pandas_dataframe(profile: Profile) -> pandas.DataFrame: return pandas.DataFrame(values) -def to_flame_graph_format(profile: Profile, profile_key: str = "amount") -> list[str]: +def to_flame_graph_format( + profile: Profile, profile_key: str = "amount", minimize: bool = False +) -> list[str]: """Transforms the **memory** profile w.r.t. :ref:`profile-spec` into the format supported by perl script of Brendan Gregg. @@ -129,6 +131,7 @@ def to_flame_graph_format(profile: Profile, profile_key: str = "amount") -> list :param Profile profile: the memory profile :param profile_key: key that is used to obtain the data + :param minimize: minimizes the uids :returns: list of lines, each representing one allocation call stack """ stacks = [] @@ -139,7 +142,7 @@ def to_flame_graph_format(profile: Profile, profile_key: str = "amount") -> list if alloc["uid"] != "%TOTAL_TIME%": stack_str = to_uid(alloc["uid"]) + ";" for frame in alloc["trace"][::-1]: - line = to_string_line(frame) + line = to_uid(frame, minimize) stack_str += line + ";" if stack_str and stack_str.endswith(";"): final = stack_str[:-1] @@ -149,16 +152,17 @@ def to_flame_graph_format(profile: Profile, profile_key: str = "amount") -> list return stacks -def to_uid(record: dict[str, Any] | str) -> str: +def to_uid(record: dict[str, Any] | str, minimize: bool = False) -> str: """Retrieves uid from record :param record: record for which we are retrieving uid :return: single string representing uid """ if isinstance(record, str): - return record + result = record else: - return to_string_line(record) + result = to_string_line(record) + return common_kit.hide_generics(result) if minimize else result def to_string_line(frame: dict[str, Any] | str) -> str: diff --git a/perun/utils/common/common_kit.py b/perun/utils/common/common_kit.py index f43df95de..cc320053e 100644 --- a/perun/utils/common/common_kit.py +++ b/perun/utils/common/common_kit.py @@ -583,4 +583,24 @@ def add_to_sorted( values.pop(0) +def hide_generics(uid: str) -> str: + """Hides the generics in the uid + + This transforms std::> into std::<*> + + :param uid: uid with generics + :return uid without generics + """ + nesting = 0 + chars = [] + for c in uid: + if c == "<": + nesting += 1 + elif c == ">": + nesting -= 1 + if nesting == 0 or (c == '<' and nesting == 1): + chars.append(c) + return "".join(chars) + + MODULE_CACHE: dict[str, types.ModuleType] = {} diff --git a/perun/view/flamegraph/flamegraph.py b/perun/view/flamegraph/flamegraph.py index d873c1d6d..0301b06f8 100644 --- a/perun/view/flamegraph/flamegraph.py +++ b/perun/view/flamegraph/flamegraph.py @@ -22,25 +22,28 @@ def draw_flame_graph_difference( lhs_profile: Profile, rhs_profile: Profile, - height: int, width: int = 1200, title: str = "", profile_key: str = "amount", + minimize: bool = False, ) -> str: """Draws difference of two flame graphs from two profiles :param lhs_profile: baseline profile :param rhs_profile: target_profile :param width: width of the graph - :param height: graphs height :param profile_key: key for which we are constructing profile :param title: if set to empty, then title will be generated """ # First we create two flamegraph formats - lhs_flame = convert.to_flame_graph_format(lhs_profile, profile_key=profile_key) + lhs_flame = convert.to_flame_graph_format( + lhs_profile, profile_key=profile_key, minimize=minimize + ) with open("lhs.flame", "w") as lhs_handle: lhs_handle.write("".join(lhs_flame)) - rhs_flame = convert.to_flame_graph_format(rhs_profile, profile_key=profile_key) + rhs_flame = convert.to_flame_graph_format( + rhs_profile, profile_key=profile_key, minimize=minimize + ) with open("rhs.flame", "w") as rhs_handle: rhs_handle.write("".join(rhs_flame)) @@ -56,7 +59,7 @@ def draw_flame_graph_difference( difference_script = ( f"{diff_script} -n lhs.flame rhs.flame " f"| {flame_script} --title '{title}' --countname {units} --reverse " - f"--width {width * 2} --height {height}" + f"--width {width * 2}" ) out, _ = commands.run_safely_external_command(difference_script) os.remove("lhs.flame") @@ -66,7 +69,11 @@ def draw_flame_graph_difference( def draw_flame_graph( - profile: Profile, height: int, width: int = 1200, title: str = "", profile_key: str = "amount" + profile: Profile, + width: int = 1200, + title: str = "", + profile_key: str = "amount", + minimize: bool = False, ) -> str: """Draw Flame graph from profile. @@ -75,12 +82,11 @@ def draw_flame_graph( :param profile: the memory profile :param width: width of the graph - :param height: graphs height :param profile_key: key for which we are constructing profile :param title: if set to empty, then title will be generated """ # converting profile format to format suitable to Flame graph visualization - flame = convert.to_flame_graph_format(profile, profile_key=profile_key) + flame = convert.to_flame_graph_format(profile, profile_key=profile_key, minimize=minimize) header = profile["header"] profile_type = header["type"] @@ -103,8 +109,6 @@ def draw_flame_graph( "--reverse", "--width", str(width), - "--height", - str(height), "--minwidth", "1", ] diff --git a/perun/view/flamegraph/run.py b/perun/view/flamegraph/run.py index a8cca6733..e41039a6b 100644 --- a/perun/view/flamegraph/run.py +++ b/perun/view/flamegraph/run.py @@ -1,4 +1,5 @@ """Flame graph visualization of the profiles.""" + from __future__ import annotations # Standard Imports @@ -12,14 +13,13 @@ import perun.profile.factory as profile_factory -def save_flamegraph(profile: profile_factory.Profile, filename: str, graph_height: int) -> None: +def save_flamegraph(profile: profile_factory.Profile, filename: str) -> None: """Draws and saves flamegraph to file :param profile: profile for which we are saving flamegraph :param filename: name of the file where the flamegraph will be saved - :param graph_height: height of the graph """ - flamegraph_content = flame.draw_flame_graph(profile, graph_height) + flamegraph_content = flame.draw_flame_graph(profile) with open(filename, "w") as file_handle: file_handle.write(flamegraph_content) @@ -31,17 +31,8 @@ def save_flamegraph(profile: profile_factory.Profile, filename: str, graph_heigh default="flame.svg", help="Sets the output file of the resulting flame graph.", ) -@click.option( - "--graph-height", - "-h", - default=20, - type=int, - help="Increases the width of the resulting flame graph.", -) @profile_factory.pass_profile -def flamegraph( - profile: profile_factory.Profile, filename: str, graph_height: int, **_: Any -) -> None: +def flamegraph(profile: profile_factory.Profile, filename: str, **_: Any) -> None: """Flame graph interprets the relative and inclusive presence of the resources according to the stack depth of the origin of resources. @@ -82,4 +73,4 @@ def flamegraph( :func:`perun.profile.convert.to_flame_graph_format` for more details how the profiles are converted to the flame graph format. """ - save_flamegraph(profile, filename, graph_height) + save_flamegraph(profile, filename) diff --git a/perun/view_diff/flamegraph/run.py b/perun/view_diff/flamegraph/run.py index 0d105a7d6..221bcab7c 100755 --- a/perun/view_diff/flamegraph/run.py +++ b/perun/view_diff/flamegraph/run.py @@ -20,7 +20,6 @@ from perun.view_diff.short import run as table_run -DEFAULT_HEIGHT: int = 14 DEFAULT_WIDTH: int = 600 TAGS_TO_INDEX: list[str] = [] @@ -114,16 +113,15 @@ def generate_flamegraphs( lhs_profile: Profile, rhs_profile: Profile, data_types: list[str], - height: int = DEFAULT_HEIGHT, width: int = DEFAULT_WIDTH, skip_diff: bool = False, + minimize: bool = False, ) -> list[tuple[str, str, str, str]]: """Constructs a list of tuples of flamegraphs for list of data_types :param lhs_profile: baseline profile :param rhs_profile: target profile :param data_types: list of data types (resources) - :param height: height of the flame graph :param width: width of the flame graph """ flamegraphs = [] @@ -132,20 +130,20 @@ def generate_flamegraphs( data_type = mapping.from_readable_key(dtype) lhs_graph = flamegraph_factory.draw_flame_graph( lhs_profile, - height, width, title="Baseline Flamegraph", profile_key=data_type, + minimize=minimize, ) escaped_lhs = escape_content(f"lhs_{i}", lhs_graph) log.minor_success(f"Baseline flamegraph ({dtype})", "generated") rhs_graph = flamegraph_factory.draw_flame_graph( rhs_profile, - height, width, title="Target Flamegraph", profile_key=data_type, + minimize=minimize, ) escaped_rhs = escape_content(f"rhs_{i}", rhs_graph) log.minor_success(f"Target flamegraph ({dtype})", "generated") @@ -156,10 +154,10 @@ def generate_flamegraphs( diff_graph = flamegraph_factory.draw_flame_graph_difference( lhs_profile, rhs_profile, - height, width, title="Difference Flamegraph", profile_key=data_type, + minimize=minimize, ) escaped_diff = escape_content(f"diff_{i}", diff_graph) log.minor_success(f"Diff flamegraph ({dtype})", "generated") @@ -188,7 +186,6 @@ def generate_flamegraph_difference( lhs_profile, rhs_profile, data_types, - kwargs.get("height", DEFAULT_HEIGHT), kwargs.get("width", DEFAULT_WIDTH), ) lhs_header, rhs_header = diff_kit.generate_headers(lhs_profile, rhs_profile) @@ -224,13 +221,6 @@ def generate_flamegraph_difference( default=DEFAULT_WIDTH, help="Sets the width of the flamegraph (default=600px).", ) -@click.option( - "-h", - "--height", - type=click.INT, - default=DEFAULT_HEIGHT, - help="Sets the height of the flamegraph (default=14).", -) @click.option("-o", "--output-file", help="Sets the output file (default=automatically generated).") def flamegraph(ctx: click.Context, *_: Any, **kwargs: Any) -> None: """ """ diff --git a/perun/view_diff/report/run.py b/perun/view_diff/report/run.py index 598b108cd..0edab2590 100755 --- a/perun/view_diff/report/run.py +++ b/perun/view_diff/report/run.py @@ -60,7 +60,7 @@ class Config: DefaultTopN: int = 10 DefaultRelativeThreshold: float = 0.01 - DefaultHeightCoefficient: int = 20 + DefaultHeightCoefficient: int = 50 def __init__(self) -> None: """Initializes the config @@ -71,6 +71,7 @@ def __init__(self) -> None: self.top_n_traces: int = self.DefaultTopN self.relative_threshold = self.DefaultRelativeThreshold self.max_seen_trace: int = 0 + self.minimize: bool = False @dataclass @@ -447,8 +448,8 @@ def process_traces( """ max_trace = 0 for _, resource in progressbar.progressbar(profile.all_resources()): - full_trace = [convert.to_uid(t) for t in resource["trace"]] - full_trace.append(convert.to_uid(resource["uid"])) + full_trace = [convert.to_uid(t, Config().minimize) for t in resource["trace"]] + full_trace.append(convert.to_uid(resource["uid"], Config().minimize)) trace_len = len(full_trace) max_trace = max(max_trace, trace_len) if trace_len > 1: @@ -619,6 +620,7 @@ def generate_sankey_difference(lhs_profile: Profile, rhs_profile: Profile, **kwa :param kwargs: additional arguments """ # We automatically set the value of True for kperf, which samples + Config().minimize = kwargs.get("minimize", False) Config().top_n_traces = kwargs.get("top_n", Config().DefaultTopN) Config().relative_threshold = kwargs.get( "filter_by_relative", Config().DefaultRelativeThreshold @@ -642,7 +644,7 @@ def generate_sankey_difference(lhs_profile: Profile, rhs_profile: Profile, **kwa rhs_profile, Stats.all_stats(), skip_diff=True, - height=Config().max_seen_trace, + minimize=Config().minimize, ) log.minor_success("Sankey graphs", "generated") lhs_header, rhs_header = diff_kit.generate_headers(lhs_profile, rhs_profile) @@ -678,7 +680,7 @@ def generate_sankey_difference(lhs_profile: Profile, rhs_profile: Profile, **kwa flamegraphs=flamegraphs, selection_table=selection_table, offline=config.lookup_key_recursively("showdiff.offline", False), - height=Config().max_seen_trace * Config().DefaultHeightCoefficient, + height=Config().max_seen_trace * Config().DefaultHeightCoefficient + 200, container_height=Config().max_seen_trace * Config().DefaultHeightCoefficient + 200, ) log.minor_success("HTML template", "rendered") @@ -707,6 +709,12 @@ def generate_sankey_difference(lhs_profile: Profile, rhs_profile: Profile, **kwa type=click.INT, default=Config().DefaultTopN, ) +@click.option( + "-m", + "--minimize", + is_flag=True, + help=f"Minimizes the traces, folds the recursive calls, hids the generic types.", +) @click.pass_context def report(ctx: click.Context, *_: Any, **kwargs: Any) -> None: """Creates sankey graphs representing the differences between two profiles""" diff --git a/tests/test_diff_views.py b/tests/test_diff_views.py index 02f51fc0f..95bac5b84 100755 --- a/tests/test_diff_views.py +++ b/tests/test_diff_views.py @@ -153,7 +153,8 @@ def test_diff_incremental_sankey_kperf(pcs_with_root): # Next try to create it using the click result = runner.invoke( - cli.showdiff, [baseline_profilename, target_profilename, "report", "-o", "diff.html"] + cli.showdiff, + [baseline_profilename, target_profilename, "report", "-o", "diff.html", "--minimize"], ) assert result.exit_code == 0 assert "diff.html" in os.listdir(os.getcwd()) diff --git a/tests/test_flame_graph.py b/tests/test_flame_graph.py index d7aa6fbd7..a8b8fb6e5 100644 --- a/tests/test_flame_graph.py +++ b/tests/test_flame_graph.py @@ -1,4 +1,5 @@ """Basic testing for the flame graph generation""" + from __future__ import annotations # Standard Imports @@ -24,7 +25,7 @@ def test_flame_graph(pcs_with_root, valid_profile_pool): memory_profile = test_utils.load_profile("to_add_profiles", "new-prof-2-memory-basic.perf") # First try to create the graph using the convential matters - flamegraph_run.save_flamegraph(memory_profile, "flame2.svg", 20) + flamegraph_run.save_flamegraph(memory_profile, "flame2.svg") assert "flame2.svg" in os.listdir(os.getcwd()) # Next try to create it using the click From e5b89306e2248c586cd2348d0594376abb4c2811 Mon Sep 17 00:00:00 2001 From: Tomas Fiedor Date: Thu, 20 Jun 2024 21:37:17 +0200 Subject: [PATCH 2/4] Make flamegraphs synchronized --- perun/scripts/flamegraph.pl | 14 ++++++++++---- perun/view/flamegraph/flamegraph.py | 3 +++ perun/view_diff/flamegraph/run.py | 6 ++++++ perun/view_diff/report/run.py | 13 +++++++------ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/perun/scripts/flamegraph.pl b/perun/scripts/flamegraph.pl index 61e30b2e9..16bd93371 100755 --- a/perun/scripts/flamegraph.pl +++ b/perun/scripts/flamegraph.pl @@ -104,6 +104,7 @@ my $fontsize = 12; # base text size my $fontwidth = 0.59; # avg width relative to fontsize my $minwidth = 0.1; # min function width, pixels or percentage of time +my $offset = 0; # offset added to rectangles (this is used to align two flamegraphs) my $nametype = "Function:"; # what are the names in the data? my $countname = "samples"; # what are the counts in the data? my $colors = "hot"; # color theme @@ -137,6 +138,7 @@ sub usage { --height NUM # height of each frame (default 16) --minwidth NUM # omit smaller functions. In pixels or use "%" for # percentage of time (default 0.1 pixels) + --offset NUM # offset of the start of the flamegraph from top (default 0) --fonttype FONT # font type (default "Verdana") --fontsize NUM # font size (default 12) --countname TEXT # count type label (default "samples") @@ -165,6 +167,7 @@ sub usage { 'fonttype=s' => \$fonttype, 'width=i' => \$imagewidth, 'height=i' => \$frameheight, + 'offset=i' => \$offset, 'encoding=s' => \$encoding, 'fontsize=f' => \$fontsize, 'fontwidth=f' => \$fontwidth, @@ -767,6 +770,9 @@ sub flow { } # draw canvas, and embed interactive JavaScript program +if ($offset != 0) { + $offset = ($offset + 1) * $frameheight; +} my $imageheight = (($depthmax + 1) * $frameheight) + $ypad1 + $ypad2; $imageheight += $ypad3 if $subtitletext ne ""; my $titlesize = $fontsize + 5; @@ -1135,11 +1141,11 @@ sub flow { $im->filledRectangle(0, 0, $imagewidth, $imageheight, 'url(#background)'); $im->stringTTF("title", int($imagewidth / 2), $fontsize * 2, $titletext); $im->stringTTF("subtitle", int($imagewidth / 2), $fontsize * 4, $subtitletext) if $subtitletext ne ""; -$im->stringTTF("details", $xpad, $imageheight - ($ypad2 / 2), " "); +$im->stringTTF("details", $xpad, $imageheight - ($ypad2 / 2) + $offset, " "); $im->stringTTF("unzoom", $xpad, $fontsize * 2, "Reset Zoom", 'class="hide"'); $im->stringTTF("search", $imagewidth - $xpad - 100, $fontsize * 2, "Search"); $im->stringTTF("ignorecase", $imagewidth - $xpad - 16, $fontsize * 2, "ic"); -$im->stringTTF("matched", $imagewidth - $xpad - 100, $imageheight - ($ypad2 / 2), " "); +$im->stringTTF("matched", $imagewidth - $xpad - 100, $imageheight - ($ypad2 / 2) + $offset, " "); if ($palette) { read_palette(); @@ -1209,7 +1215,7 @@ sub flow { } else { $color = color($colors, $hash, $func); } - $im->filledRectangle($x1, $y1, $x2, $y2, $color, 'rx="2" ry="2"'); + $im->filledRectangle($x1, $y1+$offset, $x2, $y2+$offset, $color, 'rx="2" ry="2"'); my $chars = int( ($x2 - $x1) / ($fontsize * $fontwidth)); my $text = ""; @@ -1221,7 +1227,7 @@ sub flow { $text =~ s//>/g; } - $im->stringTTF(undef, $x1 + 3, 3 + ($y1 + $y2) / 2, $text); + $im->stringTTF(undef, $x1 + 3, 3 + ($y1 + $y2) / 2 + $offset, $text); $im->group_end($nameattr); } diff --git a/perun/view/flamegraph/flamegraph.py b/perun/view/flamegraph/flamegraph.py index 0301b06f8..a5b7fa6c7 100644 --- a/perun/view/flamegraph/flamegraph.py +++ b/perun/view/flamegraph/flamegraph.py @@ -71,6 +71,7 @@ def draw_flame_graph_difference( def draw_flame_graph( profile: Profile, width: int = 1200, + offset: int = 0, title: str = "", profile_key: str = "amount", minimize: bool = False, @@ -109,6 +110,8 @@ def draw_flame_graph( "--reverse", "--width", str(width), + "--offset", + f"{offset}", "--minwidth", "1", ] diff --git a/perun/view_diff/flamegraph/run.py b/perun/view_diff/flamegraph/run.py index 221bcab7c..961e7a0bd 100755 --- a/perun/view_diff/flamegraph/run.py +++ b/perun/view_diff/flamegraph/run.py @@ -116,14 +116,18 @@ def generate_flamegraphs( width: int = DEFAULT_WIDTH, skip_diff: bool = False, minimize: bool = False, + offsets: list[int] = [0, 0], ) -> list[tuple[str, str, str, str]]: """Constructs a list of tuples of flamegraphs for list of data_types :param lhs_profile: baseline profile :param rhs_profile: target profile + :param minimize: whether the flamegraph should be minimized or not + :param offset: offset of start of drawing rectangles :param data_types: list of data types (resources) :param width: width of the flame graph """ + max_offset = max(offsets) flamegraphs = [] for i, dtype in enumerate(data_types): try: @@ -134,6 +138,7 @@ def generate_flamegraphs( title="Baseline Flamegraph", profile_key=data_type, minimize=minimize, + offset=abs(offsets[0] - max_offset), ) escaped_lhs = escape_content(f"lhs_{i}", lhs_graph) log.minor_success(f"Baseline flamegraph ({dtype})", "generated") @@ -144,6 +149,7 @@ def generate_flamegraphs( title="Target Flamegraph", profile_key=data_type, minimize=minimize, + offset=abs(offsets[1] - max_offset), ) escaped_rhs = escape_content(f"rhs_{i}", rhs_graph) log.minor_success(f"Target flamegraph ({dtype})", "generated") diff --git a/perun/view_diff/report/run.py b/perun/view_diff/report/run.py index 0edab2590..25320f35a 100755 --- a/perun/view_diff/report/run.py +++ b/perun/view_diff/report/run.py @@ -70,7 +70,7 @@ def __init__(self) -> None: self.trace_is_inclusive: bool = False self.top_n_traces: int = self.DefaultTopN self.relative_threshold = self.DefaultRelativeThreshold - self.max_seen_trace: int = 0 + self.max_seen_trace: list[int] = [] self.minimize: bool = False @@ -464,7 +464,7 @@ def process_traces( process_edge(graph, profile_type, resource, src, tgt) for uid in full_trace: graph.uid_to_traces[uid].append(full_trace) - Config().max_seen_trace = max(max_trace, Config().max_seen_trace) + Config().max_seen_trace.append(max_trace) def generate_trace_stats(graph: Graph) -> dict[str, list[TraceStat]]: @@ -612,7 +612,7 @@ def extract_stats_from_trace( return uid_trace_stats -def generate_sankey_difference(lhs_profile: Profile, rhs_profile: Profile, **kwargs: Any) -> None: +def generate_report(lhs_profile: Profile, rhs_profile: Profile, **kwargs: Any) -> None: """Generates differences of two profiles as sankey diagram :param lhs_profile: baseline profile @@ -645,6 +645,7 @@ def generate_sankey_difference(lhs_profile: Profile, rhs_profile: Profile, **kwa Stats.all_stats(), skip_diff=True, minimize=Config().minimize, + offsets=Config().max_seen_trace, ) log.minor_success("Sankey graphs", "generated") lhs_header, rhs_header = diff_kit.generate_headers(lhs_profile, rhs_profile) @@ -680,8 +681,8 @@ def generate_sankey_difference(lhs_profile: Profile, rhs_profile: Profile, **kwa flamegraphs=flamegraphs, selection_table=selection_table, offline=config.lookup_key_recursively("showdiff.offline", False), - height=Config().max_seen_trace * Config().DefaultHeightCoefficient + 200, - container_height=Config().max_seen_trace * Config().DefaultHeightCoefficient + 200, + height=max(Config().max_seen_trace) * Config().DefaultHeightCoefficient + 200, + container_height=max(Config().max_seen_trace) * Config().DefaultHeightCoefficient + 200, ) log.minor_success("HTML template", "rendered") output_file = diff_kit.save_diff_view( @@ -720,4 +721,4 @@ def report(ctx: click.Context, *_: Any, **kwargs: Any) -> None: """Creates sankey graphs representing the differences between two profiles""" assert ctx.parent is not None and f"impossible happened: {ctx} has no parent" profile_list = ctx.parent.params["profile_list"] - generate_sankey_difference(profile_list[0], profile_list[1], **kwargs) + generate_report(profile_list[0], profile_list[1], **kwargs) From 3f13ccf65e882edfb1f00f4e1bb40e984f04ed00 Mon Sep 17 00:00:00 2001 From: Tomas Fiedor Date: Fri, 21 Jun 2024 08:01:26 +0200 Subject: [PATCH 3/4] Add few tests --- perun/utils/common/cli_kit.py | 4 +--- .../profiles/diff_profiles/ktrace-target.perf | 20 ------------------- tests/test_utils.py | 2 ++ 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/perun/utils/common/cli_kit.py b/perun/utils/common/cli_kit.py index 0b9e073f8..260bdd43b 100644 --- a/perun/utils/common/cli_kit.py +++ b/perun/utils/common/cli_kit.py @@ -257,9 +257,7 @@ def vcs_path_callback(_: click.Context, __: click.Option, value: Any) -> Any: :param str value: value that is being read from the commandline :returns tuple: tuple of flags or parameters """ - if not value: - return common_kit.locate_dir_on(".", ".git") - return value + return common_kit.locate_dir_on(".", ".git") if not value else value def vcs_parameter_callback(ctx: click.Context, param: click.Option, value: Any) -> Any: diff --git a/tests/profiles/diff_profiles/ktrace-target.perf b/tests/profiles/diff_profiles/ktrace-target.perf index 43057f6c4..fef331fa8 100755 --- a/tests/profiles/diff_profiles/ktrace-target.perf +++ b/tests/profiles/diff_profiles/ktrace-target.perf @@ -2,7 +2,6 @@ "resources": { "reweight_entity#0": {}, "irqtime_account_irq#0": {}, - "idle_cpu#0": {}, "_raw_spin_lock_irqsave#0": {}, "_raw_spin_unlock_irqrestore#0": {}, "irq_enter_rcu#0": {}, @@ -665,25 +664,6 @@ "type": "stats", "uid": "irqtime_account_irq" }, - "idle_cpu#0": { - "Callees Mean [#]": 7.055339273128346e-07, - "Callees [#]": 403, - "E Max": 109753, - "E Mean": 0.0007409040272428077, - "E Min": 405, - "I Max": 254223, - "I Mean": 0.0007412849645448977, - "I Min": 405, - "Total Exclusive T [%]": 0.01486264104619905, - "Total Exclusive T [ms]": 570.90508, - "Total Inclusive T [%]": 0.014870282703112617, - "Total Inclusive T [ms]": 571.198612, - "ncalls": 770552, - "time": 38412088284, - "trace": [], - "type": "stats", - "uid": "idle_cpu" - }, "_raw_spin_lock_irqsave#0": { "Callees Mean [#]": 0.0, "Callees [#]": 0, diff --git a/tests/test_utils.py b/tests/test_utils.py index fe2211a76..689e351e1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -311,6 +311,8 @@ def simple_generator(): with pytest.raises(AssertionError): mapping.get_unit("unsupported") + assert common_kit.hide_generics("std::vector>") == "std::vector<>" + def test_predicates(capsys): """Test predicates used for testing""" From 5d0dd3c63d965a6d5affd896c1b1ebd53c878fa1 Mon Sep 17 00:00:00 2001 From: Tomas Fiedor Date: Fri, 21 Jun 2024 08:04:54 +0200 Subject: [PATCH 4/4] Fix codacy issue --- perun/view_diff/report/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perun/view_diff/report/run.py b/perun/view_diff/report/run.py index 25320f35a..1cf752270 100755 --- a/perun/view_diff/report/run.py +++ b/perun/view_diff/report/run.py @@ -714,7 +714,7 @@ def generate_report(lhs_profile: Profile, rhs_profile: Profile, **kwargs: Any) - "-m", "--minimize", is_flag=True, - help=f"Minimizes the traces, folds the recursive calls, hids the generic types.", + help="Minimizes the traces, folds the recursive calls, hids the generic types.", ) @click.pass_context def report(ctx: click.Context, *_: Any, **kwargs: Any) -> None: