Skip to content

Instantly share code, notes, and snippets.

@jakirkham
Forked from jcrist/trace.py
Created January 29, 2021 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakirkham/4150fb05d3071584cc8f210631fb9057 to your computer and use it in GitHub Desktop.
Save jakirkham/4150fb05d3071584cc8f210631fb9057 to your computer and use it in GitHub Desktop.
Dask Execution Tracer
import os
from dask.callbacks import Callback
from dask.dot import dot_graph
class Track(Callback):
def __init__(self, path='dasks', save_every=1):
self.path = path
self.save_every = save_every
self.n = 0
os.mkdir(path)
def _plot(self, dsk, state):
data = {}
func = {}
for key in state['released']:
data[key] = {'color': 'blue'}
for key in state['cache']:
data[key] = {'color': 'red'}
for key in state['finished']:
func[key] = {'color': 'blue'}
for key in state['running']:
func[key] = {'color': 'red'}
filename = os.path.join(self.path, 'part_{:0>4d}'.format(self.n))
dot_graph(dsk, filename=filename, format='gif',
data_attributes=data,
function_attributes=func)
def _pretask(self, key, dsk, state):
if self.n % self.save_every == 0:
self._plot(dsk, state)
self.n += 1
def _finish(self, dsk, state, errored):
self._plot(dsk, state)
self.n += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment