Skip to content

Commit

Permalink
Add option to profile the importer
Browse files Browse the repository at this point in the history
  • Loading branch information
30350n committed Jun 3, 2024
1 parent 317c36d commit 11254fd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ images/template*
env/
.venv/
release/
*.prof
19 changes: 18 additions & 1 deletion pcb2blender_importer/importer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import io, random, re, shutil, struct, tempfile
import io, random, re, shutil, struct, sys, tempfile
from dataclasses import dataclass
from enum import Enum
from math import inf, radians
Expand All @@ -21,6 +21,13 @@
from .blender_addon_utils import ErrorHelper
from .materials import *

ENABLE_PROFILER = False
if ENABLE_PROFILER:
from cProfile import Profile

def has_debugger_attached():
return sys.gettrace() is not None

PCB = "pcb.wrl"
COMPONENTS = "components"
LAYERS = "layers"
Expand Down Expand Up @@ -200,6 +207,10 @@ def __init__(self):
def execute(self, context):
filepath = Path(self.filepath)

if ENABLE_PROFILER and has_debugger_attached():
profiler = Profile()
profiler.enable()

# import boards

if (pcb := self.import_pcb3d(context, filepath)) == {"CANCELLED"}:
Expand Down Expand Up @@ -276,6 +287,12 @@ def execute(self, context):
if self.enhance_materials:
enhance_materials(self.new_materials)

if ENABLE_PROFILER and has_debugger_attached():
profiler.disable()
profiler.dump_stats(
Path(__file__).parent.resolve() / Path(__file__).with_suffix(".prof").name
)

return {"FINISHED"}

def import_pcb3d(self, context, filepath):
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ gitpython
pytest
pytest-blender
requests
snakeviz

fake-bpy-module
numpy
Expand Down

0 comments on commit 11254fd

Please sign in to comment.