utils.py:add profile command to profile python command

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao
2024-09-12 17:13:39 +08:00
committed by Xiang Xiao
parent 160f61cd4d
commit 92d79d5e71
+17
View File
@@ -20,6 +20,7 @@
#
############################################################################
import cProfile
import re
import shlex
from typing import List, Tuple, Union
@@ -349,6 +350,22 @@ class Addr2Line(gdb.Command):
Addr2Line()
class Profile(gdb.Command):
"""Profile a gdb command
Usage: profile <gdb command>
"""
def __init__(self):
super(Profile, self).__init__("profile", gdb.COMMAND_USER)
def invoke(self, args, from_tty):
cProfile.run(f"gdb.execute('{args}')", sort="cumulative")
Profile()
def nitems(array):
array_type = array.type
element_type = array_type.target()