eina_btlog: allows continuous running on input, flush when possible.

eina_btlog will make a table of the backtrace and then must compute
columns length.

However, if not running in such mode (ie: show_compact/-c), we don't
need to queue lines or compute column lengths.

Also, now that we accept non-backtrace lines, like other output
interleaved, then flush the table once such line is found, this will
restart the table columns for the next output, but at least allows
eina_btlog to run on a live output, such as:

       myapp 2>&1 | eina_btlog
This commit is contained in:
Gustavo Sverzut Barbieri 2016-12-06 14:00:55 -02:00
parent f0e13ccad9
commit 8342548356
1 changed files with 11 additions and 0 deletions

View File

@ -432,10 +432,17 @@ main(int argc, char **argv)
return 1;
}
repeat:
while (fgets(buf, sizeof(buf) - 1, stdin))
{
btl = bt_append(btl, buf);
if (show_compact) goto do_show;
bt = eina_list_last_data_get(btl);
if (bt && !bt->bin_dir) break; /* flush once first non-bt is found */
}
/* compute columns for expanded display */
for (i = 0; i < 6; i++) cols[i] = 0;
EINA_LIST_FOREACH(btl, l, bt)
{
if (!bt->bin_dir) continue;
@ -456,6 +463,8 @@ main(int argc, char **argv)
len = strlen(bt->func_name);
if (len > cols[5]) cols[5] = len;
}
do_show:
EINA_LIST_FOREACH(btl, l, bt)
{
if (bt->comment && show_comments)
@ -505,6 +514,8 @@ main(int argc, char **argv)
free(bt->comment);
free(bt);
}
/* if not EOF, then we just flushed due non-bt line, try again */
if (!feof(stdin)) goto repeat;
eina_shutdown();