ocrd_cli_wrap_processor: implement --profile
@@ -27,6 +27,7 @@ def ocrd_cli_wrap_processor(
working_dir=None,
dump_json=False,
help=False, # pylint: disable=redefined-builtin
+ profile=False,
version=False,
overwrite=False,
show_resource=None,
@@ -85,4 +86,19 @@ def ocrd_cli_wrap_processor(
report = WorkspaceValidator.check_file_grp(workspace, kwargs['input_file_grp'], '' if overwrite else kwargs['output_file_grp'], page_id)
if not report.is_valid:
raise Exception("Invalid input/output file grps:\n\t%s" % '\n\t'.join(report.errors))
+ if profile:
+ import cProfile
+ import pstats
+ import io
+ import atexit
+ print("Profiling...")
+ pr = cProfile.Profile()
+ pr.enable()
+ def exit():
+ pr.disable()
+ print("Profiling completed")
+ s = io.StringIO()
+ pstats.Stats(pr, stream=s).sort_stats("cumulative").print_stats()
+ print(s.getvalue())
+ atexit.register(exit)
run_processor(processorClass, ocrd_tool, mets, workspace=workspace, **kwargs)
