From 6f83192909726d5968ff1eb6ef1f6712ddcfceb1 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 3 Aug 2021 19:54:29 -0400 Subject: [PATCH] Add a few more profiling helpers. Especially useful is the log print before converting the mesh verticies. This is the slowest part of Korman, per profiling. --- korman/exporter/mesh.py | 2 ++ korman/operators/op_lightmap.py | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/korman/exporter/mesh.py b/korman/exporter/mesh.py index fef6d9a..e1e20c7 100644 --- a/korman/exporter/mesh.py +++ b/korman/exporter/mesh.py @@ -374,6 +374,8 @@ class MeshConverter(_MeshManager): inc_progress() def _export_geometry(self, bo, mesh, materials, geospans, mat2span_LUT): + self._report.msg("Converting geometry from '{}'...", mesh.name, indent=1) + # Recall that materials is a mapping of exported materials to blender material indices. # Therefore, geodata maps blender material indices to working geometry data. # Maybe the logic is a bit inverted, but it keeps the inner loop simple. diff --git a/korman/operators/op_lightmap.py b/korman/operators/op_lightmap.py index b757cf8..4f363f9 100644 --- a/korman/operators/op_lightmap.py +++ b/korman/operators/op_lightmap.py @@ -16,10 +16,12 @@ import bpy from bpy.props import * +import cProfile from contextlib import contextmanager -import itertools +import pstats from ..exporter.etlight import LightBaker +from ..exporter.explosions import ExportError from ..helpers import UiHelper from ..korlib import ConsoleToggler @@ -95,6 +97,25 @@ class LightmapBakeMultiOperator(_LightingOperator, bpy.types.Operator): super().__init__() def execute(self, context): + profile_me = False + + try: + if profile_me: + cProfile.runctx("self._run(context)", globals(), locals(), "bake_cProfile") + else: + self._run(context) + except ExportError as error: + self.report({"ERROR"}, str(error)) + return {"CANCELLED"} + else: + if profile_me: + with open("bake_profile.log", "w") as out: + stats = pstats.Stats("bake_cProfile", stream=out) + stats = stats.sort_stats("time", "cumtime") + stats.print_stats() + return {"FINISHED"} + + def _run(self, context): all_objects = context.selected_objects if self.bake_selection else context.scene.objects filtered_objects = [i for i in all_objects if i.type == "MESH" and i.plasma_object.enabled] @@ -109,8 +130,6 @@ class LightmapBakeMultiOperator(_LightingOperator, bpy.types.Operator): if lightmap_mod.bake_lightmap: lightmap_mod.image = bake.get_lightmap(i) - return {"FINISHED"} - class LightmapClearMultiOperator(_LightingOperator, bpy.types.Operator): bl_idname = "object.plasma_lightmap_clear"