summaryrefslogtreecommitdiff
path: root/inkstitch.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2022-06-30 19:22:33 +0200
committerGitHub <noreply@github.com>2022-06-30 19:22:33 +0200
commit8d5ef5b6635b5b84f12409b535114853954680d1 (patch)
treec963bf0e1ddc4ee584c08b4014232f0f067ae512 /inkstitch.py
parent725281f075f8d40a68427733f377983b6f7c607b (diff)
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
Diffstat (limited to 'inkstitch.py')
-rw-r--r--inkstitch.py21
1 files changed, 19 insertions, 2 deletions
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