Skip to content

Commit

Permalink
perf probe: Rewrite show_one_line() to make it simpler
Browse files Browse the repository at this point in the history
Cc: Masami Hiramatsu <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Franck Bui-Huu <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
fbuihuu authored and acmel committed Dec 21, 2010
1 parent 62c15fc commit befe341
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions tools/perf/util/probe-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,28 +290,21 @@ static int get_real_path(const char *raw_path, const char *comp_dir,
static int show_one_line(FILE *fp, int l, bool skip, bool show_num)
{
char buf[LINEBUF_SIZE];
const char *color = PERF_COLOR_BLUE;
const char *color = show_num ? "" : PERF_COLOR_BLUE;
const char *prefix = NULL;

if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
goto error;
if (!skip) {
if (show_num)
fprintf(stdout, "%7d %s", l, buf);
else
color_fprintf(stdout, color, " %s", buf);
}

while (strlen(buf) == LINEBUF_SIZE - 1 &&
buf[LINEBUF_SIZE - 2] != '\n') {
do {
if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
goto error;
if (!skip) {
if (show_num)
fprintf(stdout, "%s", buf);
else
color_fprintf(stdout, color, "%s", buf);
if (skip)
continue;
if (!prefix) {
prefix = show_num ? "%7d " : " ";
color_fprintf(stdout, color, prefix, l);
}
}
color_fprintf(stdout, color, "%s", buf);

} while (strchr(buf, '\n') == NULL);

return 0;
error:
Expand Down

0 comments on commit befe341

Please sign in to comment.