From 8d5ef5b6635b5b84f12409b535114853954680d1 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Thu, 30 Jun 2022 19:22:33 +0200 Subject: Fixes (#1703) * guide line position * use direction from line to shape * optimize intersection detection * fix flapack elf * handle weird guide lines better * update starting point for self crossing (multiple) fills * ripple: fixes and non circular join style * avoid jumps in ripple stitch * fallback only necessary if shape does not intersect grating * make valid may return a polygon * add profiling * Stitch.__init__ didn't work right and was super slow * shrink or grow to multipolygon Co-authored-by: Lex Neva --- inkstitch.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'inkstitch.py') diff --git a/inkstitch.py b/inkstitch.py index 612def21..1dc5a3e3 100644 --- a/inkstitch.py +++ b/inkstitch.py @@ -2,7 +2,8 @@ # # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. - +import cProfile +import pstats import logging import os import sys @@ -50,6 +51,11 @@ my_args, remaining_args = parser.parse_known_args() if os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "DEBUG")): debug.enable() +profiler = None +if os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "PROFILE")): + profiler = cProfile.Profile() + profiler.enable() + extension_name = my_args.extension # example: foo_bar_baz -> FooBarBaz @@ -58,8 +64,19 @@ extension_class_name = extension_name.title().replace("_", "") extension_class = getattr(extensions, extension_class_name) extension = extension_class() -if hasattr(sys, 'gettrace') and sys.gettrace(): +if (hasattr(sys, 'gettrace') and sys.gettrace()) or profiler is not None: extension.run(args=remaining_args) + if profiler: + path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "profile_stats") + profiler.disable() + profiler.dump_stats(path + ".prof") + + with open(path, 'w') as stats_file: + stats = pstats.Stats(profiler, stream=stats_file) + stats.sort_stats(pstats.SortKey.CUMULATIVE) + stats.print_stats() + + print(f"profiling stats written to {path} and {path}.prof", file=sys.stderr) else: save_stderr() exception = None -- cgit v1.2.3