From 031cf9952535181a59039785ee9775f21bfebe63 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 9 Nov 2023 15:31:39 -0500 Subject: [PATCH] common: introduce the lower limit parameter Signed-off-by: Jan Michalski --- .../generate_call_stacks.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/utils/call_stacks_analysis/generate_call_stacks.py b/utils/call_stacks_analysis/generate_call_stacks.py index d721cecc106..64a356141b1 100755 --- a/utils/call_stacks_analysis/generate_call_stacks.py +++ b/utils/call_stacks_analysis/generate_call_stacks.py @@ -22,6 +22,8 @@ PARSER.add_argument('-a', '--api-file', default='api.txt') PARSER.add_argument('-w', '--white-list') # XXX PARSER.add_argument('-d', '--dump', action='store_true', help='Dump debug files') +PARSER.add_argument('-l', '--lower-limit', type=int, default=0, + help='Exclude call stacks of stack usage lower than the limit. Excluded call stacks won\'t appear in both "all" and "filtered" call stacks lists.') PARSER.add_argument('-t', '--skip-threshold', type=int, default=0, help='Ignore non-reachable function if its stack usage <= threshold') @@ -308,9 +310,22 @@ def main(): print('Reverse calls - done') call_stacks = generate_all_call_stacks(stack_usage, calls, rcalls, api, white_list) - dump(call_stacks, 'call_stacks_all', True) + print('Generate call stacks - done') + + if args.lower_limit > 0: + def above_limit(call_stack: CallStack) -> bool: + return call_stack['size'] > args.lower_limit + too_big = [call_stack + for call_stack in call_stacks + if above_limit(call_stack)] + small_enough = [call_stack + for call_stack in call_stacks + if not above_limit(call_stack)] + dump(small_enough, 'call_stacks_excluded') + call_stacks = too_big + print('Exclude small enough call stacks - done') + dump(call_stacks, 'call_stacks', True) print('Number of found call stacks: {}'.format(len(call_stacks))) - print('Call stack generation - done') if __name__ == '__main__': main()