Skip to content

Commit

Permalink
Merge pull request #10 from omazapa/main
Browse files Browse the repository at this point in the history
añadido soporte para correr el profiler de cProfile de python
closes colav/impactu#209
  • Loading branch information
omazapa authored Jul 29, 2024
2 parents 388082c + 0c5f612 commit 3f52067
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions kahi/Kahi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion kahi/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# flake8: noqa
__version__ = '0.0.9-alpha'
__version__ = '0.0.10-alpha'


def get_version():
Expand Down

0 comments on commit 3f52067

Please sign in to comment.