From: Nicholas Nethercote Date: Mon, 2 Oct 2023 21:11:42 +0000 (+1100) Subject: Minor tweaks for Python tooling updates. X-Git-Tag: VALGRIND_3_22_0~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a12e480c21cc973d45fb90ac42b8ced76e4b409b;p=thirdparty%2Fvalgrind.git Minor tweaks for Python tooling updates. Annoying that these are necessary, but that seems to be standard for this stuff. --- diff --git a/cachegrind/cg_annotate.in b/cachegrind/cg_annotate.in index 4d9d3e32cd..fe3f411818 100755 --- a/cachegrind/cg_annotate.in +++ b/cachegrind/cg_annotate.in @@ -50,6 +50,7 @@ def die(msg: str) -> NoReturn: SearchAndReplace = Callable[[str], str] + # A typed wrapper for parsed args. class Args(Namespace): # None of these fields are modified after arg parsing finishes. @@ -223,7 +224,7 @@ class Args(Namespace): p.print_usage(file=sys.stderr) die("argument --diff: requires exactly two Cachegrind output files") - return args0 + return args0 # type: ignore [return-value] # Args are stored in a global for easy access. @@ -318,6 +319,7 @@ class Events: # type is very hot and just using a type alias is much faster. Cc = list[int] + # Add the counts in `a_cc` to `b_cc`. def add_cc_to_cc(a_cc: Cc, b_cc: Cc) -> None: for i, a_count in enumerate(a_cc): @@ -375,6 +377,7 @@ def update_cc_extremes(self: Cc, min_cc: Cc, max_cc: Cc) -> None: # `--mod-funcname`. # - Mname/mname: modified name, used for what could be an Mfl or an Mfn. + # A deep cost centre with a dict for the inner mnames and CCs. class Dcc: outer_cc: Cc @@ -881,7 +884,7 @@ def print_mname_summary( print() # Print LCCs. - threshold_mnames = set([]) + threshold_mnames: set[str] = set([]) cumul_cc = events.mk_empty_cc() for mname, lcc in list_mname_lcc: add_cc_to_cc(lcc.outer_cc, cumul_cc) @@ -1090,9 +1093,7 @@ def print_annotated_src_files( # mtimes as if they are all as early as the earliest one. # Therefore, we warn only if the earliest source file is # more recent than the cgout file. - min_ofl_st_mtime_ns = min( - [os.stat(ofl).st_mtime_ns for ofl in ofls] - ) + min_ofl_st_mtime_ns = min(os.stat(ofl).st_mtime_ns for ofl in ofls) for cgout_filename in args.cgout_filename: if min_ofl_st_mtime_ns > os.stat(cgout_filename).st_mtime_ns: @@ -1155,7 +1156,7 @@ def print_annotation_summary( print() total_cc = events.mk_empty_cc() - for (cc, label) in zip(annotated_ccs.ccs(), AnnotatedCcs.labels): + for cc, label in zip(annotated_ccs.ccs(), AnnotatedCcs.labels): printer.print_cc(cc, None, label) add_cc_to_cc(cc, total_cc) diff --git a/cachegrind/cg_diff.in b/cachegrind/cg_diff.in index e193e99d78..acc5484f1a 100755 --- a/cachegrind/cg_diff.in +++ b/cachegrind/cg_diff.in @@ -128,12 +128,13 @@ class Args(Namespace): help="file produced by Cachegrind", ) - return p.parse_args(namespace=Args()) + return p.parse_args(namespace=Args()) # type: ignore [return-value] # Args are stored in a global for easy access. args = Args.parse() + # A single instance of this class is constructed, from `args` and the `events:` # line in the cgout file. class Events: @@ -172,6 +173,7 @@ class Events: # type is very hot and just using a type alias is much faster. Cc = list[int] + # Add the counts in `a_cc` to `b_cc`. def add_cc_to_cc(a_cc: Cc, b_cc: Cc) -> None: for i, a_count in enumerate(a_cc): diff --git a/cachegrind/cg_merge.in b/cachegrind/cg_merge.in index 1201114ded..7cc0f2b14b 100755 --- a/cachegrind/cg_merge.in +++ b/cachegrind/cg_merge.in @@ -74,12 +74,13 @@ class Args(Namespace): help="file produced by Cachegrind", ) - return p.parse_args(namespace=Args()) + return p.parse_args(namespace=Args()) # type: ignore [return-value] # Args are stored in a global for easy access. args = Args.parse() + # A single instance of this class is constructed, from `args` and the `events:` # line in the cgout file. class Events: