perf report: Add consistent spacing rules
[deliverable/linux.git] / Documentation / perf_counter / builtin-report.c
index 56c664d1b628196e539138d24e24b6579a95f4b4..e930b4e02335d50a03dc8135064c02a7bbe55c4c 100644 (file)
 
 static char            const *input_name = "perf.data";
 static char            *vmlinux = NULL;
-static char            *sort_order = "comm,dso";
+
+static char            default_sort_order[] = "comm,dso";
+static char            *sort_order = default_sort_order;
+
 static int             input;
 static int             show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
 
@@ -103,9 +106,10 @@ static struct dso *dsos__findnew(const char *name)
        if (!dso)
                goto out_delete_dso;
 
-       nr = dso__load(dso, NULL);
+       nr = dso__load(dso, NULL, verbose);
        if (nr < 0) {
-               fprintf(stderr, "Failed to open: %s\n", name);
+               if (verbose)
+                       fprintf(stderr, "Failed to open: %s\n", name);
                goto out_delete_dso;
        }
        if (!nr && verbose) {
@@ -139,7 +143,7 @@ static int load_kernel(void)
        if (!kernel_dso)
                return -1;
 
-       err = dso__load_kernel(kernel_dso, vmlinux, NULL);
+       err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose);
        if (err) {
                dso__delete(kernel_dso);
                kernel_dso = NULL;
@@ -340,11 +344,11 @@ sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
 static size_t
 sort__thread_print(FILE *fp, struct hist_entry *self)
 {
-       return fprintf(fp, " %16s:%5d", self->thread->comm ?: "", self->thread->pid);
+       return fprintf(fp, "%16s:%5d", self->thread->comm ?: "", self->thread->pid);
 }
 
 static struct sort_entry sort_thread = {
-       .header = "         Command: Pid ",
+       .header = "         Command:  Pid",
        .cmp    = sort__thread_cmp,
        .print  = sort__thread_print,
 };
@@ -378,11 +382,11 @@ sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
 static size_t
 sort__comm_print(FILE *fp, struct hist_entry *self)
 {
-       return fprintf(fp, "  %16s", self->thread->comm);
+       return fprintf(fp, "%16s", self->thread->comm);
 }
 
 static struct sort_entry sort_comm = {
-       .header         = "          Command",
+       .header         = "         Command",
        .cmp            = sort__comm_cmp,
        .collapse       = sort__comm_collapse,
        .print          = sort__comm_print,
@@ -412,13 +416,13 @@ static size_t
 sort__dso_print(FILE *fp, struct hist_entry *self)
 {
        if (self->dso)
-               return fprintf(fp, "  %-25s", self->dso->name);
+               return fprintf(fp, "%-25s", self->dso->name);
 
-       return fprintf(fp, "  %016llx         ", (__u64)self->ip);
+       return fprintf(fp, "%016llx         ", (__u64)self->ip);
 }
 
 static struct sort_entry sort_dso = {
-       .header = " Shared Object            ",
+       .header = "Shared Object            ",
        .cmp    = sort__dso_cmp,
        .print  = sort__dso_print,
 };
@@ -445,18 +449,18 @@ sort__sym_print(FILE *fp, struct hist_entry *self)
        size_t ret = 0;
 
        if (verbose)
-               ret += fprintf(fp, "  %#018llx", (__u64)self->ip);
+               ret += fprintf(fp, "%#018llx  ", (__u64)self->ip);
 
        if (self->sym)
-               ret += fprintf(fp, "  %s", self->sym->name);
+               ret += fprintf(fp, "%s", self->sym->name);
        else
-               ret += fprintf(fp, "  %#016llx", (__u64)self->ip);
+               ret += fprintf(fp, "%#016llx", (__u64)self->ip);
 
        return ret;
 }
 
 static struct sort_entry sort_sym = {
-       .header = " Symbol",
+       .header = "Symbol",
        .cmp    = sort__sym_cmp,
        .print  = sort__sym_print,
 };
@@ -549,8 +553,10 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, uint64_t total_samples)
        } else
                ret = fprintf(fp, "%12d ", self->count);
 
-       list_for_each_entry(se, &hist_entry__sort_list, list)
+       list_for_each_entry(se, &hist_entry__sort_list, list) {
+               fprintf(fp, "  ");
                ret += se->print(fp, self);
+       }
 
        ret += fprintf(fp, "\n");
 
@@ -717,11 +723,14 @@ static size_t output__fprintf(FILE *fp, uint64_t total_samples)
        struct rb_node *nd;
        size_t ret = 0;
 
+       fprintf(fp, "\n");
+       fprintf(fp, "#\n");
+       fprintf(fp, "# (%Ld profiler events)\n", (__u64)total_samples);
        fprintf(fp, "#\n");
 
        fprintf(fp, "# Overhead");
        list_for_each_entry(se, &hist_entry__sort_list, list)
-               fprintf(fp, " %s", se->header);
+               fprintf(fp, "  %s", se->header);
        fprintf(fp, "\n");
 
        fprintf(fp, "# ........");
@@ -729,7 +738,7 @@ static size_t output__fprintf(FILE *fp, uint64_t total_samples)
                int i;
 
                fprintf(fp, "  ");
-               for (i = 0; i < strlen(se->header)-1; i++)
+               for (i = 0; i < strlen(se->header); i++)
                        fprintf(fp, ".");
        }
        fprintf(fp, "\n");
@@ -741,6 +750,13 @@ static size_t output__fprintf(FILE *fp, uint64_t total_samples)
                ret += hist_entry__fprintf(fp, pos, total_samples);
        }
 
+       if (!strcmp(sort_order, default_sort_order)) {
+               fprintf(fp, "#\n");
+               fprintf(fp, "# (For more details, try: perf report --sort comm,dso,symbol)\n");
+               fprintf(fp, "#\n");
+       }
+       fprintf(fp, "\n");
+
        return ret;
 }
 
This page took 0.040073 seconds and 5 git commands to generate.