Skip to content

Commit

Permalink
common: introduce the lower limit parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Michalski <[email protected]>
  • Loading branch information
janekmi committed Nov 10, 2023
1 parent 3d0f0ee commit eb8629f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion utils/call_stacks_analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

If succesfull, it produces:

- `call_stacks_all.json` with call stacks ordered descending by call stack consumption.
- `call_stacks.json` containing call stacks whose call stack use is above the lower limit (the condition applicable only if `--lower-limit` is used) and `call_stacks_excluded.json` whose call stack use is below the limit. Both files are ordered in descending order by call stack use.
- `stack_usage.json` with the data extracted from the provided `src/stats/stack-usage-nondebug.txt`.

**Note**: If too many functions ought to be added to a white list it might be useful to ignore functions having a certain stack usage or lower. Please see `-t` option to set a desired threshold.
Expand Down
27 changes: 20 additions & 7 deletions utils/call_stacks_analysis/generate_call_stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
PARSER.add_argument('-w', '--white-list') # XXX
PARSER.add_argument('-i', '--api-filter-file')
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')

Expand Down Expand Up @@ -284,7 +286,7 @@ def generate_all_call_stacks(stack_usage: StackUsage, calls: Calls, rcalls: RCal
def filter_call_stacks(call_stacks: List[CallStack], api_filter_file: APIFilter) -> List[CallStack]:
api_filter = load_from_txt(api_filter_file)
dump(api_filter, 'api_filter')
print('Load APIFilter - done')
print('Load API Filter - done')

call_stacks_filtered = []
for call_stack in call_stacks:
Expand Down Expand Up @@ -324,14 +326,25 @@ def main():

call_stacks = generate_all_call_stacks(stack_usage, calls, rcalls, api, white_list)
dump(call_stacks, 'call_stacks_all', True)
print('Number of found call stacks: {}'.format(len(call_stacks)))
print('Call stack generation - done')
print('Generate call stacks - done')
print('Number of call stacks: {}'.format(len(call_stacks)))

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)]
call_stacks = too_big
print('Filter out call stacks <= {} - done'.format(args.lower_limit))
print('Number of call stacks: {}'.format(len(call_stacks)))

if args.api_filter_file is not None:
call_stacks_filtered = filter_call_stacks(call_stacks, args.api_filter_file)
dump(call_stacks_filtered, 'call_stacks_filtered', True)
print('Number of found call stacks (filtered): {}'.format(len(call_stacks_filtered)))
print('Call stacks filtering - done')
call_stacks = filter_call_stacks(call_stacks, args.api_filter_file)
print('Filter our call stacks not in the API filter - done')
print('Number of call stacks: {}'.format(len(call_stacks)))

dump(call_stacks, 'call_stacks_final', True)

if __name__ == '__main__':
main()

0 comments on commit eb8629f

Please sign in to comment.