summaryrefslogtreecommitdiff
path: root/misc/tools/fmtprofile.py
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2021-03-25 20:49:12 +0300
committerRasmus Andersson <rasmus@notion.se>2021-03-25 20:49:12 +0300
commit56cba2d659d15129a665a3f540efc85c2b704d12 (patch)
tree0b43ba3af77fd6d69eebd8eebf34d237b10fc924 /misc/tools/fmtprofile.py
parent034e568938497cd398109b191dc2b9e8f5d261e8 (diff)
downloadinter-56cba2d659d15129a665a3f540efc85c2b704d12.tar.xz
tooling: adds a --profile=<file> option to fontbuild for profiling runs and adds misc/tools/fmtprofile.py for printing and inspecting profile results
Diffstat (limited to 'misc/tools/fmtprofile.py')
-rwxr-xr-xmisc/tools/fmtprofile.py24
1 files changed, 24 insertions, 0 deletions
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='<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()