A profiler for resource use. Records the following each timestep 1. Time in seconds since the epoch 2. Memory usage in MB 3. % CPU usage Examples -------- >>> from operator import add, mul >>> from dask.threaded import get >>> dsk = {'x': 1, 'y': (a
| 120 | |
| 121 | |
| 122 | class ResourceProfiler(Callback): |
| 123 | """A profiler for resource use. |
| 124 | |
| 125 | Records the following each timestep |
| 126 | 1. Time in seconds since the epoch |
| 127 | 2. Memory usage in MB |
| 128 | 3. % CPU usage |
| 129 | |
| 130 | Examples |
| 131 | -------- |
| 132 | |
| 133 | >>> from operator import add, mul |
| 134 | >>> from dask.threaded import get |
| 135 | >>> dsk = {'x': 1, 'y': (add, 'x', 10), 'z': (mul, 'y', 2)} |
| 136 | >>> with ResourceProfiler() as prof: |
| 137 | ... get(dsk, 'z') |
| 138 | 22 |
| 139 | |
| 140 | These results can be visualized in a bokeh plot using the ``visualize`` |
| 141 | method. Note that this requires bokeh to be installed. |
| 142 | |
| 143 | >>> prof.visualize() # doctest: +SKIP |
| 144 | |
| 145 | You can activate the profiler globally |
| 146 | |
| 147 | >>> prof.register() |
| 148 | |
| 149 | If you use the profiler globally you will need to clear out old results |
| 150 | manually. |
| 151 | |
| 152 | >>> prof.clear() |
| 153 | |
| 154 | Note that when used as a context manager data will be collected throughout |
| 155 | the duration of the enclosed block. In contrast, when registered globally |
| 156 | data will only be collected while a dask scheduler is active. |
| 157 | |
| 158 | >>> prof.unregister() |
| 159 | """ |
| 160 | |
| 161 | def __init__(self, dt=1): |
| 162 | self._dt = dt |
| 163 | self._entered = False |
| 164 | self._tracker = None |
| 165 | self.results = [] |
| 166 | self.start_time = None |
| 167 | self.end_time = None |
| 168 | |
| 169 | def _is_running(self): |
| 170 | return self._tracker is not None and self._tracker.is_alive() |
| 171 | |
| 172 | def _start_collect(self): |
| 173 | if not self._is_running(): |
| 174 | self._tracker = _Tracker(self._dt) |
| 175 | self._tracker.start() |
| 176 | self._tracker.parent_conn.send("collect") |
| 177 | |
| 178 | def _stop_collect(self): |
| 179 | if self._is_running(): |
no outgoing calls
searching dependent graphs…