Skip to content

Commit 757efa3

Browse files
committed
feature: add level option for output call tree depth
1 parent c50bd8a commit 757efa3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

callee.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
is_dtrace = False
3030
output_format = "png"
3131
is_simplify = False
32+
callgraph_level = 0
3233

3334
black_lists_stap = ("kretprobe_trampoline",)
3435

@@ -153,9 +154,9 @@ def travel_tree(self):
153154
self.root.parent = None
154155
self.root.is_root = True
155156

156-
self._travel_tree(self.root)
157+
self._travel_tree(self.root, 1)
157158

158-
def _travel_tree(self, node):
159+
def _travel_tree(self, node, level):
159160
if is_simplify:
160161
uniq_children = self._uniq_children(node.children)
161162
else:
@@ -176,8 +177,10 @@ def _travel_tree(self, node):
176177
self.core_content += new_link
177178
#print new_link
178179

180+
if level == callgraph_level:
181+
return
179182
for child in uniq_children:
180-
self._travel_tree(child)
183+
self._travel_tree(child, level + 1)
181184

182185

183186
def draw_callgraph(funcs):
@@ -248,7 +251,7 @@ def generate_pngs(dotfiles):
248251

249252
def main():
250253
global callgraph_threshold, bt_threshold, keep_dot_files, is_dtrace
251-
global output_format, is_simplify
254+
global output_format, is_simplify, callgraph_level
252255
parser = OptionParser(usage='%prog [options] log_file',
253256
description='Generate pngs from Dtrace or Systemtap log')
254257
parser.add_option('-k', '--keep-dot', action = 'store_true',
@@ -266,6 +269,8 @@ def main():
266269
' extend to threshold_bt')
267270
parser.add_option('-s', '--is_simplify', action = 'store_true',
268271
help = 'output simplified version, remove the same node, loop node')
272+
parser.add_option('-l', '--level', type = 'int',
273+
help = 'the depth of output call tree')
269274

270275
(options, args) = parser.parse_args()
271276

@@ -281,6 +286,8 @@ def main():
281286
callgraph_threshold = options.threshold_cg
282287
if options.threshold_bt and options.threshold_bt > 0:
283288
bt_threshold = options.threshold_bt
289+
if options.level and options.level > 0:
290+
callgraph_level = options.level
284291

285292
if len(args) != 1:
286293
parser.error("incorrect number of arguments")

0 commit comments

Comments
 (0)