TODO: this can probably be replaced with simply reading the file
    ourselves!

def count_events (env, evtpath, filter):
    """TODO: this can probably be replaced with simply reading the file
    ourselves!

    """
    with env.slurp (argv=['dmstat', '%s%s[cols energy]' % (evtpath, filter)], linebreak=True) as s:
        for etype, payload in s:
            if etype != 'stdout':
                continue

            if b'good:' not in payload:
                continue

            return int (payload.split ()[-1])

    raise Exception ('parsing of dmlist output failed')