perf hists: Use bigger buffer for stdio headers
[cascardo/linux.git] / tools / perf / ui / stdio / hist.c
index f04a631..c8dca34 100644 (file)
@@ -528,8 +528,8 @@ static int print_hierarchy_indent(const char *sep, int indent,
        return fprintf(fp, "%-.*s", (indent - 2) * HIERARCHY_INDENT, line);
 }
 
-static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
-                                 const char *sep, FILE *fp)
+static int hists__fprintf_hierarchy_headers(struct hists *hists,
+                                           struct perf_hpp *hpp, FILE *fp)
 {
        bool first_node, first_col;
        int indent;
@@ -538,6 +538,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
        unsigned header_width = 0;
        struct perf_hpp_fmt *fmt;
        struct perf_hpp_list_node *fmt_node;
+       const char *sep = symbol_conf.field_sep;
 
        indent = hists->nr_hpp_node;
 
@@ -549,7 +550,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
                                    struct perf_hpp_list_node, list);
 
        perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
-               fmt->header(fmt, hpp, hists);
+               fmt->header(fmt, hpp, hists, 0, NULL);
                fprintf(fp, "%s%s", hpp->buf, sep ?: "  ");
        }
 
@@ -569,7 +570,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
                                header_width += fprintf(fp, "+");
                        first_col = false;
 
-                       fmt->header(fmt, hpp, hists);
+                       fmt->header(fmt, hpp, hists, 0, NULL);
 
                        header_width += fprintf(fp, "%s", trim(hpp->buf));
                }
@@ -623,20 +624,28 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
        return 2;
 }
 
-static int
-hists__fprintf_hierarchy_headers(struct hists *hists,
-                                struct perf_hpp *hpp,
-                                FILE *fp)
+static void fprintf_line(struct hists *hists, struct perf_hpp *hpp,
+                        int line, FILE *fp)
 {
-       struct perf_hpp_list_node *fmt_node;
        struct perf_hpp_fmt *fmt;
+       const char *sep = symbol_conf.field_sep;
+       bool first = true;
+       int span = 0;
 
-       list_for_each_entry(fmt_node, &hists->hpp_formats, list) {
-               perf_hpp_list__for_each_format(&fmt_node->hpp, fmt)
-                       perf_hpp__reset_width(fmt, hists);
-       }
+       hists__for_each_format(hists, fmt) {
+               if (perf_hpp__should_skip(fmt, hists))
+                       continue;
 
-       return print_hierarchy_header(hists, hpp, symbol_conf.field_sep, fp);
+               if (!first && !span)
+                       fprintf(fp, "%s", sep ?: "  ");
+               else
+                       first = false;
+
+               fmt->header(fmt, hpp, hists, line, &span);
+
+               if (!span)
+                       fprintf(fp, "%s", hpp->buf);
+       }
 }
 
 static int
@@ -644,28 +653,23 @@ hists__fprintf_standard_headers(struct hists *hists,
                                struct perf_hpp *hpp,
                                FILE *fp)
 {
+       struct perf_hpp_list *hpp_list = hists->hpp_list;
        struct perf_hpp_fmt *fmt;
        unsigned int width;
        const char *sep = symbol_conf.field_sep;
        bool first = true;
-
-       hists__for_each_format(hists, fmt) {
-               if (perf_hpp__should_skip(fmt, hists))
-                       continue;
-
-               if (!first)
-                       fprintf(fp, "%s", sep ?: "  ");
-               else
-                       first = false;
-
-               fmt->header(fmt, hpp, hists);
-               fprintf(fp, "%s", hpp->buf);
+       int line;
+
+       for (line = 0; line < hpp_list->nr_header_lines; line++) {
+               /* first # is displayed one level up */
+               if (line)
+                       fprintf(fp, "# ");
+               fprintf_line(hists, hpp, line, fp);
+               fprintf(fp, "\n");
        }
 
-       fprintf(fp, "\n");
-
        if (sep)
-               return 1;
+               return hpp_list->nr_header_lines;
 
        first = true;
 
@@ -689,12 +693,12 @@ hists__fprintf_standard_headers(struct hists *hists,
 
        fprintf(fp, "\n");
        fprintf(fp, "#\n");
-       return 3;
+       return hpp_list->nr_header_lines + 2;
 }
 
 static int hists__fprintf_headers(struct hists *hists, FILE *fp)
 {
-       char bf[96];
+       char bf[1024];
        struct perf_hpp dummy_hpp = {
                .buf    = bf,
                .size   = sizeof(bf),
@@ -713,7 +717,6 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
                      int max_cols, float min_pcnt, FILE *fp,
                      bool use_callchain)
 {
-       struct perf_hpp_fmt *fmt;
        struct rb_node *nd;
        size_t ret = 0;
        const char *sep = symbol_conf.field_sep;
@@ -724,8 +727,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
 
        init_rem_hits();
 
-       hists__for_each_format(hists, fmt)
-               perf_hpp__reset_width(fmt, hists);
+       hists__reset_column_width(hists);
 
        if (symbol_conf.col_width_list_str)
                perf_hpp__set_user_width(symbol_conf.col_width_list_str);