示例#1
0
def test_time_format():
    assert (plot_util.time_format(34) == '34s')
    assert (plot_util.time_format(59) == '59s')
    assert (plot_util.time_format(60) == '0:01')
    assert (plot_util.time_format(119) == '0:01')
    assert (plot_util.time_format(120) == '0:02')
    assert (plot_util.time_format(3694) == '1:01')
示例#2
0
def status_report(jobs, width, height=None, tmp_prefix='', dst_prefix=''):
    '''height, if provided, will limit the number of rows in the table,
       showing first and last rows, row numbers and an elipsis in the middle.'''
    abbreviate_jobs_list = False
    n_begin_rows = 0
    n_end_rows = 0
    if height and height < len(jobs) + 1:  # One row for header
        abbreviate_jobs_list = True

    if abbreviate_jobs_list:
        n_rows = height - 2  # Minus one for header, one for ellipsis
        n_begin_rows = int(n_rows / 2)
        n_end_rows = n_rows - n_begin_rows

    tab = tt.Texttable()
    headings = [
        'plot id', 'k', 'tmp', 'dst', 'wall', 'phase', 'tmp', 'pid', 'stat',
        'mem', 'user', 'sys', 'io'
    ]
    if height:
        headings.insert(0, '#')
    tab.header(headings)
    tab.set_cols_dtype('t' * len(headings))
    tab.set_cols_align('r' * len(headings))
    tab.set_header_align('r' * len(headings))
    for i, j in enumerate(sorted(jobs, key=job.Job.get_time_wall)):
        # Elipsis row
        if abbreviate_jobs_list and i == n_begin_rows:
            row = ['...'] + ([''] * 13)
        # Omitted row
        elif abbreviate_jobs_list and i > n_begin_rows and i < (len(jobs) -
                                                                n_end_rows):
            continue

        # Regular row
        else:
            try:
                with j.proc.oneshot():
                    row = [
                        j.plot_id[:8], j.k,
                        abbr_path(j.tmpdir, tmp_prefix),
                        abbr_path(j.dstdir, dst_prefix),
                        plot_util.time_format(j.get_time_wall()),
                        phase_str(j.progress()),
                        plot_util.human_format(j.get_tmp_usage(), 0),
                        j.proc.pid,
                        j.get_run_status(),
                        plot_util.human_format(j.get_mem_usage(), 1),
                        plot_util.time_format(j.get_time_user()),
                        plot_util.time_format(j.get_time_sys()),
                        plot_util.time_format(j.get_time_iowait())
                    ]
            except (psutil.NoSuchProcess, psutil.AccessDenied):
                # In case the job has disappeared
                row = [j.plot_id[:8]] + (['--'] * 12)

            if height:
                row.insert(0, '%3d' % i)

        tab.add_row(row)

    tab.set_max_width(width)
    tab.set_deco(0)  # No borders
    # return ('tmp dir prefix: %s ; dst dir prefix: %s\n' % (tmp_prefix, dst_prefix)
    return tab.draw()
示例#3
0
def status_report(jobs: typing.List[job.Job],
                  width: int,
                  height: typing.Optional[int] = None,
                  tmp_prefix: str = '',
                  dst_prefix: str = '') -> str:
    '''height, if provided, will limit the number of rows in the table,
       showing first and last rows, row numbers and an elipsis in the middle.'''
    abbreviate_jobs_list = False
    n_begin_rows = 0
    n_end_rows = 0
    if height and height < len(jobs) + 1:  # One row for header
        abbreviate_jobs_list = True

        n_rows = height - 2  # Minus one for header, one for ellipsis
        n_begin_rows = int(n_rows / 2)
        n_end_rows = n_rows - n_begin_rows

    tab = tt.Texttable()
    headings = [
        'plot id', 'k', 'tmp', 'dst', 'wall', 'phase', 'tmp', 'pid', 'stat',
        'mem', 'user', 'sys', 'io'
    ]
    if height:
        headings.insert(0, '#')
    tab.header(headings)
    tab.set_cols_dtype('t' * len(headings))
    tab.set_cols_align('r' * len(headings))
    tab.set_header_align('r' * len(headings))

    for i, j in enumerate(sorted(jobs, key=job.Job.get_time_wall)):
        # Elipsis row
        if abbreviate_jobs_list and i == n_begin_rows:
            row = ['...'] + ([''] * (len(headings) - 1))
        # Omitted row
        elif abbreviate_jobs_list and i > n_begin_rows and i < (len(jobs) -
                                                                n_end_rows):
            continue

        # Regular row
        else:
            try:
                with j.proc.oneshot():
                    row = [
                        j.plot_id[:8],  # Plot ID
                        str(j.k),  # k size
                        abbr_path(j.tmpdir, tmp_prefix),  # Temp directory
                        abbr_path(j.dstdir,
                                  dst_prefix),  # Destination directory
                        plot_util.time_format(j.get_time_wall()),  # Time wall
                        str(j.progress()),  # Overall progress (major:minor)
                        plot_util.human_format(j.get_tmp_usage(),
                                               0),  # Current temp file size
                        j.proc.pid,  # System pid
                        j.get_run_status(),  # OS status for the job process
                        plot_util.human_format(j.get_mem_usage(), 1,
                                               True),  # Memory usage
                        plot_util.time_format(
                            j.get_time_user()),  # user system time
                        plot_util.time_format(j.get_time_sys()),  # system time
                        plot_util.time_format(j.get_time_iowait())  # io wait
                    ]
            except (psutil.NoSuchProcess, psutil.AccessDenied):
                # In case the job has disappeared
                row = [j.plot_id[:8]] + (['--'] * 12)

            if height:
                row.insert(0, '%3d' % i)

        tab.add_row(row)

    tab.set_max_width(width)
    tab.set_deco(0)  # No borders

    return tab.draw()  # type: ignore[no-any-return]