I wanted to share a new open-source resource I published to the Ignition Exchange to help track script runtimes and catch unhandled exceptions across Ignition projects without cluttering Gateway logs.
The Perspective Script Execution Profiler & Analysis Suite allows you to wrap Jython functions, Perspective transforms, or Gateway events with a simple @profiler decorator. It captures execution durations, errors, and stack traces into MS SQL Server, and includes a built-in Perspective UI to analyze runtime performance in real time.
Features
Universal @profiler Decorator: Import the script library, then add the decorator to your function. Drop it on Project Library scripts, Perspective transforms, or event handlers to measure latency.
Database Logging: Captures durations, status, and full stack traces directly to MS SQL Server.
Perspective Dashboard: Includes dynamic XY time-series charts and filterable data tables for quick troubleshooting.
Zero-Config Setup: Automatically initializes its database schema on Gateway startup.
Maintenance Utility: Built-in views to quickly clean up historical performance logs.
You are using import with project library scripts. This is unwise, and not entirely safe, especially in Ignition v8.1.
You are importing system in your project scripts. This is unnecessary.
Your try - except clauses will only catch jython errors, not any java errors. Since you are wrapping database operations that typically only throw java errors, it suggests that much of this is untested.
You are using import with project library scripts. This is unwise, and not entirely safe, especially in Ignition v8.1.
You are importing system in your project scripts. This is unnecessary.
I actually import system and my project scripts (usually via my vscode extension and only in the Project Library scripts) to get intellisense on IDEs. I remember reading something about issues on the forum but have yet to run into anything.
Importing system at the top level of a library script is unnecessary but harmless--a tiny bit of wasted time.
Importing across project library scripts is dangerous, particularly in v8.1 and older. Mainly because of this longstanding bug:
This extension is actively promoting importing profiler, where it should be directing users to reference the fully-qualified scriptProfiler.profiler everywhere.
Not to derail the topic but I have some composition functionality that probably has 60 selective imports and I use this across the entire project without issue (8.1.45 -> 8.3.10). This is anecdotal so I guess YMMV.
Example:
# `composition`
from someservice import SomeService
from system.date import now
def composeSomeService(dependency1=None, dependency2=None):
...
return SomeService(dependency1, dependency2)
# Client call tag event script, perspective, etc.
someService = composition.composeSomeService()
someService.doWork()
If I understand correctly from the post referenced, you should be able to do selective imports or module imports as long as it is at the top level of the script and it is 8.3. Scripts that are not in Project Library should not use any imports except modules that are in site-packages/stdlib and java libraries.
I also know that calling import in the designer scope has caused many headaches for me so I try not to do that.