From 56cba2d659d15129a665a3f540efc85c2b704d12 Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Thu, 25 Mar 2021 10:49:12 -0700 Subject: tooling: adds a --profile= option to fontbuild for profiling runs and adds misc/tools/fmtprofile.py for printing and inspecting profile results --- misc/tools/fmtprofile.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 misc/tools/fmtprofile.py (limited to 'misc/tools/fmtprofile.py') diff --git a/misc/tools/fmtprofile.py b/misc/tools/fmtprofile.py new file mode 100755 index 000000000..695d88ee7 --- /dev/null +++ b/misc/tools/fmtprofile.py @@ -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='', 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='', 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() -- cgit v1.2.3