self.sort_indices = [event_indices[event] for event in self.sort_events]
def mk_cc(self, text: str) -> Cc:
+ """Raises a `ValueError` exception on syntax error."""
# This is slightly faster than a list comprehension.
counts = list(map(int, text.split()))
# Used in various places in the output.
-FANCY: str = "-" * 80
+def print_fancy(text: str) -> None:
+ fancy = "-" * 80
+ print(fancy)
+ print("--", text)
+ print(fancy)
-def print_header(desc: str, cmd: str, events: Events) -> None:
- print(FANCY)
+def print_cachegrind_profile(desc: str, cmd: str, events: Events) -> None:
+ print_fancy("Cachegrind profile")
print(desc, end="")
print("Command: ", cmd)
print("Data file: ", args.cgout_filename[0])
print()
-def print_summary_cc(events: Events, summary_cc: Cc) -> None:
+def print_summary(events: Events, summary_cc: Cc) -> None:
printer = CcPrinter(events, [summary_cc], summary_cc)
-
- print(FANCY)
+ print_fancy("Summary")
printer.print_events("")
- print(FANCY)
+ print()
printer.print_cc(summary_cc, "PROGRAM TOTALS")
print()
-def print_flfn_ccs(
+def print_function_summary(
events: Events, dict_flfn_cc: DictFlfnCc, summary_cc: Cc
) -> set[str]:
# Only the first threshold percentage is actually used.
sorted_ccs = list(map(lambda flfn_and_cc: flfn_and_cc[1], sorted_flfns_and_ccs))
printer = CcPrinter(events, sorted_ccs, summary_cc)
-
- print(FANCY)
+ print_fancy("Function summary")
printer.print_events(" file:function")
- print(FANCY)
+ print()
# Print per-function counts.
for flfn, flfn_cc in sorted_flfns_and_ccs:
def warn_src_file_is_newer(src_filename: str, cgout_filename: str) -> None:
msg = f"""\
-@ Source file '{src_filename}' is more recent than input file '{cgout_filename}'.
+@ Source file '{src_filename}' is newer than data file '{cgout_filename}'.
@ Annotations may not be correct.
"""
print(mk_warning(msg))
def print_annotated_src_file(
events: Events,
- dict_line_cc: DictLineCc | None,
- ann_type: str,
+ dict_line_cc: DictLineCc,
src_file: TextIO,
annotated_ccs: AnnotatedCcs,
summary_cc: Cc,
) -> None:
- print(FANCY)
- print("-- ", ann_type, "-annotated source: ", src_file.name, sep="")
- print(FANCY)
-
- # Get file's CCs.
- if not dict_line_cc:
- print(f" No information has been collected for {src_file.name}")
- print()
- return
-
# If the source file is more recent than the cgout file, issue warning.
if os.stat(src_file.name).st_mtime_ns > os.stat(args.cgout_filename[0]).st_mtime_ns:
warn_src_file_is_newer(src_file.name, args.cgout_filename[0])
printer = CcPrinter(events, list(dict_line_cc.values()), summary_cc)
-
+ # The starting fancy has already been printed by the caller.
printer.print_events("")
print()
threshold_src_filenames: set[str],
dict_fl_dict_line_cc: DictFlDictLineCc,
summary_cc: Cc,
-) -> tuple[list[str], AnnotatedCcs]:
- unreadable_auto_filenames: list[str] = []
+) -> AnnotatedCcs:
annotated_ccs = AnnotatedCcs(events)
def pair_with(label: str) -> Callable[[str], tuple[str, str]]:
include_dirnames = args.include.copy()
include_dirnames.insert(0, "")
+ def print_ann_fancy(ann_type: str, src_filename: str) -> None:
+ print_fancy(f"{ann_type}-annotated source file: {src_filename}")
+
for src_filename, ann_type in sorted(all_src_filenames):
- annotated = False
+ readable = False
for include_dirname in include_dirnames:
if include_dirname == "":
full_src_filename = src_filename
try:
with open(full_src_filename, "r", encoding="utf-8") as src_file:
- # The pop will fail if it's a user-specified filename that
- # isn't mentioned in the cgout file.
- print_annotated_src_file(
- events,
- dict_fl_dict_line_cc.pop(src_filename, None),
- ann_type,
- src_file,
- annotated_ccs,
- summary_cc,
- )
- annotated = True
+ dict_line_cc = dict_fl_dict_line_cc.pop(src_filename, None)
+ if dict_line_cc is not None:
+ print_ann_fancy(ann_type, src_file.name) # includes full path
+ print_annotated_src_file(
+ events,
+ dict_line_cc,
+ src_file,
+ annotated_ccs,
+ summary_cc,
+ )
+ else:
+ # This only happens for user-specified files that are
+ # readable but not mentioned in the cgout file.
+ print_ann_fancy(ann_type, src_filename)
+ print("This file was not mentioned by the data file")
+ print()
+
+ readable = True
break
except OSError:
pass
- if not annotated:
- unreadable_auto_filenames.append(src_filename)
+ if not readable:
dict_line_cc = dict_fl_dict_line_cc.pop(src_filename, None)
add_dict_line_cc_to_cc(dict_line_cc, annotated_ccs.unreadable_cc)
+ print_ann_fancy(ann_type, src_filename)
+ print("This file was unreadable")
+ print()
+
# Sum the CCs remaining in `dict_fl_dict_line_cc`, which are all in files
# below the threshold.
for dict_line_cc in dict_fl_dict_line_cc.values():
add_dict_line_cc_to_cc(dict_line_cc, annotated_ccs.below_threshold_cc)
- return (unreadable_auto_filenames, annotated_ccs)
+ return annotated_ccs
-def print_unreadable_auto_filenames(unreadable_auto_filenames: list[str]) -> None:
- if unreadable_auto_filenames:
- print(FANCY)
- print("The following files chosen for auto-annotation could not be read:")
- print(FANCY)
- for filename in sorted(unreadable_auto_filenames):
- print(" ", filename)
- print()
-
-
-def print_annotated_ccs(
+def print_annotation_summary(
events: Events,
annotated_ccs: AnnotatedCcs,
summary_cc: Cc,
# lines above.
if args.auto or args.src_filenames:
printer = CcPrinter(events, annotated_ccs.ccs(), summary_cc)
- print(FANCY)
+ print_fancy("Annotation summary")
printer.print_events("")
- print(FANCY)
+ print()
total_cc = events.mk_empty_cc()
for (cc, label) in zip(annotated_ccs.ccs(), AnnotatedCcs.labels):
# Each of the following calls prints a section of the output.
- print_header(desc, cmd, events)
+ print_cachegrind_profile(desc, cmd, events)
- print_summary_cc(events, summary_cc)
+ print_summary(events, summary_cc)
- threshold_src_filenames = print_flfn_ccs(events, dict_flfn_cc, summary_cc)
+ threshold_src_filenames = print_function_summary(events, dict_flfn_cc, summary_cc)
- (unreadable_auto_filenames, annotated_ccs) = print_annotated_src_files(
+ annotated_ccs = print_annotated_src_files(
events, threshold_src_filenames, dict_fl_dict_line_cc, summary_cc
)
- print_unreadable_auto_filenames(unreadable_auto_filenames)
-
- print_annotated_ccs(events, annotated_ccs, summary_cc)
+ print_annotation_summary(events, annotated_ccs, summary_cc)
if __name__ == "__main__":
--------------------------------------------------------------------------------
+-- Cachegrind profile
+--------------------------------------------------------------------------------
Files compared: ann1.cgout; ann1b.cgout
Command: ./a.out; ./a.out
Data file: ann-diff.cgout
Auto-annotation: on
--------------------------------------------------------------------------------
-Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
+-- Summary
--------------------------------------------------------------------------------
+Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
+
5,000,000 (100.0%) 0 0 -2,000,000 (100.0%) 0 0 0 0 0 PROGRAM TOTALS
--------------------------------------------------------------------------------
-Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw file:function
+-- Function summary
--------------------------------------------------------------------------------
+Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw file:function
+
5,000,000 (100.0%) 0 0 -2,000,000 (100.0%) 0 0 0 0 0 a.c:main
--------------------------------------------------------------------------------
--- Auto-annotated source: a.c
+-- Auto-annotated source file: a.c
--------------------------------------------------------------------------------
Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
--------------------------------------------------------------------------------
-Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
+-- Annotation summary
--------------------------------------------------------------------------------
+Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
+
0 0 0 0 0 0 0 0 0 annotated: files known & above threshold & readable, line numbers known
5,000,000 (100.0%) 0 0 -2,000,000 (100.0%) 0 0 0 0 0 annotated: files known & above threshold & readable, line numbers unknown
0 0 0 0 0 0 0 0 0 unannotated: files known & above threshold & unreadable
--------------------------------------------------------------------------------
+-- Cachegrind profile
+--------------------------------------------------------------------------------
I1 cache: 32768 B, 64 B, 8-way associative
D1 cache: 32768 B, 64 B, 8-way associative
LL cache: 19922944 B, 64 B, 19-way associative
Auto-annotation: on
--------------------------------------------------------------------------------
-Ir I1mr ILmr
+-- Summary
--------------------------------------------------------------------------------
+Ir I1mr ILmr
+
5,229,753 952 931 PROGRAM TOTALS
--------------------------------------------------------------------------------
-Ir I1mr ILmr file:function
+-- Function summary
--------------------------------------------------------------------------------
+Ir I1mr ILmr file:function
+
5,000,015 1 1 a.c:main
47,993 19 19 /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:do_lookup_x
28,534 11 11 /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:_dl_lookup_symbol_x
6,898 2 2 /build/glibc-OTsEL5/glibc-2.27/elf/dl-misc.c:_dl_name_match_p
--------------------------------------------------------------------------------
--- Auto-annotated source: a.c
+-- Auto-annotated source file: /build/glibc-OTsEL5/glibc-2.27/elf/../sysdeps/x86_64/dl-machine.h
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: /build/glibc-OTsEL5/glibc-2.27/elf/dl-misc.c
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: /build/glibc-OTsEL5/glibc-2.27/elf/dl-tunables.c
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: /build/glibc-OTsEL5/glibc-2.27/elf/dl-tunables.h
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: /build/glibc-OTsEL5/glibc-2.27/elf/do-rel.h
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: /build/glibc-OTsEL5/glibc-2.27/string/../sysdeps/x86_64/strcmp.S
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: a.c
--------------------------------------------------------------------------------
Ir I1mr ILmr
2 0 0 }
--------------------------------------------------------------------------------
-The following files chosen for auto-annotation could not be read:
---------------------------------------------------------------------------------
- /build/glibc-OTsEL5/glibc-2.27/elf/../sysdeps/x86_64/dl-machine.h
- /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c
- /build/glibc-OTsEL5/glibc-2.27/elf/dl-misc.c
- /build/glibc-OTsEL5/glibc-2.27/elf/dl-tunables.c
- /build/glibc-OTsEL5/glibc-2.27/elf/dl-tunables.h
- /build/glibc-OTsEL5/glibc-2.27/elf/do-rel.h
- /build/glibc-OTsEL5/glibc-2.27/string/../sysdeps/x86_64/strcmp.S
-
+-- Annotation summary
--------------------------------------------------------------------------------
Ir I1mr ILmr
---------------------------------------------------------------------------------
+
5,000,015 1 1 annotated: files known & above threshold & readable, line numbers known
0 0 0 annotated: files known & above threshold & readable, line numbers unknown
179,512 136 134 unannotated: files known & above threshold & unreadable
--------------------------------------------------------------------------------
+-- Cachegrind profile
+--------------------------------------------------------------------------------
I1 cache: 32768 B, 64 B, 8-way associative
D1 cache: 32768 B, 64 B, 8-way associative
LL cache: 19922944 B, 64 B, 19-way associative
Auto-annotation: off
--------------------------------------------------------------------------------
-Dw Dr Ir
+-- Summary
--------------------------------------------------------------------------------
+Dw Dr Ir
+
18,005 (100.0%) 4,057,955 (100.0%) 5,229,753 (100.0%) PROGRAM TOTALS
--------------------------------------------------------------------------------
-Dw Dr Ir file:function
+-- Function summary
--------------------------------------------------------------------------------
+Dw Dr Ir file:function
+
3 (0.0%) 4,000,004 (98.6%) 5,000,015 (95.6%) a.c:main
4,543 (25.2%) 17,566 (0.4%) 47,993 (0.9%) /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:do_lookup_x
3,083 (17.1%) 5,750 (0.1%) 28,534 (0.5%) /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:_dl_lookup_symbol_x
0 5,158 (0.1%) 25,408 (0.5%) /build/glibc-OTsEL5/glibc-2.27/string/../sysdeps/x86_64/strcmp.S:strcmp
--------------------------------------------------------------------------------
--- User-annotated source: a.c
+-- User-annotated source file: a.c
--------------------------------------------------------------------------------
Dw Dr Ir
0 2 (0.0%) 2 (0.0%) }
--------------------------------------------------------------------------------
-Dw Dr Ir
+-- Annotation summary
--------------------------------------------------------------------------------
+Dw Dr Ir
+
3 (0.0%) 4,000,004 (98.6%) 5,000,015 (95.6%) annotated: files known & above threshold & readable, line numbers known
0 0 0 annotated: files known & above threshold & readable, line numbers unknown
0 0 0 unannotated: files known & above threshold & unreadable
--------------------------------------------------------------------------------
+-- Cachegrind profile
+--------------------------------------------------------------------------------
Command: ann2
Data file: ann2.cgout
Events recorded: A SomeCount VeryLongEventName
Auto-annotation: on
--------------------------------------------------------------------------------
-A SomeCount VeryLongEventName
+-- Summary
--------------------------------------------------------------------------------
+A SomeCount VeryLongEventName
+
100,000 (100.0%) 100,000 (100.0%) 0 PROGRAM TOTALS
--------------------------------------------------------------------------------
-A SomeCount VeryLongEventName file:function
+-- Function summary
--------------------------------------------------------------------------------
+A SomeCount VeryLongEventName file:function
+
70,091 (70.1%) 90,291 (90.3%) 0 ann2-basic.rs:f0
15,000 (15.0%) 600 (0.6%) 0 ann2-basic.rs:f1
9,000 (9.0%) 6,000 (6.0%) 0 ann2-could-not-be-found.rs:f1
500 (0.5%) 0 0 ann2-basic.rs:f4
--------------------------------------------------------------------------------
--- Auto-annotated source: ann2-basic.rs
+-- Auto-annotated source file: ann2-basic.rs
--------------------------------------------------------------------------------
A SomeCount VeryLongEventName
300 (0.3%) 0 0 twenty
--------------------------------------------------------------------------------
--- Auto-annotated source: ann2-more-recent-than-cgout.rs
+-- Auto-annotated source file: ann2-could-not-be-found.rs
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: ann2-more-recent-than-cgout.rs
--------------------------------------------------------------------------------
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ WARNING @@ WARNING @@ WARNING @@ WARNING @@ WARNING @@ WARNING @@ WARNING @@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-@ Source file 'ann2-more-recent-than-cgout.rs' is more recent than input file 'ann2.cgout'.
+@ Source file 'ann2-more-recent-than-cgout.rs' is newer than data file 'ann2.cgout'.
@ Annotations may not be correct.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-- line 4 ----------------------------------------
--------------------------------------------------------------------------------
--- Auto-annotated source: ann2-negatives.rs
+-- Auto-annotated source file: ann2-negatives.rs
--------------------------------------------------------------------------------
A SomeCount VeryLongEventName
-- line 13 ----------------------------------------
--------------------------------------------------------------------------------
--- Auto-annotated source: ann2-past-the-end.rs
+-- User-annotated source file: ann2-no-such-file.rs
+--------------------------------------------------------------------------------
+This file was unreadable
+
+--------------------------------------------------------------------------------
+-- Auto-annotated source file: ann2-past-the-end.rs
--------------------------------------------------------------------------------
A SomeCount VeryLongEventName
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
--------------------------------------------------------------------------------
--- User-annotated source: ann2-unmentioned.rs
+-- User-annotated source file: ann2-unmentioned.rs
--------------------------------------------------------------------------------
- No information has been collected for ann2-unmentioned.rs
+This file was not mentioned by the data file
--------------------------------------------------------------------------------
--- Auto-annotated source: ann2-aux/ann2-via-I.rs
+-- Auto-annotated source file: ann2-aux/ann2-via-I.rs
--------------------------------------------------------------------------------
A SomeCount VeryLongEventName
1,000 (1.0%) 500 (0.5%) 0 one
--------------------------------------------------------------------------------
-The following files chosen for auto-annotation could not be read:
---------------------------------------------------------------------------------
- ann2-could-not-be-found.rs
- ann2-no-such-file.rs
-
+-- Annotation summary
--------------------------------------------------------------------------------
A SomeCount VeryLongEventName
---------------------------------------------------------------------------------
+
84,500 (84.5%) 94,700 (94.7%) 990 (n/a) annotated: files known & above threshold & readable, line numbers known
5,100 (5.1%) -900 (-0.9%) -990 (n/a) annotated: files known & above threshold & readable, line numbers unknown
9,000 (9.0%) 6,000 (6.0%) 0 unannotated: files known & above threshold & unreadable