Skip to content

Commit 927471c

Browse files
committed
CMD: add option to annotate stats
1 parent 7072335 commit 927471c

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

chb/app/AppResultFunctionMetrics.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# Copyright (c) 2016-2020 Kestrel Technology LLC
88
# Copyright (c) 2020 Henny Sipma
9-
# Copyright (c) 2021 Aarno Labs LLC
9+
# Copyright (c) 2021-2025 Aarno Labs LLC
1010
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal
@@ -28,7 +28,7 @@
2828
# ------------------------------------------------------------------------------
2929
import xml.etree.ElementTree as ET
3030

31-
from typing import Dict, Optional, TYPE_CHECKING
31+
from typing import Dict, List, Optional, TYPE_CHECKING
3232

3333
import chb.util.fileutil as UF
3434

@@ -236,22 +236,27 @@ def as_dictionary(self) -> Dict[str, str]:
236236
def metrics_to_string(
237237
self,
238238
shownocallees: bool = False,
239-
space: str = " ") -> str:
239+
space: str = " ",
240+
annotations: List[str] = []) -> str:
240241
callcount = ''
241242
name = ''
242243
unrc = ''
244+
anns = ""
243245
if shownocallees and (not self.has_name()):
244246
if self.call_count == 0:
245247
callcount = ' (no callees)'
246248
if self.has_name():
247249
name = ' (' + self.name + ')'
248250
if self.unresolved_call_count > 0:
249251
unrc = str(self.unresolved_call_count)
252+
if len(annotations) > 0:
253+
anns = " [" + ", ".join(annotations) + "]"
254+
250255
return (str(self.faddr).ljust(10) + space
251256
+ '{:6.1f}'.format(self.espp) + space
252257
+ '{:6.1f}'.format(self.readsp) + space
253258
+ '{:6.1f}'.format(self.writesp) + space
254259
+ unrc.rjust(6) + space
255260
+ str(self.block_count).rjust(6) + space
256261
+ str(self.instruction_count).rjust(6) + space
257-
+ '{:8.3f}'.format(self.time) + name + callcount)
262+
+ '{:8.3f}'.format(self.time) + name + callcount + anns)

chb/app/AppResultMetrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# Copyright (c) 2016-2020 Kestrel Technology LLC
88
# Copyright (c) 2020 Henny Sipma
9-
# Copyright (c) 2021-2024 Aarno Labs LLC
9+
# Copyright (c) 2021-2025 Aarno Labs LLC
1010
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal

chb/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chbversion: str = "0.3.0-20250325"
1+
chbversion: str = "0.3.0-20250326"

chb/cmdline/chkx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,9 @@ def parse() -> argparse.Namespace:
612612
"--opcodes",
613613
help=("json filename (without extension) to save opcode distribution "
614614
+ "stats (for instructions within analyzed functions)"))
615+
resultsstats.add_argument(
616+
"--annotationfile",
617+
help="name of json file that has function annotations")
615618
resultsstats.add_argument(
616619
"--loglevel", "-log",
617620
choices=UL.LogLevel.options(),

chb/cmdline/commandutil.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ def results_stats(args: argparse.Namespace) -> NoReturn:
619619
sortby: str = args.sortby
620620
timeshare: int = args.timeshare
621621
opcodes: str = args.opcodes
622+
annotationfile: str = str(args.annotationfile)
622623
loglevel: str = args.loglevel
623624
logfilename: Optional[str] = args.logfilename
624625
logfilemode: str = args.logfilemode
@@ -637,6 +638,15 @@ def results_stats(args: argparse.Namespace) -> NoReturn:
637638
mode=logfilemode,
638639
msg="results stats invoked")
639640

641+
annotations: Dict[str, List[str]] = {}
642+
if annotationfile is not None:
643+
with open(annotationfile, "r") as fp:
644+
annotationdata = json.load(fp)
645+
for (key, flist) in annotationdata["keys"].items():
646+
for faddr in flist:
647+
annotations.setdefault(faddr, [])
648+
annotations[faddr].append(key)
649+
640650
xinfo = XI.XInfo()
641651
xinfo.load(path, xfile)
642652

@@ -655,7 +665,12 @@ def results_stats(args: argparse.Namespace) -> NoReturn:
655665
else:
656666
sortkey = lambda f: int(f.faddr, 16)
657667
for f in sorted(stats.get_function_results(), key=sortkey):
658-
print(f.metrics_to_string(shownocallees=nocallees))
668+
if f.faddr in annotations:
669+
fn_annotations = annotations[f.faddr]
670+
else:
671+
fn_annotations = []
672+
print(f.metrics_to_string(shownocallees=nocallees,
673+
annotations=fn_annotations))
659674

660675
print(stats.disassembly_to_string())
661676
print(stats.analysis_to_string())

0 commit comments

Comments
 (0)