diff --git a/tools/gdb/utils.py b/tools/gdb/utils.py index 6a2509c8bb8..42dfcb81dc0 100644 --- a/tools/gdb/utils.py +++ b/tools/gdb/utils.py @@ -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 + """ + + 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()