ripe-alarm-8919
03/06/2025, 9:17 PMflow_time =
runtime_finished and step_name = "end"
minus
runtime_init and step_name = "start"
But we observed that:
1. in local mode, start_step's runtime_finished
is called after end_step's runtime_finished
. meaning the former would be more accurate. (i assume that the longer the more accurate when measuring flow run time for my use case. ) curious if this is some known impl details or just our specific env (multithread exec order?)
2. i think step_init
is called before runtime_init
, but there’s no step_finished
what’s the best approach if we want to measure and emit metrics about a flow’s run’s startedAt
and endedAt
? which are the best hooks to recommend? https://github.com/Netflix/metaflow/blob/master/metaflow/decorators.py#L360victorious-lawyer-58417
03/06/2025, 9:30 PMfrom metaflow import FlowSpec, step
from functools import wraps
import time
def timing(f):
@wraps(f)
def wrapper(self):
start = time.time()
f(self)
self.duration = time.time() - start
print(f"Task took {self.duration} seconds")
return wrapper
class TimingFlow(FlowSpec):
@timing
@step
def start(self):
for i in range(3):
print(i)
time.sleep(1)
self.next(self.end)
@step
def end(self):
print("done!")
if __name__ == '__main__':
TimingFlow()
victorious-lawyer-58417
03/06/2025, 9:31 PMvictorious-lawyer-58417
03/06/2025, 9:33 PMdef timing(f):
@wraps(f)
def wrapper(self):
if f.__name__ == 'start':
self.flow_start = time.time()
f(self)
if f.__name__ == 'end':
self.duration = time.time() - self.flow_start
print(f"Task took {self.duration} seconds")
return wrapper
ripe-alarm-8919
03/06/2025, 9:42 PMmammoth-monitor-19889
03/06/2025, 9:48 PMripe-alarm-8919
03/06/2025, 9:50 PM@poetry
flow level decorator right? can we use the flow level decorator to add this custom decorator(? or wrapper) for every step?square-wire-39606
03/06/2025, 10:40 PMripe-alarm-8919
03/06/2025, 10:52 PMbrash-wolf-45301
03/06/2025, 11:02 PMbrash-wolf-45301
03/06/2025, 11:05 PMsquare-wire-39606
03/06/2025, 11:19 PMvictorious-lawyer-58417
03/06/2025, 11:24 PMtask_decorate
hook to attach behavior pre/post-step
• you can then execute code before/after the user code in your wrapper - just call `step_func()` to invoke user code in the middle. You can create artifacts too to store timing info etc
• there are a few different mechanisms for including the decorator by default in all runs, but you can do it e.g. via Metaflow config or an env var or a custom base classvictorious-lawyer-58417
03/07/2025, 12:30 AM