A profiler for dask execution at the scheduler cache level. Records the following information for each task: 1. Key 2. Task 3. Size metric 4. Cache entry time in seconds since the epoch 5. Cache exit time in seconds since the epoch Examples -----
| 296 | |
| 297 | |
| 298 | class CacheProfiler(Callback): |
| 299 | """A profiler for dask execution at the scheduler cache level. |
| 300 | |
| 301 | Records the following information for each task: |
| 302 | 1. Key |
| 303 | 2. Task |
| 304 | 3. Size metric |
| 305 | 4. Cache entry time in seconds since the epoch |
| 306 | 5. Cache exit time in seconds since the epoch |
| 307 | |
| 308 | Examples |
| 309 | -------- |
| 310 | |
| 311 | >>> from operator import add, mul |
| 312 | >>> from dask.threaded import get |
| 313 | >>> from dask.diagnostics import CacheProfiler |
| 314 | >>> dsk = {'x': 1, 'y': (add, 'x', 10), 'z': (mul, 'y', 2)} |
| 315 | >>> with CacheProfiler() as prof: |
| 316 | ... get(dsk, 'z') |
| 317 | 22 |
| 318 | |
| 319 | >>> prof.results # doctest: +SKIP |
| 320 | [CacheData(key='y', task=(add, 'x', 10), metric=1, cache_time=..., free_time=...), |
| 321 | CacheData(key='z', task=(mul, 'y', 2), metric=1, cache_time=..., free_time=...)] |
| 322 | |
| 323 | The default is to count each task (``metric`` is 1 for all tasks). Other |
| 324 | functions may used as a metric instead through the ``metric`` keyword. For |
| 325 | example, the ``nbytes`` function found in ``cachey`` can be used to measure |
| 326 | the number of bytes in the cache. |
| 327 | |
| 328 | >>> from cachey import nbytes # doctest: +SKIP |
| 329 | >>> with CacheProfiler(metric=nbytes) as prof: # doctest: +SKIP |
| 330 | ... get(dsk, 'z') |
| 331 | 22 |
| 332 | |
| 333 | The profiling results can be visualized in a bokeh plot using the |
| 334 | ``visualize`` method. Note that this requires bokeh to be installed. |
| 335 | |
| 336 | >>> prof.visualize() # doctest: +SKIP |
| 337 | |
| 338 | You can activate the profiler globally |
| 339 | |
| 340 | >>> prof.register() |
| 341 | |
| 342 | If you use the profiler globally you will need to clear out old results |
| 343 | manually. |
| 344 | |
| 345 | >>> prof.clear() |
| 346 | >>> prof.unregister() |
| 347 | |
| 348 | """ |
| 349 | |
| 350 | def __init__(self, metric=None, metric_name=None): |
| 351 | self.clear() |
| 352 | self._metric = metric or (lambda value: 1) |
| 353 | if metric_name: |
| 354 | self._metric_name = metric_name |
| 355 | elif metric: |
no outgoing calls