Skip to content

Commit 5753d90

Browse files
committed
CMD: add tags to result metrics
1 parent ada1128 commit 5753d90

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

chb/app/AppResultFunctionMetrics.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,21 @@ def metrics_to_string(
237237
self,
238238
shownocallees: bool = False,
239239
space: str = " ",
240-
annotations: List[str] = []) -> str:
240+
tags: List[str] = [],
241+
taglen: int = 0) -> str:
241242
callcount = ''
242243
name = ''
243244
unrc = ''
244-
anns = ""
245+
ftags = "".ljust(taglen)
245246
if shownocallees and (not self.has_name()):
246247
if self.call_count == 0:
247248
callcount = ' (no callees)'
248249
if self.has_name():
249250
name = ' (' + self.name + ')'
250251
if self.unresolved_call_count > 0:
251252
unrc = str(self.unresolved_call_count)
252-
if len(annotations) > 0:
253-
anns = " [" + ", ".join(annotations) + "]"
253+
if len(tags) > 0:
254+
ftags = (" [" + ",".join(tags) + "]").ljust(taglen)
254255

255256
return (str(self.faddr).ljust(10) + space
256257
+ '{:6.1f}'.format(self.espp) + space
@@ -259,4 +260,4 @@ def metrics_to_string(
259260
+ unrc.rjust(6) + space
260261
+ str(self.block_count).rjust(6) + space
261262
+ str(self.instruction_count).rjust(6) + space
262-
+ '{:8.3f}'.format(self.time) + name + callcount + anns)
263+
+ '{:8.3f}'.format(self.time) + ftags + name + callcount)

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-20250327"
1+
chbversion: str = "0.3.0-20250329"

chb/cmdline/chkx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ def parse() -> argparse.Namespace:
613613
help=("json filename (without extension) to save opcode distribution "
614614
+ "stats (for instructions within analyzed functions)"))
615615
resultsstats.add_argument(
616-
"--annotationfile",
617-
help="name of json file that has function annotations")
616+
"--tagfile",
617+
help="name of json file that has function tags")
618618
resultsstats.add_argument(
619619
"--loglevel", "-log",
620620
choices=UL.LogLevel.options(),

chb/cmdline/commandutil.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +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: Optional[str] = args.annotationfile
622+
tagfile: Optional[str] = args.tagfile
623623
loglevel: str = args.loglevel
624624
logfilename: Optional[str] = args.logfilename
625625
logfilemode: str = args.logfilemode
@@ -638,14 +638,21 @@ def results_stats(args: argparse.Namespace) -> NoReturn:
638638
mode=logfilemode,
639639
msg="results stats invoked")
640640

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():
641+
tags: Dict[str, List[str]] = {}
642+
if tagfile is not None:
643+
with open(tagfile, "r") as fp:
644+
tagdata = json.load(fp)
645+
for (key, flist) in tagdata["keys"].items():
646646
for faddr in flist:
647-
annotations.setdefault(faddr, [])
648-
annotations[faddr].append(key)
647+
tags.setdefault(faddr, [])
648+
if not key in tags[faddr]:
649+
tags[faddr].append(key)
650+
651+
maxlen = 0
652+
for (faddr, keys) in tags.items():
653+
taglen = 4 + len(",".join(keys))
654+
if taglen > maxlen:
655+
maxlen = taglen
649656

650657
xinfo = XI.XInfo()
651658
xinfo.load(path, xfile)
@@ -665,12 +672,14 @@ def results_stats(args: argparse.Namespace) -> NoReturn:
665672
else:
666673
sortkey = lambda f: int(f.faddr, 16)
667674
for f in sorted(stats.get_function_results(), key=sortkey):
668-
if f.faddr in annotations:
669-
fn_annotations = annotations[f.faddr]
675+
if f.faddr in tags:
676+
fn_tags = tags[f.faddr]
670677
else:
671-
fn_annotations = []
678+
fn_tags = []
679+
if "hide" in fn_tags:
680+
continue
672681
print(f.metrics_to_string(shownocallees=nocallees,
673-
annotations=fn_annotations))
682+
tags=fn_tags, taglen=maxlen))
674683

675684
print(stats.disassembly_to_string())
676685
print(stats.analysis_to_string())

0 commit comments

Comments
 (0)