bootchart-improved

/

Draft for now.

Linux kernel upstream repository contains "bootchart" scripts written in Perl to visualize initcall_debug output. The Perl script parses dmesg output text and generate SVG format text to standard output. The saved SVG text can be opened by Web browser and any other svg compatible viewer.

However the visual of that SVG file is not so good.

T.B.D.

def bootchart_initcall(ax, data, label):
    tab10 = pyplot.get_cmap('tab10')

    ax.broken_barh(
        data,
        (-0.5, 0.5),
        facecolors=[tab10(i % 10) for i in range(len(data)-1)]
    )

    ax.set_ylim([-1.1, 0.1])
    ax.set_xlim([0.2, 1.3])

    fontsize = 12
    while fontsize > 0.1:
        textbase = -10000
        bbox = None
        artists = []
        for i in range(len(data)-1):

            if data[i][1] < 0.0002:
                continue

            dataaxis = data[i][0] + data[i][1]/2
            widthaxis = -0.5

            textaxis = dataaxis
            if dataaxis < textbase:
                textaxis = textbase

            text = ax.text(textaxis, widthaxis - 0.25,
                           label[i], rotation=270, rotation_mode='anchor', fontsize=fontsize)

            if bbox is None:
                bbox = _get_text_bbox(ax, text)

            textbase = textaxis + bbox.width
            text.set_x(textaxis - bbox.width/2)

            artists.append(text)

        if textbase < data[-1][0]*1.5:

            datac = (data[0][0] + data[-1][0] + data[-1][1])/2
            textc = (data[0][0] + textbase)/2
            d = textc - datac

            for text in artists:
                x, _ = text.get_position()
                text.set_x(x - d)

            break

        fontsize *= 0.95
        for text in artists:
            text.remove()
        artists.clear()

    j = 0
    for i in range(len(data)-1):

        if data[i][1] < 0.0002:
            continue

        dataaxis = data[i][0] + data[i][1]/2
        widthaxis = -0.5

        x, _ = artists[j].get_position()

        ax.annotate('', xy=(dataaxis, widthaxis), xycoords='data',
                    xytext=(x, widthaxis - 0.25), textcoords='data',
                    arrowprops=dict(arrowstyle='-', color='black', lw=0.1))

        j += 1