Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf utils: Check verbose flag properly

It now can have negative value to suppress the message entirely. So it
needs to check it being positive.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: kernel-team@lge.com
Link: http://lkml.kernel.org/r/20170217081742.17417-3-namhyung@kernel.org
[ Adjust fuzz on tools/perf/util/pmu.c, add > 0 checks in many other places ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
bb963e16 80df1988

+52 -52
+1 -1
tools/perf/builtin-diff.c
··· 744 744 745 745 first = false; 746 746 747 - if (verbose || data__files_cnt > 2) 747 + if (verbose > 0 || data__files_cnt > 2) 748 748 data__fprintf(); 749 749 750 750 /* Don't sort callchain for perf diff */
+2 -2
tools/perf/builtin-mem.c
··· 42 42 43 43 fprintf(stderr, "%-13s%-*s%s\n", 44 44 e->tag, 45 - verbose ? 25 : 0, 46 - verbose ? perf_mem_events__name(j) : "", 45 + verbose > 0 ? 25 : 0, 46 + verbose > 0 ? perf_mem_events__name(j) : "", 47 47 e->supported ? ": available" : ""); 48 48 } 49 49 exit(0);
+1 -1
tools/perf/builtin-record.c
··· 432 432 try_again: 433 433 if (perf_evsel__open(pos, pos->cpus, pos->threads) < 0) { 434 434 if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) { 435 - if (verbose) 435 + if (verbose > 0) 436 436 ui__warning("%s\n", msg); 437 437 goto try_again; 438 438 }
+1 -1
tools/perf/builtin-report.c
··· 1009 1009 * providing it only in verbose mode not to bloat too 1010 1010 * much struct symbol. 1011 1011 */ 1012 - if (verbose) { 1012 + if (verbose > 0) { 1013 1013 /* 1014 1014 * XXX: Need to provide a less kludgy way to ask for 1015 1015 * more space per symbol, the u32 is for the index on
+6 -6
tools/perf/builtin-sched.c
··· 460 460 BUG_ON(!sched->tasks); 461 461 sched->tasks[task->nr] = task; 462 462 463 - if (verbose) 463 + if (verbose > 0) 464 464 printf("registered task #%ld, PID %ld (%s)\n", sched->nr_tasks, pid, comm); 465 465 466 466 return task; ··· 794 794 const u32 pid = perf_evsel__intval(evsel, sample, "pid"); 795 795 struct task_desc *waker, *wakee; 796 796 797 - if (verbose) { 797 + if (verbose > 0) { 798 798 printf("sched_wakeup event %p\n", evsel); 799 799 800 800 printf(" ... pid %d woke up %s/%d\n", sample->tid, comm, pid); ··· 822 822 int cpu = sample->cpu; 823 823 s64 delta; 824 824 825 - if (verbose) 825 + if (verbose > 0) 826 826 printf("sched_switch event %p\n", evsel); 827 827 828 828 if (cpu >= MAX_CPUS || cpu < 0) ··· 870 870 goto out_put; 871 871 } 872 872 873 - if (verbose) { 873 + if (verbose > 0) { 874 874 printf("fork event\n"); 875 875 printf("... parent: %s/%d\n", thread__comm_str(parent), parent->tid); 876 876 printf("... child: %s/%d\n", thread__comm_str(child), child->tid); ··· 1573 1573 1574 1574 timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp)); 1575 1575 color_fprintf(stdout, color, " %12s secs ", stimestamp); 1576 - if (new_shortname || (verbose && sched_in->tid)) { 1576 + if (new_shortname || (verbose > 0 && sched_in->tid)) { 1577 1577 const char *pid_color = color; 1578 1578 1579 1579 if (thread__has_color(sched_in)) ··· 2050 2050 2051 2051 if (thread__resolve_callchain(thread, cursor, evsel, sample, 2052 2052 NULL, NULL, sched->max_stack + 2) != 0) { 2053 - if (verbose) 2053 + if (verbose > 0) 2054 2054 error("Failed to resolve callchain. Skipping\n"); 2055 2055 2056 2056 return;
+3 -3
tools/perf/builtin-stat.c
··· 573 573 if (errno == EINVAL || errno == ENOSYS || 574 574 errno == ENOENT || errno == EOPNOTSUPP || 575 575 errno == ENXIO) { 576 - if (verbose) 576 + if (verbose > 0) 577 577 ui__warning("%s event is not supported by the kernel.\n", 578 578 perf_evsel__name(counter)); 579 579 counter->supported = false; ··· 582 582 !(counter->leader->nr_members > 1)) 583 583 continue; 584 584 } else if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) { 585 - if (verbose) 585 + if (verbose > 0) 586 586 ui__warning("%s\n", msg); 587 587 goto try_again; 588 588 } ··· 2539 2539 2540 2540 status = 0; 2541 2541 for (run_idx = 0; forever || run_idx < run_count; run_idx++) { 2542 - if (run_count != 1 && verbose) 2542 + if (run_count != 1 && verbose > 0) 2543 2543 fprintf(output, "[ perf stat: executing run #%d ... ]\n", 2544 2544 run_idx + 1); 2545 2545
+1 -1
tools/perf/builtin-top.c
··· 871 871 if (perf_evsel__open(counter, top->evlist->cpus, 872 872 top->evlist->threads) < 0) { 873 873 if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) { 874 - if (verbose) 874 + if (verbose > 0) 875 875 ui__warning("%s\n", msg); 876 876 goto try_again; 877 877 }
+3 -3
tools/perf/builtin-trace.c
··· 1399 1399 return &trace->syscalls.table[id]; 1400 1400 1401 1401 out_cant_read: 1402 - if (verbose) { 1402 + if (verbose > 0) { 1403 1403 fprintf(trace->output, "Problems reading syscall %d", id); 1404 1404 if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) 1405 1405 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); ··· 1801 1801 bool print_dso, bool print_sym) 1802 1802 { 1803 1803 1804 - if ((verbose || print_dso) && al->map) 1804 + if ((verbose > 0 || print_dso) && al->map) 1805 1805 fprintf(f, "%s@", al->map->dso->long_name); 1806 1806 1807 - if ((verbose || print_sym) && al->sym) 1807 + if ((verbose > 0 || print_sym) && al->sym) 1808 1808 fprintf(f, "%s+0x%" PRIx64, al->sym->name, 1809 1809 al->addr - al->sym->start); 1810 1810 else if (al->map)
+1 -1
tools/perf/pmu-events/json.c
··· 49 49 int err; 50 50 int fd = open(fn, O_RDONLY); 51 51 52 - if (fd < 0 && verbose && fn) { 52 + if (fd < 0 && verbose > 0 && fn) { 53 53 pr_err("Error opening events file '%s': %s\n", fn, 54 54 strerror(errno)); 55 55 }
+1 -1
tools/perf/tests/attr.c
··· 144 144 int vcnt = min(verbose, (int) sizeof(v) - 1); 145 145 char cmd[3*PATH_MAX]; 146 146 147 - if (verbose) 147 + if (verbose > 0) 148 148 vcnt++; 149 149 150 150 snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s",
+1 -1
tools/perf/tests/builtin-test.c
··· 299 299 if (!dont_fork) { 300 300 pr_debug("test child forked, pid %d\n", getpid()); 301 301 302 - if (!verbose) { 302 + if (verbose <= 0) { 303 303 int nullfd = open("/dev/null", O_WRONLY); 304 304 305 305 if (nullfd >= 0) {
+1 -1
tools/perf/tests/code-reading.c
··· 599 599 continue; 600 600 } 601 601 602 - if (verbose) { 602 + if (verbose > 0) { 603 603 char errbuf[512]; 604 604 perf_evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); 605 605 pr_debug("perf_evlist__open() failed!\n%s\n", errbuf);
+1 -1
tools/perf/tests/fdarray.c
··· 19 19 { 20 20 int printed = 0; 21 21 22 - if (!verbose) 22 + if (verbose <= 0) 23 23 return 0; 24 24 25 25 printed += fprintf(fp, "\n%s: ", prefix);
+1 -1
tools/perf/tests/llvm.c
··· 76 76 * Skip this test if user's .perfconfig doesn't set [llvm] section 77 77 * and clang is not found in $PATH, and this is not perf test -v 78 78 */ 79 - if (!force && (verbose == 0 && 79 + if (!force && (verbose <= 0 && 80 80 !llvm_param.user_set_param && 81 81 llvm__search_clang())) { 82 82 pr_debug("No clang and no verbosive, skip this test\n");
+1 -1
tools/perf/tests/parse-events.c
··· 1808 1808 { 1809 1809 char msg[1024]; 1810 1810 1811 - if (!verbose) 1811 + if (verbose <= 0) 1812 1812 return; 1813 1813 1814 1814 vsnprintf(msg, sizeof(msg), warn, params);
+2 -2
tools/perf/tests/perf-record.c
··· 172 172 173 173 err = perf_evlist__parse_sample(evlist, event, &sample); 174 174 if (err < 0) { 175 - if (verbose) 175 + if (verbose > 0) 176 176 perf_event__fprintf(event, stderr); 177 177 pr_debug("Couldn't parse sample\n"); 178 178 goto out_delete_evlist; 179 179 } 180 180 181 - if (verbose) { 181 + if (verbose > 0) { 182 182 pr_info("%" PRIu64" %d ", sample.time, sample.cpu); 183 183 perf_event__fprintf(event, stderr); 184 184 }
+1 -1
tools/perf/tests/python-use.c
··· 15 15 int ret; 16 16 17 17 if (asprintf(&cmd, "echo \"import sys ; sys.path.append('%s'); import perf\" | %s %s", 18 - PYTHONPATH, PYTHON, verbose ? "" : "2> /dev/null") < 0) 18 + PYTHONPATH, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0) 19 19 return -1; 20 20 21 21 ret = system(cmd) ? -1 : 0;
+3 -3
tools/perf/tests/thread-map.c
··· 109 109 TEST_ASSERT_VAL("failed to allocate thread_map", 110 110 threads); 111 111 112 - if (verbose) 112 + if (verbose > 0) 113 113 thread_map__fprintf(threads, stderr); 114 114 115 115 TEST_ASSERT_VAL("failed to remove thread", ··· 117 117 118 118 TEST_ASSERT_VAL("thread_map count != 1", threads->nr == 1); 119 119 120 - if (verbose) 120 + if (verbose > 0) 121 121 thread_map__fprintf(threads, stderr); 122 122 123 123 TEST_ASSERT_VAL("failed to remove thread", ··· 125 125 126 126 TEST_ASSERT_VAL("thread_map count != 0", threads->nr == 0); 127 127 128 - if (verbose) 128 + if (verbose > 0) 129 129 thread_map__fprintf(threads, stderr); 130 130 131 131 TEST_ASSERT_VAL("failed to not remove thread",
+1 -1
tools/perf/tests/vmlinux-kallsyms.c
··· 168 168 err = -1; 169 169 } 170 170 171 - if (!verbose) 171 + if (verbose <= 0) 172 172 goto out; 173 173 174 174 header_printed = false;
+3 -3
tools/perf/ui/browsers/map.c
··· 73 73 74 74 if (ui_browser__show(&browser->b, browser->map->dso->long_name, 75 75 "Press ESC to exit, %s / to search", 76 - verbose ? "" : "restart with -v to use") < 0) 76 + verbose > 0 ? "" : "restart with -v to use") < 0) 77 77 return -1; 78 78 79 79 while (1) { ··· 81 81 82 82 switch (key) { 83 83 case '/': 84 - if (verbose) 84 + if (verbose > 0) 85 85 map_browser__search(browser); 86 86 default: 87 87 break; ··· 117 117 118 118 if (maxaddr < pos->end) 119 119 maxaddr = pos->end; 120 - if (verbose) { 120 + if (verbose > 0) { 121 121 u32 *idx = symbol__browser_index(pos); 122 122 *idx = mb.b.nr_entries; 123 123 }
+1 -1
tools/perf/ui/hist.c
··· 648 648 ret += fmt->width(fmt, &dummy_hpp, hists); 649 649 } 650 650 651 - if (verbose && hists__has(hists, sym)) /* Addr + origin */ 651 + if (verbose > 0 && hists__has(hists, sym)) /* Addr + origin */ 652 652 ret += 3 + BITS_PER_LONG / 4; 653 653 654 654 return ret;
+1 -1
tools/perf/util/annotate.c
··· 1768 1768 printf("%-*.*s----\n", 1769 1769 graph_dotted_len, graph_dotted_len, graph_dotted_line); 1770 1770 1771 - if (verbose) 1771 + if (verbose > 0) 1772 1772 symbol__annotate_hits(sym, evsel); 1773 1773 1774 1774 list_for_each_entry(pos, &notes->src->source, node) {
+1 -1
tools/perf/util/dso.c
··· 1058 1058 { 1059 1059 if (!dso) 1060 1060 return strlen("[unknown]"); 1061 - if (verbose) 1061 + if (verbose > 0) 1062 1062 return dso->long_name_len; 1063 1063 1064 1064 return dso->short_name_len;
+3 -3
tools/perf/util/hist.c
··· 69 69 */ 70 70 if (h->ms.sym) { 71 71 symlen = h->ms.sym->namelen + 4; 72 - if (verbose) 72 + if (verbose > 0) 73 73 symlen += BITS_PER_LONG / 4 + 2 + 3; 74 74 hists__new_col_len(hists, HISTC_SYMBOL, symlen); 75 75 } else { ··· 93 93 if (h->branch_info) { 94 94 if (h->branch_info->from.sym) { 95 95 symlen = (int)h->branch_info->from.sym->namelen + 4; 96 - if (verbose) 96 + if (verbose > 0) 97 97 symlen += BITS_PER_LONG / 4 + 2 + 3; 98 98 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); 99 99 ··· 107 107 108 108 if (h->branch_info->to.sym) { 109 109 symlen = (int)h->branch_info->to.sym->namelen + 4; 110 - if (verbose) 110 + if (verbose > 0) 111 111 symlen += BITS_PER_LONG / 4 + 2 + 3; 112 112 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); 113 113
+4 -4
tools/perf/util/pmu.c
··· 745 745 } 746 746 } 747 747 748 - if (verbose) 748 + if (verbose > 0) 749 749 printf("Required parameter '%s' not specified\n", term->config); 750 750 751 751 return -1; ··· 803 803 804 804 format = pmu_find_format(formats, term->config); 805 805 if (!format) { 806 - if (verbose) 806 + if (verbose > 0) 807 807 printf("Invalid event/parameter '%s'\n", term->config); 808 808 if (err) { 809 809 char *pmu_term = pmu_formats_string(formats); ··· 847 847 val = term->val.num; 848 848 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) { 849 849 if (strcmp(term->val.str, "?")) { 850 - if (verbose) { 850 + if (verbose > 0) { 851 851 pr_info("Invalid sysfs entry %s=%s\n", 852 852 term->config, term->val.str); 853 853 } ··· 1232 1232 printf("%*s", 8, "["); 1233 1233 wordwrap(aliases[j].desc, 8, columns, 0); 1234 1234 printf("]\n"); 1235 - if (verbose) 1235 + if (verbose > 0) 1236 1236 printf("%*s%s/%s/\n", 8, "", aliases[j].pmu, aliases[j].str); 1237 1237 } else 1238 1238 printf(" %-50s [Kernel PMU event]\n", aliases[j].name);
+1 -1
tools/perf/util/probe-event.c
··· 594 594 pr_debug("try to find information at %" PRIx64 " in %s\n", addr, 595 595 tp->module ? : "kernel"); 596 596 597 - dinfo = debuginfo_cache__open(tp->module, verbose == 0); 597 + dinfo = debuginfo_cache__open(tp->module, verbose <= 0); 598 598 if (dinfo) 599 599 ret = debuginfo__find_probe_point(dinfo, 600 600 (unsigned long)addr, pp);
+4 -4
tools/perf/util/sort.c
··· 151 151 if (!dso_l || !dso_r) 152 152 return cmp_null(dso_r, dso_l); 153 153 154 - if (verbose) { 154 + if (verbose > 0) { 155 155 dso_name_l = dso_l->long_name; 156 156 dso_name_r = dso_r->long_name; 157 157 } else { ··· 172 172 size_t size, unsigned int width) 173 173 { 174 174 if (map && map->dso) { 175 - const char *dso_name = !verbose ? map->dso->short_name : 176 - map->dso->long_name; 175 + const char *dso_name = verbose > 0 ? map->dso->long_name : 176 + map->dso->short_name; 177 177 return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name); 178 178 } 179 179 ··· 261 261 { 262 262 size_t ret = 0; 263 263 264 - if (verbose) { 264 + if (verbose > 0) { 265 265 char o = map ? dso__symtab_origin(map->dso) : '!'; 266 266 ret += repsep_snprintf(bf, size, "%-#*llx %c ", 267 267 BITS_PER_LONG / 4 + 2, ip, o);
+1 -1
tools/perf/util/stat.c
··· 344 344 for (i = 0; i < 3; i++) 345 345 update_stats(&ps->res_stats[i], count[i]); 346 346 347 - if (verbose) { 347 + if (verbose > 0) { 348 348 fprintf(config->output, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", 349 349 perf_evsel__name(counter), count[0], count[1], count[2]); 350 350 }
+1 -1
tools/perf/util/symbol-elf.c
··· 213 213 214 214 static char *demangle_sym(struct dso *dso, int kmodule, const char *elf_name) 215 215 { 216 - int demangle_flags = verbose ? (DMGL_PARAMS | DMGL_ANSI) : DMGL_NO_OPTS; 216 + int demangle_flags = verbose > 0 ? (DMGL_PARAMS | DMGL_ANSI) : DMGL_NO_OPTS; 217 217 char *demangled = NULL; 218 218 219 219 /*