Plot resource usage in a bokeh plot. Parameters ---------- results : sequence Output of ResourceProfiler.results start_time : float Start time of the profile in seconds end_time : float End time of the profile in seconds palette : string, optional
(results, start_time, end_time, palette="Viridis", **kwargs)
| 245 | |
| 246 | |
| 247 | def plot_resources(results, start_time, end_time, palette="Viridis", **kwargs): |
| 248 | """Plot resource usage in a bokeh plot. |
| 249 | |
| 250 | Parameters |
| 251 | ---------- |
| 252 | results : sequence |
| 253 | Output of ResourceProfiler.results |
| 254 | start_time : float |
| 255 | Start time of the profile in seconds |
| 256 | end_time : float |
| 257 | End time of the profile in seconds |
| 258 | palette : string, optional |
| 259 | Name of the bokeh palette to use, must be a member of |
| 260 | bokeh.palettes.all_palettes. |
| 261 | **kwargs |
| 262 | Other keyword arguments, passed to bokeh.figure. These will override |
| 263 | all defaults set by plot_resources. |
| 264 | |
| 265 | Returns |
| 266 | ------- |
| 267 | The completed bokeh plot object. |
| 268 | """ |
| 269 | bp = import_required("bokeh.plotting", _BOKEH_MISSING_MSG) |
| 270 | from bokeh import palettes |
| 271 | from bokeh.models import LinearAxis, Range1d |
| 272 | |
| 273 | defaults = dict( |
| 274 | title="Profile Results", |
| 275 | tools="save,reset,xwheel_zoom,xpan", |
| 276 | toolbar_location="above", |
| 277 | width=800, |
| 278 | height=300, |
| 279 | ) |
| 280 | # Support plot_width and plot_height for backwards compatibility |
| 281 | if "plot_width" in kwargs: |
| 282 | kwargs["width"] = kwargs.pop("plot_width") |
| 283 | if BOKEH_VERSION().major >= 3: |
| 284 | warnings.warn("Use width instead of plot_width with Bokeh >= 3") |
| 285 | if "plot_height" in kwargs: |
| 286 | kwargs["height"] = kwargs.pop("plot_height") |
| 287 | if BOKEH_VERSION().major >= 3: |
| 288 | warnings.warn("Use height instead of plot_height with Bokeh >= 3") |
| 289 | |
| 290 | # Drop `label_size` to match `plot_cache` and `plot_tasks` kwargs |
| 291 | if "label_size" in kwargs: |
| 292 | kwargs.pop("label_size") |
| 293 | |
| 294 | defaults.update(**kwargs) |
| 295 | |
| 296 | if results: |
| 297 | t, mem, cpu = zip(*results) |
| 298 | left = start_time |
| 299 | right = end_time |
| 300 | t = [i - left for i in t] |
| 301 | p = bp.figure( |
| 302 | y_range=fix_bounds(0, max(cpu), 100), |
| 303 | x_range=fix_bounds(0, right - left, 1), |
| 304 | **defaults, |
no test coverage detected
searching dependent graphs…