diff --git a/kahi/Kahi.py b/kahi/Kahi.py index e242c3c..4cc8fbd 100644 --- a/kahi/Kahi.py +++ b/kahi/Kahi.py @@ -4,6 +4,10 @@ from collections import OrderedDict from pymongo import MongoClient from time import time +import cProfile +import pstats +import io +from pstats import SortKey class OrderedLoader(yaml.SafeLoader): @@ -140,9 +144,19 @@ def run(self): run = getattr(plugin_instance, "run") try: + if self.config["profile"]: + pr = cProfile.Profile() + pr.enable() time_start = time() status = run() time_elapsed = time() - time_start + if self.config["profile"]: + pr.disable() + s = io.StringIO() + sortby = SortKey.CUMULATIVE + ps = pstats.Stats(pr, stream=s).sort_stats(sortby) + ps.print_stats() + print(s.getvalue()) if self.verbose > 4: print("Plugin {} finished in {} seconds".format( log_id, diff --git a/kahi/_version.py b/kahi/_version.py index 395ca75..5972a0b 100644 --- a/kahi/_version.py +++ b/kahi/_version.py @@ -1,5 +1,5 @@ # flake8: noqa -__version__ = '0.0.9-alpha' +__version__ = '0.0.10-alpha' def get_version():