* [RFC PATCH] smdb.py : Add depth option to call_tree
@ 2025-12-09 12:43 Amit Dhingra
2025-12-09 13:08 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Amit Dhingra @ 2025-12-09 12:43 UTC (permalink / raw)
To: Dan Carpenter; +Cc: smatch
The output from call_tree can be overwhelming. This commit provides a
depth option to limit the call_tree output to fewer levels.
When depth is not provided, output is not limited as before.
Signed-off-by: Amit Dhingra <mechanicalamit@gmail.com>
---
smatch_data/db/smdb.py | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/smatch_data/db/smdb.py b/smatch_data/db/smdb.py
index 79b981d4..33bee138 100755
--- a/smatch_data/db/smdb.py
+++ b/smatch_data/db/smdb.py
@@ -21,7 +21,7 @@ def usage():
print("<function> - how a function is called")
print("info <function> <type> - how a function is called,
filtered by type")
print("return_states <function> - what a function returns")
- print("call_tree <function> - show the call tree")
+ print("call_tree <function> [depth] - show the call tree")
print("where <struct_type> <member> - where a struct member is set")
print("type_size <struct_type> <member> - how a struct member is
allocated")
print("type_info <struct_type> <member> - stuff from type_info")
@@ -718,7 +718,7 @@ def get_callers(func, restrict = ""):
return ret
printed_funcs = []
-def call_tree_helper(func, restrict = "", indent = 0):
+def call_tree_helper(func, restrict = "", indent = 0, maxdepth = 999,
depth = 0):
global printed_funcs
if func in printed_funcs:
return
@@ -726,6 +726,8 @@ def call_tree_helper(func, restrict = "", indent = 0):
return
if indent > 30:
return
+ if depth >= maxdepth:
+ return
printed_funcs.append(func)
callers = get_callers(func, restrict)
if len(callers) >= 20:
@@ -736,13 +738,13 @@ def call_tree_helper(func, restrict = "", indent = 0):
print("%s+ %s()" %(" " * indent, caller))
else:
print("%s%s()" %(" " * (indent + 2), caller))
- call_tree_helper(caller, restrict, indent + 2)
+ call_tree_helper(caller, restrict, indent + 2, maxdepth, depth + 1)
-def print_call_tree(func):
+def print_call_tree(func, maxdepth):
global printed_funcs
printed_funcs = []
print("%s()" %(func))
- call_tree_helper(func)
+ call_tree_helper(func, maxdepth = maxdepth)
def get_type_callers(call_tree, branch, func, my_type):
cur = con.cursor()
@@ -996,7 +998,13 @@ elif sys.argv[1] == "data_info":
print_data_info(struct_type, member)
elif sys.argv[1] == "call_tree":
func = sys.argv[2]
- print_call_tree(func)
+ maxdepth = 999
+ if len(sys.argv) >= 4:
+ maxdepth = int(sys.argv[3])
+ if (maxdepth <= 0):
+ print("depth for call_tree must be greater than zero")
+ sys.exit(1)
+ print_call_tree(func, maxdepth)
elif sys.argv[1] == "preempt":
func = sys.argv[2]
print_preempt_tree(func)
--
2.52.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC PATCH] smdb.py : Add depth option to call_tree
2025-12-09 12:43 [RFC PATCH] smdb.py : Add depth option to call_tree Amit Dhingra
@ 2025-12-09 13:08 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2025-12-09 13:08 UTC (permalink / raw)
To: Amit Dhingra; +Cc: smatch
On Tue, Dec 09, 2025 at 04:43:14AM -0800, Amit Dhingra wrote:
> The output from call_tree can be overwhelming. This commit provides a
> depth option to limit the call_tree output to fewer levels.
>
> When depth is not provided, output is not limited as before.
>
> Signed-off-by: Amit Dhingra <mechanicalamit@gmail.com>
> ---
Applied thanks!
It might take me a while to push it to the repository though...
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-09 13:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-09 12:43 [RFC PATCH] smdb.py : Add depth option to call_tree Amit Dhingra
2025-12-09 13:08 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox