29
29
is_dtrace = False
30
30
output_format = "png"
31
31
is_simplify = False
32
+ callgraph_level = 0
32
33
33
34
black_lists_stap = ("kretprobe_trampoline" ,)
34
35
@@ -153,9 +154,9 @@ def travel_tree(self):
153
154
self .root .parent = None
154
155
self .root .is_root = True
155
156
156
- self ._travel_tree (self .root )
157
+ self ._travel_tree (self .root , 1 )
157
158
158
- def _travel_tree (self , node ):
159
+ def _travel_tree (self , node , level ):
159
160
if is_simplify :
160
161
uniq_children = self ._uniq_children (node .children )
161
162
else :
@@ -176,8 +177,10 @@ def _travel_tree(self, node):
176
177
self .core_content += new_link
177
178
#print new_link
178
179
180
+ if level == callgraph_level :
181
+ return
179
182
for child in uniq_children :
180
- self ._travel_tree (child )
183
+ self ._travel_tree (child , level + 1 )
181
184
182
185
183
186
def draw_callgraph (funcs ):
@@ -248,7 +251,7 @@ def generate_pngs(dotfiles):
248
251
249
252
def main ():
250
253
global callgraph_threshold , bt_threshold , keep_dot_files , is_dtrace
251
- global output_format , is_simplify
254
+ global output_format , is_simplify , callgraph_level
252
255
parser = OptionParser (usage = '%prog [options] log_file' ,
253
256
description = 'Generate pngs from Dtrace or Systemtap log' )
254
257
parser .add_option ('-k' , '--keep-dot' , action = 'store_true' ,
@@ -266,6 +269,8 @@ def main():
266
269
' extend to threshold_bt' )
267
270
parser .add_option ('-s' , '--is_simplify' , action = 'store_true' ,
268
271
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' )
269
274
270
275
(options , args ) = parser .parse_args ()
271
276
@@ -281,6 +286,8 @@ def main():
281
286
callgraph_threshold = options .threshold_cg
282
287
if options .threshold_bt and options .threshold_bt > 0 :
283
288
bt_threshold = options .threshold_bt
289
+ if options .level and options .level > 0 :
290
+ callgraph_level = options .level
284
291
285
292
if len (args ) != 1 :
286
293
parser .error ("incorrect number of arguments" )
0 commit comments