stack.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. #!/usr/bin/env python3
  2. #
  3. # Script to find stack usage at the function level. Will detect recursion and
  4. # report as infinite stack usage.
  5. #
  6. # Example:
  7. # ./scripts/stack.py lfs.ci lfs_util.ci -Slimit
  8. #
  9. # Copyright (c) 2022, The littlefs authors.
  10. # SPDX-License-Identifier: BSD-3-Clause
  11. #
  12. import collections as co
  13. import csv
  14. import glob
  15. import itertools as it
  16. import math as m
  17. import os
  18. import re
  19. CI_PATHS = ['*.ci']
  20. # integer fields
  21. class Int(co.namedtuple('Int', 'x')):
  22. __slots__ = ()
  23. def __new__(cls, x=0):
  24. if isinstance(x, Int):
  25. return x
  26. if isinstance(x, str):
  27. try:
  28. x = int(x, 0)
  29. except ValueError:
  30. # also accept +-∞ and +-inf
  31. if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
  32. x = m.inf
  33. elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
  34. x = -m.inf
  35. else:
  36. raise
  37. assert isinstance(x, int) or m.isinf(x), x
  38. return super().__new__(cls, x)
  39. def __str__(self):
  40. if self.x == m.inf:
  41. return '∞'
  42. elif self.x == -m.inf:
  43. return '-∞'
  44. else:
  45. return str(self.x)
  46. def __int__(self):
  47. assert not m.isinf(self.x)
  48. return self.x
  49. def __float__(self):
  50. return float(self.x)
  51. none = '%7s' % '-'
  52. def table(self):
  53. return '%7s' % (self,)
  54. diff_none = '%7s' % '-'
  55. diff_table = table
  56. def diff_diff(self, other):
  57. new = self.x if self else 0
  58. old = other.x if other else 0
  59. diff = new - old
  60. if diff == +m.inf:
  61. return '%7s' % '+∞'
  62. elif diff == -m.inf:
  63. return '%7s' % '-∞'
  64. else:
  65. return '%+7d' % diff
  66. def ratio(self, other):
  67. new = self.x if self else 0
  68. old = other.x if other else 0
  69. if m.isinf(new) and m.isinf(old):
  70. return 0.0
  71. elif m.isinf(new):
  72. return +m.inf
  73. elif m.isinf(old):
  74. return -m.inf
  75. elif not old and not new:
  76. return 0.0
  77. elif not old:
  78. return 1.0
  79. else:
  80. return (new-old) / old
  81. def __add__(self, other):
  82. return self.__class__(self.x + other.x)
  83. def __sub__(self, other):
  84. return self.__class__(self.x - other.x)
  85. def __mul__(self, other):
  86. return self.__class__(self.x * other.x)
  87. # size results
  88. class StackResult(co.namedtuple('StackResult', [
  89. 'file', 'function', 'frame', 'limit', 'children'])):
  90. _by = ['file', 'function']
  91. _fields = ['frame', 'limit']
  92. _types = {'frame': Int, 'limit': Int}
  93. __slots__ = ()
  94. def __new__(cls, file='', function='',
  95. frame=0, limit=0, children=set()):
  96. return super().__new__(cls, file, function,
  97. Int(frame), Int(limit),
  98. children)
  99. def __add__(self, other):
  100. return StackResult(self.file, self.function,
  101. self.frame + other.frame,
  102. max(self.limit, other.limit),
  103. self.children | other.children)
  104. def openio(path, mode='r'):
  105. if path == '-':
  106. if mode == 'r':
  107. return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
  108. else:
  109. return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
  110. else:
  111. return open(path, mode)
  112. def collect(paths, *,
  113. sources=None,
  114. everything=False,
  115. **args):
  116. # parse the vcg format
  117. k_pattern = re.compile('([a-z]+)\s*:', re.DOTALL)
  118. v_pattern = re.compile('(?:"(.*?)"|([a-z]+))', re.DOTALL)
  119. def parse_vcg(rest):
  120. def parse_vcg(rest):
  121. node = []
  122. while True:
  123. rest = rest.lstrip()
  124. m_ = k_pattern.match(rest)
  125. if not m_:
  126. return (node, rest)
  127. k, rest = m_.group(1), rest[m_.end(0):]
  128. rest = rest.lstrip()
  129. if rest.startswith('{'):
  130. v, rest = parse_vcg(rest[1:])
  131. assert rest[0] == '}', "unexpected %r" % rest[0:1]
  132. rest = rest[1:]
  133. node.append((k, v))
  134. else:
  135. m_ = v_pattern.match(rest)
  136. assert m_, "unexpected %r" % rest[0:1]
  137. v, rest = m_.group(1) or m_.group(2), rest[m_.end(0):]
  138. node.append((k, v))
  139. node, rest = parse_vcg(rest)
  140. assert rest == '', "unexpected %r" % rest[0:1]
  141. return node
  142. # collect into functions
  143. callgraph = co.defaultdict(lambda: (None, None, 0, set()))
  144. f_pattern = re.compile(
  145. r'([^\\]*)\\n([^:]*)[^\\]*\\n([0-9]+) bytes \((.*)\)')
  146. for path in paths:
  147. with open(path) as f:
  148. vcg = parse_vcg(f.read())
  149. for k, graph in vcg:
  150. if k != 'graph':
  151. continue
  152. for k, info in graph:
  153. if k == 'node':
  154. info = dict(info)
  155. m_ = f_pattern.match(info['label'])
  156. if m_:
  157. function, file, size, type = m_.groups()
  158. if (not args.get('quiet')
  159. and 'static' not in type
  160. and 'bounded' not in type):
  161. print("warning: "
  162. "found non-static stack for %s (%s, %s)" % (
  163. function, type, size))
  164. _, _, _, targets = callgraph[info['title']]
  165. callgraph[info['title']] = (
  166. file, function, int(size), targets)
  167. elif k == 'edge':
  168. info = dict(info)
  169. _, _, _, targets = callgraph[info['sourcename']]
  170. targets.add(info['targetname'])
  171. else:
  172. continue
  173. callgraph_ = co.defaultdict(lambda: (None, None, 0, set()))
  174. for source, (s_file, s_function, frame, targets) in callgraph.items():
  175. # discard internal functions
  176. if not everything and s_function.startswith('__'):
  177. continue
  178. # ignore filtered sources
  179. if sources is not None:
  180. if not any(
  181. os.path.abspath(s_file) == os.path.abspath(s)
  182. for s in sources):
  183. continue
  184. else:
  185. # default to only cwd
  186. if not everything and not os.path.commonpath([
  187. os.getcwd(),
  188. os.path.abspath(s_file)]) == os.getcwd():
  189. continue
  190. # smiplify path
  191. if os.path.commonpath([
  192. os.getcwd(),
  193. os.path.abspath(s_file)]) == os.getcwd():
  194. s_file = os.path.relpath(s_file)
  195. else:
  196. s_file = os.path.abspath(s_file)
  197. callgraph_[source] = (s_file, s_function, frame, targets)
  198. callgraph = callgraph_
  199. if not everything:
  200. callgraph_ = co.defaultdict(lambda: (None, None, 0, set()))
  201. for source, (s_file, s_function, frame, targets) in callgraph.items():
  202. # discard filtered sources
  203. if sources is not None and not any(
  204. os.path.abspath(s_file) == os.path.abspath(s)
  205. for s in sources):
  206. continue
  207. # discard internal functions
  208. if s_function.startswith('__'):
  209. continue
  210. callgraph_[source] = (s_file, s_function, frame, targets)
  211. callgraph = callgraph_
  212. # find maximum stack size recursively, this requires also detecting cycles
  213. # (in case of recursion)
  214. def find_limit(source, seen=None):
  215. seen = seen or set()
  216. if source not in callgraph:
  217. return 0
  218. _, _, frame, targets = callgraph[source]
  219. limit = 0
  220. for target in targets:
  221. if target in seen:
  222. # found a cycle
  223. return m.inf
  224. limit_ = find_limit(target, seen | {target})
  225. limit = max(limit, limit_)
  226. return frame + limit
  227. def find_children(targets):
  228. children = set()
  229. for target in targets:
  230. if target in callgraph:
  231. t_file, t_function, _, _ = callgraph[target]
  232. children.add((t_file, t_function))
  233. return children
  234. # build results
  235. results = []
  236. for source, (s_file, s_function, frame, targets) in callgraph.items():
  237. limit = find_limit(source)
  238. children = find_children(targets)
  239. results.append(StackResult(s_file, s_function, frame, limit, children))
  240. return results
  241. def fold(Result, results, *,
  242. by=None,
  243. defines=None,
  244. **_):
  245. if by is None:
  246. by = Result._by
  247. for k in it.chain(by or [], (k for k, _ in defines or [])):
  248. if k not in Result._by and k not in Result._fields:
  249. print("error: could not find field %r?" % k)
  250. sys.exit(-1)
  251. # filter by matching defines
  252. if defines is not None:
  253. results_ = []
  254. for r in results:
  255. if all(getattr(r, k) in vs for k, vs in defines):
  256. results_.append(r)
  257. results = results_
  258. # organize results into conflicts
  259. folding = co.OrderedDict()
  260. for r in results:
  261. name = tuple(getattr(r, k) for k in by)
  262. if name not in folding:
  263. folding[name] = []
  264. folding[name].append(r)
  265. # merge conflicts
  266. folded = []
  267. for name, rs in folding.items():
  268. folded.append(sum(rs[1:], start=rs[0]))
  269. return folded
  270. def table(Result, results, diff_results=None, *,
  271. by=None,
  272. fields=None,
  273. sort=None,
  274. summary=False,
  275. all=False,
  276. percent=False,
  277. tree=False,
  278. depth=1,
  279. **_):
  280. all_, all = all, __builtins__.all
  281. if by is None:
  282. by = Result._by
  283. if fields is None:
  284. fields = Result._fields
  285. types = Result._types
  286. # fold again
  287. results = fold(Result, results, by=by)
  288. if diff_results is not None:
  289. diff_results = fold(Result, diff_results, by=by)
  290. # organize by name
  291. table = {
  292. ','.join(str(getattr(r, k) or '') for k in by): r
  293. for r in results}
  294. diff_table = {
  295. ','.join(str(getattr(r, k) or '') for k in by): r
  296. for r in diff_results or []}
  297. names = list(table.keys() | diff_table.keys())
  298. # sort again, now with diff info, note that python's sort is stable
  299. names.sort()
  300. if diff_results is not None:
  301. names.sort(key=lambda n: tuple(
  302. types[k].ratio(
  303. getattr(table.get(n), k, None),
  304. getattr(diff_table.get(n), k, None))
  305. for k in fields),
  306. reverse=True)
  307. if sort:
  308. for k, reverse in reversed(sort):
  309. names.sort(key=lambda n: (getattr(table[n], k),)
  310. if getattr(table.get(n), k, None) is not None else (),
  311. reverse=reverse ^ (not k or k in Result._fields))
  312. # build up our lines
  313. lines = []
  314. # header
  315. header = []
  316. header.append('%s%s' % (
  317. ','.join(by),
  318. ' (%d added, %d removed)' % (
  319. sum(1 for n in table if n not in diff_table),
  320. sum(1 for n in diff_table if n not in table))
  321. if diff_results is not None and not percent else '')
  322. if not summary else '')
  323. if diff_results is None:
  324. for k in fields:
  325. header.append(k)
  326. elif percent:
  327. for k in fields:
  328. header.append(k)
  329. else:
  330. for k in fields:
  331. header.append('o'+k)
  332. for k in fields:
  333. header.append('n'+k)
  334. for k in fields:
  335. header.append('d'+k)
  336. header.append('')
  337. lines.append(header)
  338. def table_entry(name, r, diff_r=None, ratios=[]):
  339. entry = []
  340. entry.append(name)
  341. if diff_results is None:
  342. for k in fields:
  343. entry.append(getattr(r, k).table()
  344. if getattr(r, k, None) is not None
  345. else types[k].none)
  346. elif percent:
  347. for k in fields:
  348. entry.append(getattr(r, k).diff_table()
  349. if getattr(r, k, None) is not None
  350. else types[k].diff_none)
  351. else:
  352. for k in fields:
  353. entry.append(getattr(diff_r, k).diff_table()
  354. if getattr(diff_r, k, None) is not None
  355. else types[k].diff_none)
  356. for k in fields:
  357. entry.append(getattr(r, k).diff_table()
  358. if getattr(r, k, None) is not None
  359. else types[k].diff_none)
  360. for k in fields:
  361. entry.append(types[k].diff_diff(
  362. getattr(r, k, None),
  363. getattr(diff_r, k, None)))
  364. if diff_results is None:
  365. entry.append('')
  366. elif percent:
  367. entry.append(' (%s)' % ', '.join(
  368. '+∞%' if t == +m.inf
  369. else '-∞%' if t == -m.inf
  370. else '%+.1f%%' % (100*t)
  371. for t in ratios))
  372. else:
  373. entry.append(' (%s)' % ', '.join(
  374. '+∞%' if t == +m.inf
  375. else '-∞%' if t == -m.inf
  376. else '%+.1f%%' % (100*t)
  377. for t in ratios
  378. if t)
  379. if any(ratios) else '')
  380. return entry
  381. # entries
  382. if not summary:
  383. for name in names:
  384. r = table.get(name)
  385. if diff_results is None:
  386. diff_r = None
  387. ratios = None
  388. else:
  389. diff_r = diff_table.get(name)
  390. ratios = [
  391. types[k].ratio(
  392. getattr(r, k, None),
  393. getattr(diff_r, k, None))
  394. for k in fields]
  395. if not all_ and not any(ratios):
  396. continue
  397. lines.append(table_entry(name, r, diff_r, ratios))
  398. # total
  399. r = next(iter(fold(Result, results, by=[])), None)
  400. if diff_results is None:
  401. diff_r = None
  402. ratios = None
  403. else:
  404. diff_r = next(iter(fold(Result, diff_results, by=[])), None)
  405. ratios = [
  406. types[k].ratio(
  407. getattr(r, k, None),
  408. getattr(diff_r, k, None))
  409. for k in fields]
  410. lines.append(table_entry('TOTAL', r, diff_r, ratios))
  411. # find the best widths, note that column 0 contains the names and column -1
  412. # the ratios, so those are handled a bit differently
  413. widths = [
  414. ((max(it.chain([w], (len(l[i]) for l in lines)))+1+4-1)//4)*4-1
  415. for w, i in zip(
  416. it.chain([23], it.repeat(7)),
  417. range(len(lines[0])-1))]
  418. # adjust the name width based on the expected call depth, though
  419. # note this doesn't really work with unbounded recursion
  420. if not summary and not m.isinf(depth):
  421. widths[0] += 4*(depth-1)
  422. # print the tree recursively
  423. if not tree:
  424. print('%-*s %s%s' % (
  425. widths[0], lines[0][0],
  426. ' '.join('%*s' % (w, x)
  427. for w, x in zip(widths[1:], lines[0][1:-1])),
  428. lines[0][-1]))
  429. if not summary:
  430. line_table = {n: l for n, l in zip(names, lines[1:-1])}
  431. def recurse(names_, depth_, prefixes=('', '', '', '')):
  432. for i, name in enumerate(names_):
  433. if name not in line_table:
  434. continue
  435. line = line_table[name]
  436. is_last = (i == len(names_)-1)
  437. print('%s%-*s ' % (
  438. prefixes[0+is_last],
  439. widths[0] - (
  440. len(prefixes[0+is_last])
  441. if not m.isinf(depth) else 0),
  442. line[0]),
  443. end='')
  444. if not tree:
  445. print(' %s%s' % (
  446. ' '.join('%*s' % (w, x)
  447. for w, x in zip(widths[1:], line[1:-1])),
  448. line[-1]),
  449. end='')
  450. print()
  451. # recurse?
  452. if name in table and depth_ > 1:
  453. children = {
  454. ','.join(str(getattr(Result(*c), k) or '') for k in by)
  455. for c in table[name].children}
  456. recurse(
  457. # note we're maintaining sort order
  458. [n for n in names if n in children],
  459. depth_-1,
  460. (prefixes[2+is_last] + "|-> ",
  461. prefixes[2+is_last] + "'-> ",
  462. prefixes[2+is_last] + "| ",
  463. prefixes[2+is_last] + " "))
  464. recurse(names, depth)
  465. if not tree:
  466. print('%-*s %s%s' % (
  467. widths[0], lines[-1][0],
  468. ' '.join('%*s' % (w, x)
  469. for w, x in zip(widths[1:], lines[-1][1:-1])),
  470. lines[-1][-1]))
  471. def main(ci_paths,
  472. by=None,
  473. fields=None,
  474. defines=None,
  475. sort=None,
  476. **args):
  477. # it doesn't really make sense to not have a depth with tree,
  478. # so assume depth=inf if tree by default
  479. if args.get('depth') is None:
  480. args['depth'] = m.inf if args['tree'] else 1
  481. elif args.get('depth') == 0:
  482. args['depth'] = m.inf
  483. # find sizes
  484. if not args.get('use', None):
  485. # find .ci files
  486. paths = []
  487. for path in ci_paths:
  488. if os.path.isdir(path):
  489. path = path + '/*.ci'
  490. for path in glob.glob(path):
  491. paths.append(path)
  492. if not paths:
  493. print("error: no .ci files found in %r?" % ci_paths)
  494. sys.exit(-1)
  495. results = collect(paths, **args)
  496. else:
  497. results = []
  498. with openio(args['use']) as f:
  499. reader = csv.DictReader(f, restval='')
  500. for r in reader:
  501. try:
  502. results.append(StackResult(
  503. **{k: r[k] for k in StackResult._by
  504. if k in r and r[k].strip()},
  505. **{k: r['stack_'+k] for k in StackResult._fields
  506. if 'stack_'+k in r and r['stack_'+k].strip()}))
  507. except TypeError:
  508. pass
  509. # fold
  510. results = fold(StackResult, results, by=by, defines=defines)
  511. # sort, note that python's sort is stable
  512. results.sort()
  513. if sort:
  514. for k, reverse in reversed(sort):
  515. results.sort(key=lambda r: (getattr(r, k),)
  516. if getattr(r, k) is not None else (),
  517. reverse=reverse ^ (not k or k in StackResult._fields))
  518. # write results to CSV
  519. if args.get('output'):
  520. with openio(args['output'], 'w') as f:
  521. writer = csv.DictWriter(f,
  522. (by if by is not None else StackResult._by)
  523. + ['stack_'+k for k in StackResult._fields])
  524. writer.writeheader()
  525. for r in results:
  526. writer.writerow(
  527. {k: getattr(r, k)
  528. for k in (by if by is not None else StackResult._by)}
  529. | {'stack_'+k: getattr(r, k)
  530. for k in StackResult._fields})
  531. # find previous results?
  532. if args.get('diff'):
  533. diff_results = []
  534. try:
  535. with openio(args['diff']) as f:
  536. reader = csv.DictReader(f, restval='')
  537. for r in reader:
  538. try:
  539. diff_results.append(StackResult(
  540. **{k: r[k] for k in StackResult._by
  541. if k in r and r[k].strip()},
  542. **{k: r['stack_'+k] for k in StackResult._fields
  543. if 'stack_'+k in r and r['stack_'+k].strip()}))
  544. except TypeError:
  545. raise
  546. except FileNotFoundError:
  547. pass
  548. # fold
  549. diff_results = fold(StackResult, diff_results, by=by, defines=defines)
  550. # print table
  551. if not args.get('quiet'):
  552. table(StackResult, results,
  553. diff_results if args.get('diff') else None,
  554. by=by if by is not None else ['function'],
  555. fields=fields,
  556. sort=sort,
  557. **args)
  558. # error on recursion
  559. if args.get('error_on_recursion') and any(
  560. m.isinf(float(r.limit)) for r in results):
  561. sys.exit(2)
  562. if __name__ == "__main__":
  563. import argparse
  564. import sys
  565. parser = argparse.ArgumentParser(
  566. description="Find stack usage at the function level.",
  567. allow_abbrev=False)
  568. parser.add_argument(
  569. 'ci_paths',
  570. nargs='*',
  571. default=CI_PATHS,
  572. help="Description of where to find *.ci files. May be a directory "
  573. "or a list of paths. Defaults to %r." % CI_PATHS)
  574. parser.add_argument(
  575. '-v', '--verbose',
  576. action='store_true',
  577. help="Output commands that run behind the scenes.")
  578. parser.add_argument(
  579. '-q', '--quiet',
  580. action='store_true',
  581. help="Don't show anything, useful with -o.")
  582. parser.add_argument(
  583. '-o', '--output',
  584. help="Specify CSV file to store results.")
  585. parser.add_argument(
  586. '-u', '--use',
  587. help="Don't parse anything, use this CSV file.")
  588. parser.add_argument(
  589. '-d', '--diff',
  590. help="Specify CSV file to diff against.")
  591. parser.add_argument(
  592. '-a', '--all',
  593. action='store_true',
  594. help="Show all, not just the ones that changed.")
  595. parser.add_argument(
  596. '-p', '--percent',
  597. action='store_true',
  598. help="Only show percentage change, not a full diff.")
  599. parser.add_argument(
  600. '-b', '--by',
  601. action='append',
  602. choices=StackResult._by,
  603. help="Group by this field.")
  604. parser.add_argument(
  605. '-f', '--field',
  606. dest='fields',
  607. action='append',
  608. choices=StackResult._fields,
  609. help="Show this field.")
  610. parser.add_argument(
  611. '-D', '--define',
  612. dest='defines',
  613. action='append',
  614. type=lambda x: (lambda k,v: (k, set(v.split(','))))(*x.split('=', 1)),
  615. help="Only include results where this field is this value.")
  616. class AppendSort(argparse.Action):
  617. def __call__(self, parser, namespace, value, option):
  618. if namespace.sort is None:
  619. namespace.sort = []
  620. namespace.sort.append((value, True if option == '-S' else False))
  621. parser.add_argument(
  622. '-s', '--sort',
  623. action=AppendSort,
  624. help="Sort by this fields.")
  625. parser.add_argument(
  626. '-S', '--reverse-sort',
  627. action=AppendSort,
  628. help="Sort by this fields, but backwards.")
  629. parser.add_argument(
  630. '-Y', '--summary',
  631. action='store_true',
  632. help="Only show the total.")
  633. parser.add_argument(
  634. '-F', '--source',
  635. dest='sources',
  636. action='append',
  637. help="Only consider definitions in this file. Defaults to anything "
  638. "in the current directory.")
  639. parser.add_argument(
  640. '--everything',
  641. action='store_true',
  642. help="Include builtin and libc specific symbols.")
  643. parser.add_argument(
  644. '--tree',
  645. action='store_true',
  646. help="Only show the function call tree.")
  647. parser.add_argument(
  648. '-Z', '--depth',
  649. nargs='?',
  650. type=lambda x: int(x, 0),
  651. const=0,
  652. help="Depth of function calls to show. 0 shows all calls but may not "
  653. "terminate!")
  654. parser.add_argument(
  655. '-e', '--error-on-recursion',
  656. action='store_true',
  657. help="Error if any functions are recursive.")
  658. sys.exit(main(**{k: v
  659. for k, v in vars(parser.parse_intermixed_args()).items()
  660. if v is not None}))