perf_counter tools: Provide helper to print percents color
[safe/jmp/linux-2.6] / tools / perf / builtin-top.c
index cdc74cf..95d5c0a 100644 (file)
@@ -66,6 +66,7 @@ static unsigned int           page_size;
 static unsigned int            mmap_pages                      = 16;
 static int                     freq                            =  0;
 static int                     verbose                         =  0;
+static char                    *vmlinux                        =  NULL;
 
 static char                    *sym_filter;
 static unsigned long           filter_start;
@@ -238,7 +239,6 @@ static void print_sym_table(void)
        for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
                struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node);
                struct symbol *sym = (struct symbol *)(syme + 1);
-               char *color = PERF_COLOR_NORMAL;
                double pcnt;
 
                if (++printed > print_entries || syme->snap_count < count_filter)
@@ -247,25 +247,16 @@ static void print_sym_table(void)
                pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) /
                                         sum_ksamples));
 
-               /*
-                * We color high-overhead entries in red, mid-overhead
-                * entries in green - and keep the low overhead places
-                * normal:
-                */
-               if (pcnt >= 5.0) {
-                       color = PERF_COLOR_RED;
-               } else {
-                       if (pcnt >= 0.5)
-                               color = PERF_COLOR_GREEN;
-               }
-
                if (nr_counters == 1)
                        printf("%20.2f - ", syme->weight);
                else
                        printf("%9.1f %10ld - ", syme->weight, syme->snap_count);
 
-               color_fprintf(stdout, color, "%4.1f%%", pcnt);
-               printf(" - %016llx : %s\n", sym->start, sym->name);
+               percent_color_fprintf(stdout, "%4.1f%%", pcnt);
+               printf(" - %016llx : %s", sym->start, sym->name);
+               if (sym->module)
+                       printf("\t[%s]", sym->module->name);
+               printf("\n");
        }
 }
 
@@ -359,12 +350,13 @@ static int parse_symbols(void)
 {
        struct rb_node *node;
        struct symbol  *sym;
+       int modules = vmlinux ? 1 : 0;
 
        kernel_dso = dso__new("[kernel]", sizeof(struct sym_entry));
        if (kernel_dso == NULL)
                return -1;
 
-       if (dso__load_kernel(kernel_dso, NULL, symbol_filter, 1) != 0)
+       if (dso__load_kernel(kernel_dso, vmlinux, symbol_filter, verbose, modules) <= 0)
                goto out_delete_dso;
 
        node = rb_first(&kernel_dso->syms);
@@ -680,6 +672,7 @@ static const struct option options[] = {
                            "system-wide collection from all CPUs"),
        OPT_INTEGER('C', "CPU", &profile_cpu,
                    "CPU to profile on"),
+       OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
        OPT_INTEGER('m', "mmap-pages", &mmap_pages,
                    "number of mmap data pages"),
        OPT_INTEGER('r', "realtime", &realtime_prio,
@@ -709,6 +702,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
 {
        int counter;
 
+       symbol__init();
+
        page_size = sysconf(_SC_PAGE_SIZE);
 
        argc = parse_options(argc, argv, options, top_usage, 0);