WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mumble/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.1.2"
__version__ = "0.2.0"

from mumble.mumble import PSMHandler
27 changes: 27 additions & 0 deletions mumble/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import cProfile

from mumble import PSMHandler

Expand Down Expand Up @@ -75,9 +76,27 @@
"help": "Path to a config file",
"default": None,
},
"profile": {
"is_flag": True,
"help": "Profile the code with cProfile",
"default": False,
"show_default": True,
},
}


def profile(fnc, filepath):
"""A decorator that uses cProfile to profile a function"""

def inner(*args, **kwargs):
with cProfile.Profile() as profiler:
return_value = fnc(*args, **kwargs)
profiler.dump_stats(filepath + ".profile.prof")
return return_value

return inner


@click.command("cli", context_settings={"show_default": True})
@click.argument("input_file", type=click.Path(exists=True), default=None)
def main(**kwargs):
Expand All @@ -92,13 +111,21 @@ def main(**kwargs):
for key, value in kwargs.items()
if ctx.get_parameter_source(key) == click.core.ParameterSource.COMMANDLINE
}
if kwargs["profile"]:
pr = cProfile.Profile()
pr.enable()
else:
pr = None

# Initialize PSMHandler with priority for CLI params
psm_handler = PSMHandler(
config_file=kwargs.get("config_file"),
**cli_params,
)
modified_psm_list = psm_handler.add_modified_psms(kwargs["input_file"])
if pr:
pr.disable()
pr.dump_stats(kwargs["input_file"] + ".profile.prof")

psm_handler.write_modified_psm_list(modified_psm_list)

Expand Down
Loading