Documentation
PLEASE NOTE: This document applies to latest version and not to the latest stable release v2.20
Documentation for other releases can be found by using the version selector in the top right of any doc page.timer
Time task execution for debugging and performance profiling.
This module provides named timers that can be started, stopped, and read to measure elapsed time between tasks. Useful for debugging, performance optimization, and IoT devices with limited resources.
Attributes
check_mode:
support: full
Parameters
| Parameter | Required | Type | Values | Description |
|---|---|---|---|---|
| name | true | string | ||
| precision | string | ms us ns |
||
| state | string | started stopped read |
Examples
Basic timing
- name: Start performance timer
timer:
name: app_startup
state: started
- name: Run application startup
command: ./startup.sh
- name: Stop timer and get elapsed time
timer:
name: app_startup
state: stopped
register: elapsed
- name: Log startup time
debug:
msg: "Startup took {{ elapsed.extra.elapsed_ms }} milliseconds"
Read without stopping
- timer:
name: long_operation
state: started
- command: ./step1.sh
- timer:
name: long_operation
state: read
register: checkpoint
- debug:
msg: "Checkpoint: {{ checkpoint.extra.elapsed_ms }}ms elapsed"
- command: ./step2.sh
- timer:
name: long_operation
state: stopped
register: final_time
Multiple timers with different precision
- timer:
name: fast_op
state: started
precision: us
- command: ./fast.sh
- timer:
name: fast_op
state: stopped
register: fast_elapsed
- debug:
msg: "Fast op took {{ fast_elapsed.extra.elapsed_us }} microseconds"