Commit 248f0619 authored by Romain Courteaud's avatar Romain Courteaud

Add profiler support to trace surykatka execution.

parent 284fb88f
...@@ -49,6 +49,9 @@ setup( ...@@ -49,6 +49,9 @@ setup(
"dev": ["pytest", "black", "pyflakes", "mock", "httpretty"] "dev": ["pytest", "black", "pyflakes", "mock", "httpretty"]
}, },
entry_points={ entry_points={
"console_scripts": ["surykatka=surykatka.cli:runSurykatka "] "console_scripts": [
"surykatka=surykatka.cli:runSurykatka ",
"surykatkastat=surykatka.cli:runStats ",
]
}, },
) )
...@@ -55,6 +55,9 @@ from .bot import create_bot ...@@ -55,6 +55,9 @@ from .bot import create_bot
default="plain", default="plain",
show_default=True, show_default=True,
) )
@click.option(
"--profile", help="Profiler data path", type=click.Path(exists=False)
)
def runSurykatka( def runSurykatka(
run, run,
sqlite, sqlite,
...@@ -65,6 +68,7 @@ def runSurykatka( ...@@ -65,6 +68,7 @@ def runSurykatka(
configuration, configuration,
reload, reload,
output, output,
profile,
): ):
mapping = {} mapping = {}
...@@ -85,7 +89,28 @@ def runSurykatka( ...@@ -85,7 +89,28 @@ def runSurykatka(
mapping["RELOAD"] = str(reload) mapping["RELOAD"] = str(reload)
mapping["FORMAT"] = output mapping["FORMAT"] = output
bot = create_bot(cfgfile=configuration, mapping=mapping) bot = create_bot(cfgfile=configuration, mapping=mapping)
if profile is None:
return bot.run(run) return bot.run(run)
else:
import cProfile
return cProfile.runctx(
"bot.run(run)", globals(), locals(), filename=profile
)
@click.command(short_help="Stats profiler bot data.")
@click.option("--stats", type=click.Choice(["cumul", "time"]))
@click.argument("profile", type=click.Path(exists=True, dir_okay=False))
def runStats(stats, profile):
click.echo("Profile bot execution")
import pstats
profile_stats = pstats.Stats(profile)
if stats == "time":
profile_stats.sort_stats("time", "calls").print_stats(30)
else:
profile_stats.sort_stats("cumulative").print_stats(30)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment