tooling: adds a --profile=<file> option to fontbuild for profiling runs and adds misc/tools/fmtprofile.py for printing and inspecting profile results

This commit is contained in:
Rasmus Andersson 2021-03-25 10:49:12 -07:00
parent 034e568938
commit 56cba2d659
3 changed files with 76 additions and 1 deletions

24
misc/tools/fmtprofile.py Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env python
# encoding: utf8
#
# Formats a Python profile dump from for example `fontbuild --profile=file ...`
#
import argparse, pstats
from pstats import SortKey
def main():
argparser = argparse.ArgumentParser(description='Formats a Python profile dump')
argparser.add_argument('infile', metavar='<file>', type=str, help='Python pstats file')
argparser.add_argument('-n', '--limit', metavar='N', default=None, type=int,
help='Only print the top N entries')
argparser.add_argument('--sort', metavar='<key>', default=['time'], nargs='+', type=str,
help='Sort by keys (default is time.) Available keys: ' + ', '.join(SortKey))
args = argparser.parse_args()
p = pstats.Stats(args.infile)
p.strip_dirs()
p.sort_stats(SortKey(*args.sort))
p.print_stats(args.limit)
if __name__ == '__main__':
main()