Re: [PATCH] perf: Make printing table easily

From: Hitoshi Mitake
Date: Wed Mar 17 2010 - 03:50:40 EST


On 03/11/10 23:06, Arnaldo Carvalho de Melo wrote:
> Em Thu, Mar 11, 2010 at 01:51:26PM +0100, Ingo Molnar escreveu:
>>
>> * Hitoshi Mitake<mitake@xxxxxxxxxxxxxxxxxxxxx> wrote:
>>
>>> Hi,
>>>
>>> Making table of matrix by printf is painful work,
>>> but it can be found in perf here and there.
>>> So I'd like to propose semi-automation of making table.
>>> New files util/table.c provides stuffs for easy table printing.
>>
>> Looks quite reasonable in theory. I suspect it would be useful to see a few
>> table printing places converted to this facility, to see the simplification
>> factor in practice.
>
> I'm going thru the printing routines now to get them usable by TUI/GUIs,
> starting with a libnewt based browser integrating initially report and
> annotate, after I get the first patch in shape for merging I'll revisit
> this table class of yours :-)

Thanks Arnaldo!

But I noticed fatal weak point of table.c.

User of table.c can reduce the cost of specifying
format specifier for printf, but like this case:

table_add_fixed(t, "%p", SIZE_OF_ADDR);
if (some_cond1)
table_add_fixed(t, "%10d", sizeof(int));
if (some_cond2)
table_add_string(t, "%30s", 30);

table_printf() may produces a lot of if-branch like this:

if (some_cond1 && some_cond2)
table_printf(t, table_test, 2501, "one");
else if (!some_cond1 && some_cond2)
table_printf(t, table_test, "one");
else if (some_cond1 && !some_cond2)
table_printf(t, table_test, 2501);

It is not so good, as Ingo told, at least table of this style
is not useful in real world...

But, how about this style?

First, user declare column with name like this:
table_add_column(t, "num1", "%10d", sizeof(int));

Then, user can add values with name,
table_add_field(t, "num1", 2501);

Finally, flush stored column
table_flush_line(t);

This way will be good for making title of table.
How about this?

Thanks,
Hitoshi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/