This is an automated email from Gerrit.

"Richard Allen <rsa...@gmail.com>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/8602

-- gerrit

commit 508a9276380cdee3e363c8fd1565862a593fde9f
Author: Richard Allen <rsa...@rsaxvc.net>
Date:   Fri Nov 29 11:39:34 2024 -0600

    tools: Add gmon analyzer
    
    A simple utility to parse a gmon file and generate a text report.
    
    Change-Id: I38276dd1be012ce5781b1364b7cbb08c32a1a2a2
    Signed-off-by: Richard Allen <rsa...@gmail.com>

diff --git a/tools/scripts/gmon_parse.py b/tools/scripts/gmon_parse.py
new file mode 100755
index 0000000000..56fd5c326f
--- /dev/null
+++ b/tools/scripts/gmon_parse.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+import argparse
+import sys
+
+parser = argparse.ArgumentParser()
+parser.add_argument('inputFiles', nargs='+', type=argparse.FileType('rb'))
+parser.set_defaults(PSZ=4, baz='badger')
+parser.add_argument('--32', dest='PSZ', action='store_const', const=4, 
help="32-bit pointers")
+parser.add_argument('--64', dest='PSZ', action='store_const', const=8, 
help="64-bit pointers")
+args = parser.parse_args()
+print(args)
+
+#These values from gmon_out.h
+GMON_TAG_TIME_HIST = 0
+GMON_TAG_CG_ARC = 1
+GMON_TAG_BB_COUNT = 2
+
+SIZEOF_POINTER = args.PSZ
+print(SIZEOF_POINTER)
+BYTEORDER = 'big'
+
+
+for f in args.inputFiles:
+       nHist = 0
+       nArcs = 0
+       nBBs  = 0
+
+       cookie = f.read(4)
+       if cookie != b"gmon":
+               print("Unexpected gmon.out cookie:", cookie)
+               sys.exit(1)
+       version = f.read(4)
+       if int.from_bytes(version, byteorder='big') == 1:
+               BYTEORDER = 'big'
+       elif int.from_bytes(version, byteorder='little') == 1:
+               BYTEORDER = 'little'
+       print("ByteOrder:", BYTEORDER)
+       print("Version:", int.from_bytes(version, byteorder=BYTEORDER))
+       spare = f.read(3 * 4)
+       while (header := f.read(1)):
+               header = header[0]
+               if header == GMON_TAG_TIME_HIST:
+                       print("Histogram")
+                       nHist += 1
+                       low_pc = int.from_bytes(f.read(SIZEOF_POINTER), 
BYTEORDER)
+                       high_pc = int.from_bytes(f.read(SIZEOF_POINTER), 
BYTEORDER)
+                       hist_size = int.from_bytes(f.read(4), BYTEORDER)
+                       prof_rate = int.from_bytes(f.read(4), BYTEORDER)
+                       dimen = f.read(15)
+                       dimen_abbrev = f.read(1)
+                       print("\tdimen:", dimen)
+                       print("\thist_size:", hist_size)
+                       print("\tprof_rate:", prof_rate)
+                       for hist in range(hist_size):
+                               sample = f.read(2)
+                               if len(sample) != 2:
+                                       print("unable to read samples, giving 
up")
+                                       sys.exit(2)
+                               sample = int.from_bytes(sample, BYTEORDER)
+                               print("\t\t",sample)
+               elif header == GMON_TAG_CG_ARC:
+                       from_pc = int.from_bytes(f.read(SIZEOF_POINTER), 
BYTEORDER)
+                       self_pc = int.from_bytes(f.read(SIZEOF_POINTER), 
BYTEORDER)
+                       count = int.from_bytes(f.read(4), BYTEORDER)
+                       print("Arc", from_pc, self_pc, count)
+                       nArcs += 1
+               elif header == GMON_TAG_BB_COUNT:
+                       print("BasicBlock")
+                       bb_count = int.from_bytes(f.read(SIZEOF_POINTER), 
BYTEORDER)
+                       print("\tcount=",bb_count)
+                       for bb in range(bb_count):
+                               pc = f.read(SIZEOF_POINTER)
+                               count = f.read(SIZEOF_POINTER)
+                               if len(pc) != SIZEOF_POINTER or len(count) != 
SIZEOF_POINTER:
+                                       print("unable to read samples, giving 
up")
+                                       sys.exit(2)
+                       nBBs += bb_count
+               else:
+                       print("Unknown header byte:",header,"giving up")
+                       sys.exit(1)
+
+       print("Processed", nHist, "histograms,", nArcs, "arcs,",  nBBs, 
"basic-blocks")

-- 

Reply via email to