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 9, 2023
1 parent c77b47a commit 5cf12c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 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
22 changes: 20 additions & 2 deletions utils/call_stacks_analysis/generate_call_stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -308,9 +310,25 @@ 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)]
# Note: Both call_stacks_excluded and call_stacks .json files
# are needed when the user wants to list all API calls making
# use of a particular function in their call stacks.
dump(small_enough, 'call_stacks_excluded', True)
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()

0 comments on commit 5cf12c6

Please sign in to comment.