show_percs: bool
annotate: bool
context: int
- include: list[str]
cgout_filename: list[str]
@staticmethod
help="print N lines of context before and after annotated lines "
"(default: %(default)s)",
)
- p.add_argument(
- "-I",
- "--include",
- action="append",
- default=[],
- metavar="D",
- help="add D to the list of searched source file directories",
- )
p.add_argument(
"cgout_filename",
nargs=1,
print("Events shown: ", *events.show_events)
print("Event sort order:", *events.sort_events)
print("Threshold: ", args.threshold)
-
- if len(args.include) == 0:
- print("Include dirs: ")
- else:
- print(f"Include dirs: {args.include[0]}")
- for include_dirname in args.include[1:]:
- print(f" {include_dirname}")
-
print("Annotation: ", "on" if args.annotate else "off")
print()
dict_line_cc = dict_fl_dict_line_cc.pop("???", None)
add_dict_line_cc_to_cc(dict_line_cc, annotated_ccs.files_unknown_cc)
- # Prepend "" to the include dirnames so things work in the case where the
- # filename has the full path.
- include_dirnames = args.include.copy()
- include_dirnames.insert(0, "")
-
def print_ann_fancy(src_filename: str) -> None:
print_fancy(f"Annotated source file: {src_filename}")
for src_filename in sorted(ann_src_filenames):
- readable = False
- for include_dirname in include_dirnames:
- if include_dirname == "":
- full_src_filename = src_filename
- else:
- full_src_filename = os.path.join(include_dirname, src_filename)
-
- try:
- with open(full_src_filename, "r", encoding="utf-8") as src_file:
- dict_line_cc = dict_fl_dict_line_cc.pop(src_filename, None)
- assert dict_line_cc is not None
- print_ann_fancy(src_file.name) # includes full path
- print_annotated_src_file(
- events,
- dict_line_cc,
- src_file,
- annotated_ccs,
- summary_cc,
- )
- readable = True
- break
- except OSError:
- pass
-
- if not readable:
+ try:
+ with open(src_filename, "r", encoding="utf-8") as src_file:
+ dict_line_cc = dict_fl_dict_line_cc.pop(src_filename, None)
+ assert dict_line_cc is not None
+ print_ann_fancy(src_filename)
+ print_annotated_src_file(
+ events,
+ dict_line_cc,
+ src_file,
+ annotated_ccs,
+ summary_cc,
+ )
+ except OSError:
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)
ann2.post.exp ann2.stderr.exp ann2.vgtest ann2.cgout \
ann2-basic.rs ann2-more-recent-than-cgout.rs \
ann2-negatives.rs ann2-past-the-end.rs \
- ann2-aux/ann2-via-I.rs \
chdir.vgtest chdir.stderr.exp \
clreq.vgtest clreq.stderr.exp \
dlclose.vgtest dlclose.stderr.exp dlclose.stdout.exp \
Events shown: Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Event sort order: Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Threshold: 0.1
-Include dirs:
Annotation: on
--------------------------------------------------------------------------------
Events shown: One Two
Event sort order: One Two
Threshold: 0.1
-Include dirs:
Annotation: on
--------------------------------------------------------------------------------
Events shown: A
Event sort order: A
Threshold: 0.1
-Include dirs:
Annotation: on
--------------------------------------------------------------------------------
Events shown: Ir I1mr ILmr
Event sort order: Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Threshold: 0.1
-Include dirs:
Annotation: on
--------------------------------------------------------------------------------
Events shown: Dw Dr Ir
Event sort order: Dr
Threshold: 0.1
-Include dirs:
Annotation: off
--------------------------------------------------------------------------------
one
two
three
+four
+five
# File with source newer than the cgout file.
fl=ann2-past-the-end.rs
-# This filename is repeated in ann2-could-not-be-found.rs above.
+# No `fn=` line yet, so the function name falls back to `<unspecified>`.
+1 1000 500 0
+# This funcname is repeated in ann2-could-not-be-found.rs above.
fn=f1
-1 200 100 0
+2 200 100 0
20 300 100 0
21 300 100 0
22 200 0 -1000
101 3000 2000 0
102 3000 2000 0
-# File found in ann2-aux/, via -I.
-fl=ann2-via-I.rs
-# No `fn=` line, so the function name falls back to `<unspecified>`.
-1 1000 500 0
-
# File below the threshold. (It also doesn't exist, but that doesn't matter. We
# don't try to open it because it's below the threshold.)
fl=ann2-below-threshold.rs
Events shown: A SomeCount VeryLongEventName
Event sort order: A SomeCount VeryLongEventName
Threshold: 0.5
-Include dirs: ann2-no-such-dir
- ann2-no-such-dir-2
- ann2-aux
Annotation: on
--------------------------------------------------------------------------------
> 9,000 (9.0%, 95.6%) 6,000 (6.0%, 99.0%) 0 (n/a, n/a) ann2-could-not-be-found.rs:f1
-> 1,000 (1.0%, 96.6%) 500 (0.5%, 99.5%) 0 (n/a, n/a) ann2-via-I.rs:<unspecified>
-
-> 1,000 (1.0%, 97.6%) 300 (0.3%, 99.8%) -1,000 (n/a, n/a) ann2-past-the-end.rs:f1
+> 2,000 (2.0%, 97.6%) 800 (0.8%, 99.8%) -1,000 (n/a, n/a) ann2-past-the-end.rs:
+ 1,000 (1.0%) 500 (0.5%) 0 <unspecified>
+ 1,000 (1.0%) 300 (0.3%) -1,000 (n/a) f1
> 1,000 (1.0%, 98.6%) 0 (0.0%, 99.8%) 0 (n/a, n/a) ann2-more-recent-than-cgout.rs:new
> 2,000 (2.0%, 95.1%) 100 (0.1%, 97.3%) 0 (n/a, n/a) f2:ann2-basic.rs
-> 1,000 (1.0%, 96.1%) 500 (0.5%, 97.8%) 0 (n/a, n/a) <unspecified>:ann2-via-I.rs
+> 1,000 (1.0%, 96.1%) 500 (0.5%, 97.8%) 0 (n/a, n/a) <unspecified>:ann2-past-the-end.rs
> 1,000 (1.0%, 97.1%) 0 (0.0%, 97.8%) 0 (n/a, n/a) unknown:???
--------------------------------------------------------------------------------
-- Annotated source file: ann2-past-the-end.rs
--------------------------------------------------------------------------------
-A_________ SomeCount_ VeryLongEventName
+A___________ SomeCount_ VeryLongEventName
-200 (0.2%) 100 (0.1%) 0 one
- . . . two
- . . . three
--- line 3 ----------------------------------------
+1,000 (1.0%) 500 (0.5%) 0 one
+ 200 (0.2%) 100 (0.1%) 0 two
+ . . . three
+ . . . four
+-- line 4 ----------------------------------------
-300 (0.3%) 100 (0.1%) 0 <bogus line 20>
-300 (0.3%) 100 (0.1%) 0 <bogus line 21>
-200 (0.2%) 0 -1,000 (n/a) <bogus line 22>
+ 300 (0.3%) 100 (0.1%) 0 <bogus line 20>
+ 300 (0.3%) 100 (0.1%) 0 <bogus line 21>
+ 200 (0.2%) 0 -1,000 (n/a) <bogus line 22>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ WARNING @@ WARNING @@ WARNING @@ WARNING @@ WARNING @@ WARNING @@ WARNING @@
@@ Information recorded about lines past the end of 'ann2-past-the-end.rs'.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
---------------------------------------------------------------------------------
--- Annotated source file: ann2-aux/ann2-via-I.rs
---------------------------------------------------------------------------------
-A___________ SomeCount_ VeryLongEventName
-
-1,000 (1.0%) 500 (0.5%) 0 one
-
--------------------------------------------------------------------------------
-- Annotation summary
--------------------------------------------------------------------------------
# The `sleep` is to ensure the mtime of the second touched file is greater than
# the mtime of the first touched file.
-post: touch ann2.cgout && sleep 0.1 && touch ann2-more-recent-than-cgout.rs && python3 ../cg_annotate --context 2 --annotate --show-percs=yes --threshold=0.5 -Iann2-no-such-dir --include ann2-no-such-dir-2 -I=ann2-aux ann2.cgout
+post: touch ann2.cgout && sleep 0.1 && touch ann2-more-recent-than-cgout.rs && python3 ../cg_annotate --context 2 --annotate --show-percs=yes --threshold=0.5 ann2.cgout
cleanup: rm cachegrind.out