fix: registered timestamp on timer node
This commit is contained in:
+15
-31
@@ -5,20 +5,20 @@ Measures workflow execution time from start to finish
|
||||
|
||||
import time
|
||||
|
||||
# Global storage for workflow timers
|
||||
_TIMER_START_TIMES = {}
|
||||
|
||||
|
||||
class MetaHubTimerNode:
|
||||
"""
|
||||
Timer node that measures workflow execution time.
|
||||
Timer node that records a timestamp for workflow execution timing.
|
||||
|
||||
Usage:
|
||||
1. Place this node at the START of your workflow
|
||||
2. Connect any input (image, latent, conditioning, etc.) to trigger it early
|
||||
1. Place this node where you want to START measuring time
|
||||
2. Connect any input (clip, image, latent, conditioning) to trigger it
|
||||
3. Connect the 'elapsed_time' output to MetaHub Save Node's 'generation_time_override'
|
||||
|
||||
The timer starts when this node first executes in a workflow run.
|
||||
How it works:
|
||||
- This node records a timestamp when it executes
|
||||
- The Save Node calculates elapsed time from this timestamp
|
||||
- Place multiple timers to measure different workflow stages
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@@ -41,8 +41,8 @@ class MetaHubTimerNode:
|
||||
|
||||
def measure_time(self, clip=None, image=None, latent=None, conditioning=None):
|
||||
"""
|
||||
Measures elapsed time since this timer node was first executed.
|
||||
Each timer node instance tracks its own independent timing.
|
||||
Records the current timestamp when this node executes.
|
||||
The Save Node will calculate elapsed time from this timestamp.
|
||||
|
||||
Args:
|
||||
clip: Optional CLIP input (passed through unchanged)
|
||||
@@ -51,30 +51,14 @@ class MetaHubTimerNode:
|
||||
conditioning: Optional CONDITIONING input (passed through unchanged)
|
||||
|
||||
Returns:
|
||||
(clip, image, latent, conditioning, elapsed_time): Original inputs and elapsed time in seconds
|
||||
(clip, image, latent, conditioning, start_timestamp): Original inputs and start timestamp
|
||||
"""
|
||||
current_time = time.time()
|
||||
# Return current timestamp - Save Node will calculate elapsed time
|
||||
start_timestamp = time.time()
|
||||
print(f"[MetaHub Timer] Recording start timestamp: {start_timestamp}")
|
||||
|
||||
# Use this node instance's ID as unique timer identifier
|
||||
# This allows multiple independent timers in the same workflow
|
||||
timer_id = id(self)
|
||||
|
||||
# Start timer on first execution of this specific timer instance
|
||||
if timer_id not in _TIMER_START_TIMES:
|
||||
_TIMER_START_TIMES[timer_id] = current_time
|
||||
print(f"[MetaHub Timer] Started timer #{timer_id}")
|
||||
|
||||
# Cleanup old timers (keep only last 50 to support multiple timers)
|
||||
if len(_TIMER_START_TIMES) > 50:
|
||||
oldest_key = min(_TIMER_START_TIMES.keys(), key=lambda k: _TIMER_START_TIMES[k])
|
||||
del _TIMER_START_TIMES[oldest_key]
|
||||
|
||||
# Calculate elapsed time
|
||||
elapsed = current_time - _TIMER_START_TIMES[timer_id]
|
||||
print(f"[MetaHub Timer] Elapsed time: {elapsed:.2f}s")
|
||||
|
||||
# Passthrough the inputs unchanged + return elapsed time
|
||||
return (clip, image, latent, conditioning, elapsed)
|
||||
# Passthrough the inputs unchanged + return start timestamp
|
||||
return (clip, image, latent, conditioning, start_timestamp)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
|
||||
Reference in New Issue
Block a user