Is there anyway in an asset to access the total ti...
# ask-community
c
Is there anyway in an asset to access the total time it took to run the asset?
c
Hi Clovis. In an asset if you want to see how long it took the prior run for the asset to run, you could do something like this:
Copy code
event_records = context.instance.get_event_records(
        EventRecordsFilter(
            DagsterEventType.ASSET_MATERIALIZATION, asset_key=AssetKey("some_asset")
        ),
        limit=1,
    )
    if event_records:
        step_stats = next(
            iter(context.instance.get_run_step_stats(event_records[0].run_id, ["some_asset"]))
        )
        step_time = step_stats.end_time - step_stats.start_time
        <http://context.log.info|context.log.info>(f"step_time: {step_time}")
which basically fetches the latest run id for a given asset, and fetches the step stats from the run to calculate how long the step took