aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2020-11-05 17:21:42 +0100
committerMartin Czygan <martin.czygan@gmail.com>2020-11-05 17:21:42 +0100
commit8f7945a5733dcf2f673d8baecb9f935f9e9b0a21 (patch)
tree508f54636bfa1014ed6de1088ee8b10dec086cee
parent9bf2d7772794045f47421e32cfd8a3aa43f4af0d (diff)
downloadfuzzycat-8f7945a5733dcf2f673d8baecb9f935f9e9b0a21.tar.gz
fuzzycat-8f7945a5733dcf2f673d8baecb9f935f9e9b0a21.zip
add -P profile flag
-rw-r--r--fuzzycat/main.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/fuzzycat/main.py b/fuzzycat/main.py
index dab8802..d735a04 100644
--- a/fuzzycat/main.py
+++ b/fuzzycat/main.py
@@ -11,11 +11,16 @@ Run, e.g. fuzzycat cluster --help for more options. Example:
"""
import argparse
+import cProfile as profile
+import io
import logging
-import json
+import pstats
+# import json
import sys
import tempfile
+import orjson as json
+
from fuzzycat.cluster import (Cluster, release_key_title, release_key_title_normalized,
release_key_title_nysiis)
@@ -32,7 +37,8 @@ def run_cluster(args):
tmpdir=args.tmpdir,
prefix=args.prefix)
stats = cluster.run()
- logger.debug(json.dumps(stats))
+ logger.debug(json.dumps(dict(stats)))
+
def run_verify(args):
print('verify')
@@ -51,6 +57,7 @@ if __name__ == '__main__':
parser.add_argument('--prefix', default='fuzzycat-', help='temp file prefix')
parser.add_argument('--tmpdir', default=tempfile.gettempdir(), help='temporary directory')
+ parser.add_argument('-P', '--profile', action='store_true', help='profile program')
subparsers = parser.add_subparsers()
sub_cluster = subparsers.add_parser('cluster', help='group entities', parents=[parser])
@@ -69,4 +76,16 @@ if __name__ == '__main__':
print(__doc__, file=sys.stderr)
sys.exit(1)
+ if args.profile:
+ logging.disable(logging.DEBUG)
+ pr = profile.Profile()
+ pr.enable()
+
args.func(args)
+
+ if args.profile:
+ pr.disable()
+ s = io.StringIO()
+ ps = pstats.Stats(pr, stream=s).sort_stats('cumulative')
+ ps.print_stats()
+ print(s.getvalue(), file=sys.stderr)