示例#1
0
def invoke_gnuplot(log_path: str, gnuplot_dir: str) -> int:
    """Reads a log file, extracts the data, writes it out to gnuplot_dir and invokes gnuplot on it."""
    os.makedirs(gnuplot_dir, exist_ok=True)
    ret = gnuplot.write_test_file(gnuplot_dir, 'svg')
    if ret:
        logger.error(f'Can not write gnuplot test file with error code {ret}')
        return ret
    with open(log_path) as instream:
        json_data = extract_json(instream)
    table, _t_min, _t_max, rss_min, rss_max = extract_json_as_table(json_data)
    for pid in table:
        log_name = f'{os.path.basename(log_path)}_{pid}'
        labels = extract_labels_from_json(json_data)
        label_lines = []
        y_value = (0.5 * (rss_max[pid] - rss_min[pid])) / 1024**2
        for label_dict in labels:
            t_value = label_dict[KEY_ELAPSED_TIME]
            label_lines.append(
                f'set arrow from {t_value},{y_value} to {t_value},0 lt -1 lw 1'
            )
            label_lines.append(
                f'set label "{label_dict[KEY_LABEL]}" at {t_value},{y_value * 1.025}'
                f' left font ",10" rotate by 90 noenhanced front')
        ret = gnuplot.invoke_gnuplot(
            gnuplot_dir, log_name, table[pid],
            GNUPLOT_PLT.format(name=log_name, labels='\n'.join(label_lines)))
        if ret:
            break
    return ret
示例#2
0
def plot_gnuplot(data: typing.Dict[str, IndexResult],
                 gnuplot_dir: str) -> None:
    if len(data) < 2:  # pragma: no cover
        raise ValueError(f'Can not plot data with only {len(data)} points.')
    # First row is header row, create it then comment out the first item.
    table = [list(IndexResult._fields)[1:] + ['Path']]
    table[0][0] = f'# {table[0][0]}'
    for k in sorted(data.keys()):
        if data[k].size_input > 0 and not data[k].exception:
            table.append(list(data[k][1:]) + [k])
    name = 'IndexFileXML'
    return_code = gnuplot.invoke_gnuplot(gnuplot_dir, name, table,
                                         GNUPLOT_PLT.format(name=name))
    if return_code:  # pragma: no cover
        raise IOError(f'Can not plot gnuplot with return code {return_code}')
    return_code = gnuplot.write_test_file(gnuplot_dir, 'svg')
    if return_code:  # pragma: no cover
        raise IOError(f'Can not plot gnuplot with return code {return_code}')
示例#3
0
def plot_gnuplot(data: typing.Dict[str, HTMLResult], gnuplot_dir: str) -> None:
    if len(data) < 2:
        raise ValueError(f'Can not plot data with only {len(data)} points.')
    # First row is header row, create it then comment out the first item.
    table = [
        # list(HTMLResult._fields) + ['Path']
        ['size_input', 'size_output', 'time', 'Path']
    ]
    table[0][0] = f'# {table[0][0]}'
    for k in sorted(data.keys()):
        if data[k].size_input > 0 and not data[k].exception:
            # table.append(list(data[k]) + [k])
            table.append(
                [data[k].size_input, data[k].size_output, data[k].time, k])
    name = 'ScanFileHTML'
    return_code = gnuplot.invoke_gnuplot(gnuplot_dir, name, table,
                                         GNUPLOT_PLT.format(name=name))
    if return_code:
        raise IOError(f'Can not plot gnuplot with return code {return_code}')
    return_code = gnuplot.write_test_file(gnuplot_dir, 'svg')
    if return_code:
        raise IOError(f'Can not plot gnuplot with return code {return_code}')