|
| 1 | +# Timing Checker |
| 2 | + |
| 3 | +The Timing Checker is a validation-layer mode that measures the host-side (CPU) |
| 4 | +duration of every Level Zero API call and reports per-API statistics. It is |
| 5 | +useful for spotting which API calls dominate host time in an application and for |
| 6 | +comparing host overhead across runs. |
| 7 | + |
| 8 | +## What it measures |
| 9 | + |
| 10 | +For every API the checker takes a high-resolution monotonic timestamp when the |
| 11 | +call enters the validation layer (Prologue) and again when it returns |
| 12 | +(Epilogue). The difference is the host-side duration of that call. Per API it |
| 13 | +accumulates: |
| 14 | + |
| 15 | +- **Calls** - number of times the API was called |
| 16 | +- **Total** - sum of all host durations (ns) |
| 17 | +- **Min** / **Max** - fastest and slowest single call (ns) |
| 18 | +- **Avg** - Total / Calls (ns) |
| 19 | + |
| 20 | +The clock is `QueryPerformanceCounter` on Windows and |
| 21 | +`clock_gettime(CLOCK_MONOTONIC_RAW)` on other platforms. |
| 22 | + |
| 23 | +## How to enable |
| 24 | + |
| 25 | +The Timing Checker runs inside the validation layer, so the validation layer must |
| 26 | +be enabled. Its output is written directly to `stderr`, so the loader logging |
| 27 | +variables (`ZEL_ENABLE_LOADER_LOGGING`, `ZEL_LOADER_LOGGING_LEVEL`, |
| 28 | +`ZEL_LOADER_LOG_CONSOLE`) are **not** required. |
| 29 | + |
| 30 | +```bash |
| 31 | +export ZE_ENABLE_VALIDATION_LAYER=1 # turn the validation layer on |
| 32 | +export ZEL_ENABLE_TIMING_CHECKER=1 # enable the Timing Checker |
| 33 | + |
| 34 | +./your_level_zero_application |
| 35 | +``` |
| 36 | + |
| 37 | +On Windows set the same variables with `set` instead of `export`. |
| 38 | + |
| 39 | +## Output modes |
| 40 | + |
| 41 | +The three modes are independent and can be combined. All output goes to `stderr`. |
| 42 | + |
| 43 | +| Environment Variable | Default | Effect | |
| 44 | +|---|---|---| |
| 45 | +| `ZEL_ENABLE_TIMING_CHECKER` | `0` | Enable the checker; a per-API summary table is printed at teardown | |
| 46 | +| `ZEL_TIMING_CHECKER_CSV` | (unset) | Path to also export the per-API statistics as CSV | |
| 47 | +| `ZEL_TIMING_CHECKER_LIVE` | `0` | Also print every individual call's duration as it happens | |
| 48 | + |
| 49 | +### 1. Summary table (default when enabled) |
| 50 | + |
| 51 | +Printed to `stderr` at process teardown. Rows are sorted by `%`, each API's |
| 52 | +share of total host time, highest first: |
| 53 | + |
| 54 | +``` |
| 55 | +==== Level Zero Host API Timing (ns) ==== |
| 56 | +Function Calls Total Min Max Avg % |
| 57 | +zeInitDrivers 2 65581869 666 65581203 32790934 95.84% |
| 58 | +zeCommandListCreateImmediate 1 2783378 2783378 2783378 2783378 4.07% |
| 59 | +zeCommandListAppendSignalEvent 1 1928777 1928777 1928777 1928777 2.82% |
| 60 | +zeDeviceGetMemoryProperties 2 51819 718 51101 25909 0.08% |
| 61 | +zeContextCreate 1 4219 4219 4219 4219 0.01% |
| 62 | +zeDeviceGet 2 682 198 484 341 0.00% |
| 63 | +``` |
| 64 | + |
| 65 | +### 2. CSV export (`ZEL_TIMING_CHECKER_CSV`) |
| 66 | + |
| 67 | +```bash |
| 68 | +export ZEL_TIMING_CHECKER_CSV=timing.csv |
| 69 | +``` |
| 70 | + |
| 71 | +The process id is appended to the filename so concurrent processes do not |
| 72 | +overwrite each other (for example `timing_2449615.csv`). One row per API, sorted |
| 73 | +by `%` (share of total host time) descending. The `%` column is a percentage value: |
| 74 | + |
| 75 | +```csv |
| 76 | +Function,Calls,TotalNs,MinNs,MaxNs,AvgNs,% |
| 77 | +zeInitDrivers,2,65581869,666,65581203,32790934,95.84 |
| 78 | +zeCommandListCreateImmediate,1,2783378,2783378,2783378,2783378,4.07 |
| 79 | +zeContextCreate,1,4219,4219,4219,4219,0.01 |
| 80 | +``` |
| 81 | + |
| 82 | +### 3. Live per-call logging (`ZEL_TIMING_CHECKER_LIVE`) |
| 83 | + |
| 84 | +```bash |
| 85 | +export ZEL_TIMING_CHECKER_LIVE=1 |
| 86 | +``` |
| 87 | + |
| 88 | +Each call is printed to `stderr` as it completes (verbose): |
| 89 | + |
| 90 | +``` |
| 91 | +[timing] zeInitDrivers 66196062 ns |
| 92 | +[timing] zeDeviceGet 566 ns |
| 93 | +[timing] zeDeviceGetProperties 1301 ns |
| 94 | +``` |
| 95 | + |
| 96 | +## Interpreting results |
| 97 | + |
| 98 | +- The measured span includes the underlying driver call plus the small overhead |
| 99 | + of any other validation handlers, so it is best used for relative comparison |
| 100 | + (which APIs cost the most, run-to-run deltas) rather than as an absolute |
| 101 | + driver-only timing. |
| 102 | +- First-call costs such as `zeInit` / `zeInitDrivers` are typically much larger |
| 103 | + than steady-state calls because they perform one-time driver initialization. |
| 104 | + |
| 105 | +## Platform support |
| 106 | + |
| 107 | +Linux and Windows. The checker has no external dependencies and works with any |
| 108 | +Level Zero driver, including the null driver used by the loader tests. |
0 commit comments