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)
| 264 | |
| 265 | |
| 266 | def plot_resources(results, start_time, end_time, palette="Viridis", **kwargs): |
| 267 | """Plot resource usage in a bokeh plot. |
| 268 | |
| 269 | Parameters |
| 270 | ---------- |
| 271 | results : sequence |
| 272 | Output of ResourceProfiler.results |
| 273 | start_time : float |
| 274 | Start time of the profile in seconds |
| 275 | end_time : float |
| 276 | End time of the profile in seconds |
| 277 | palette : string, optional |
| 278 | Name of the bokeh palette to use, must be a member of |
| 279 | bokeh.palettes.all_palettes. |
| 280 | **kwargs |
| 281 | Other keyword arguments, passed to bokeh.figure. These will override |
| 282 | all defaults set by plot_resources. |
| 283 | |
| 284 | Returns |
| 285 | ------- |
| 286 | The completed bokeh plot object. |
| 287 | """ |
| 288 | bp = import_required("bokeh.plotting", _BOKEH_MISSING_MSG) |
| 289 | from bokeh import palettes |
| 290 | from bokeh.models import LinearAxis, Range1d |
| 291 | |
| 292 | defaults = dict( |
| 293 | title="Profile Results", |
| 294 | tools="save,reset,xwheel_zoom,xpan", |
| 295 | toolbar_location="above", |
| 296 | width=800, |
| 297 | height=300, |
| 298 | ) |
| 299 | # Support plot_width and plot_height for backwards compatibility |
| 300 | if "plot_width" in kwargs: |
| 301 | kwargs["width"] = kwargs.pop("plot_width") |
| 302 | if BOKEH_VERSION().major >= 3: |
| 303 | warnings.warn("Use width instead of plot_width with Bokeh >= 3") |
| 304 | if "plot_height" in kwargs: |
| 305 | kwargs["height"] = kwargs.pop("plot_height") |
| 306 | if BOKEH_VERSION().major >= 3: |
| 307 | warnings.warn("Use height instead of plot_height with Bokeh >= 3") |
| 308 | |
| 309 | # Drop `label_size` to match `plot_cache` and `plot_tasks` kwargs |
| 310 | if "label_size" in kwargs: |
| 311 | kwargs.pop("label_size") |
| 312 | |
| 313 | defaults.update(**kwargs) |
| 314 | |
| 315 | if results: |
| 316 | t, mem, cpu = zip(*results) |
| 317 | left = start_time |
| 318 | right = end_time |
| 319 | t = [i - left for i in t] |
| 320 | p = bp.figure( |
| 321 | y_range=fix_bounds(0, max(cpu), 100), |
| 322 | x_range=fix_bounds(0, right - left, 1), |
| 323 | **defaults, |
no test coverage detected