Skip to content

Instantly share code, notes, and snippets.

@kwlzn
Created September 15, 2015 22:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwlzn/42b809558dc825821ddb to your computer and use it in GitHub Desktop.
Save kwlzn/42b809558dc825821ddb to your computer and use it in GitHub Desktop.
yappi profiling
import atexit, yappi
def init_yappi():
print('[YAPPI START]')
yappi.set_clock_type('wall')
yappi.start()
@atexit.register
def finish_yappi():
print('[YAPPI STOP]')
yappi.stop()
print('[YAPPI WRITE]')
stats = yappi.get_func_stats()
for stat_type in ['pstat', 'callgrind', 'ystat']:
print('writing /tmp/pants.{}'.format(stat_type))
stats.save('/tmp/pants.{}'.format(stat_type), type=stat_type)
print('\n[YAPPI FUNC_STATS]')
print('writing /tmp/pants.func_stats')
with open('/tmp/pants.func_stats', 'wb') as fh:
stats.print_all(out=fh)
print('\n[YAPPI THREAD_STATS]')
print('writing /tmp/pants.thread_stats')
tstats = yappi.get_thread_stats()
with open('/tmp/pants.thread_stats', 'wb') as fh:
tstats.print_all(out=fh)
print('[YAPPI OUT]')
...
if __name__ == '__main__':
init_yappi()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment