]> sourceware.org Git - valgrind.git/commitdiff
Make section formatting more consistent.
authorNicholas Nethercote <n.nethercote@gmail.com>
Thu, 23 Mar 2023 08:36:47 +0000 (19:36 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Sun, 26 Mar 2023 22:01:38 +0000 (09:01 +1100)
- Every section now has a heading with the long `----` lines above and
  below.
- Event names are always shown below that heading, rather than within
  it.
- Each Unreadable file now gets its own section, much like files that
  lack any data.

cachegrind/cg_annotate.in
cachegrind/tests/ann-diff.post.exp
cachegrind/tests/ann1a.post.exp
cachegrind/tests/ann1b.post.exp
cachegrind/tests/ann2.post.exp

index bf09c36513c9d6fd78d10c5a88e1e708924c8d86..43dce8f10e447050db35c800ecd3f99e08014a9a 100755 (executable)
@@ -264,6 +264,7 @@ class Events:
         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()))
 
@@ -539,11 +540,15 @@ class CcPrinter:
 
 
 # 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])
@@ -570,17 +575,16 @@ def print_header(desc: str, cmd: str, events: Events) -> None:
     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.
@@ -607,10 +611,9 @@ def print_flfn_ccs(
     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:
@@ -666,7 +669,7 @@ def mk_warning(msg: str) -> str:
 
 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))
@@ -681,28 +684,17 @@ def warn_bogus_lines(src_filename: str) -> None:
 
 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()
 
@@ -783,8 +775,7 @@ def print_annotated_src_files(
     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]]:
@@ -810,8 +801,11 @@ def print_annotated_src_files(
     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
@@ -820,45 +814,45 @@ def print_annotated_src_files(
 
             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,
@@ -867,9 +861,9 @@ def print_annotated_ccs(
     # 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):
@@ -900,19 +894,17 @@ def main() -> None:
 
     # 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__":
index 986edf35ef53b34e5fde59aa372c426b0400f658..9f8f276ff1e1b9fb149f6249a14b03f6bc0bdd5e 100644 (file)
@@ -1,4 +1,6 @@
 --------------------------------------------------------------------------------
+-- Cachegrind profile
+--------------------------------------------------------------------------------
 Files compared:   ann1.cgout; ann1b.cgout
 Command:          ./a.out; ./a.out
 Data file:        ann-diff.cgout
@@ -11,17 +13,21 @@ User annotated:
 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 
 
@@ -29,8 +35,10 @@ 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 
index 05e9c5afa69163c2a4464d6ebdd4436f0acca2ad..b8a5f53b28419e70807e7c6ebbd5d49e994ffb33 100644 (file)
@@ -1,4 +1,6 @@
 --------------------------------------------------------------------------------
+-- 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
@@ -13,13 +15,17 @@ User annotated:
 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
@@ -31,7 +37,42 @@ Ir        I1mr ILmr  file:function
     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 
 
@@ -44,19 +85,10 @@ 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 
index 302416a44d34ea9b3dacb1a3474a7d3e861fb05b..4ad3a2eddf42f22723e12ddfecdb89867551f2b8 100644 (file)
@@ -1,4 +1,6 @@
 --------------------------------------------------------------------------------
+-- 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
@@ -13,13 +15,17 @@ User annotated:   a.c
 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
@@ -28,7 +34,7 @@ Dw            Dr                Ir                 file:function
     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                
 
@@ -41,8 +47,10 @@ 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 
index 204a472d3e51492d7bca6ed98269fcaf37bda5d1..315e13474de70d732b81afc99d1382cbe0024b40 100644 (file)
@@ -1,4 +1,6 @@
 --------------------------------------------------------------------------------
+-- Cachegrind profile
+--------------------------------------------------------------------------------
 Command:          ann2
 Data file:        ann2.cgout
 Events recorded:  A SomeCount VeryLongEventName
@@ -13,13 +15,17 @@ User annotated:   ann2-unmentioned.rs
 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
@@ -34,7 +40,7 @@ A              SomeCount         VeryLongEventName        file:function
    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 
 
@@ -62,12 +68,17 @@ 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.
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
@@ -80,7 +91,7 @@ A            SomeCount VeryLongEventName
 -- line 4 ----------------------------------------
 
 --------------------------------------------------------------------------------
--- Auto-annotated source: ann2-negatives.rs
+-- Auto-annotated source file: ann2-negatives.rs
 --------------------------------------------------------------------------------
 A                     SomeCount         VeryLongEventName       
 
@@ -102,7 +113,12 @@ 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       
 
@@ -122,26 +138,22 @@ 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 
This page took 0.050776 seconds and 5 git commands to generate.