Commit 7c0a6144 authored by Yang Jihong's avatar Yang Jihong Committed by Arnaldo Carvalho de Melo
Browse files

perf tools: Fix usage of the verbose variable



The data type of the verbose variable is integer and can be negative,
replace improperly used cases in a unified manner:
 1. if (verbose)        => if (verbose > 0)
 2. if (!verbose)       => if (verbose <= 0)
 3. if (XX && verbose)  => if (XX && verbose > 0)
 4. if (XX && !verbose) => if (XX && verbose <= 0)

Reviewed-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Signed-off-by: default avatarYang Jihong <yangjihong1@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Carsten Haitzler <carsten.haitzler@arm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin KaFai Lau <martin.lau@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Link: https://lore.kernel.org/r/20221220035702.188413-3-yangjihong1@huawei.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 188ac720
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1029,7 +1029,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel,
		if (!ls)
			return -ENOMEM;

		if (aggr_mode == LOCK_AGGR_CALLER && verbose) {
		if (aggr_mode == LOCK_AGGR_CALLER && verbose > 0) {
			ls->callstack = get_callstack(sample, max_stack_depth);
			if (ls->callstack == NULL)
				return -ENOMEM;
@@ -1214,7 +1214,7 @@ static void print_bad_events(int bad, int total)
	for (i = 0; i < BROKEN_MAX; i++)
		broken += bad_hist[i];

	if (quiet || (broken == 0 && !verbose))
	if (quiet || (broken == 0 && verbose <= 0))
		return;

	pr_info("\n=== output for debug===\n\n");
@@ -1529,7 +1529,7 @@ static void print_contention_result(struct lock_contention *con)
			break;
		}

		if (aggr_mode == LOCK_AGGR_CALLER && verbose) {
		if (aggr_mode == LOCK_AGGR_CALLER && verbose > 0) {
			struct map *kmap;
			struct symbol *sym;
			char buf[128];
+2 −2
Original line number Diff line number Diff line
@@ -3629,7 +3629,7 @@ static int record__init_thread_cpu_masks(struct record *rec, struct perf_cpu_map
	for (t = 0; t < rec->nr_threads; t++) {
		__set_bit(perf_cpu_map__cpu(cpus, t).cpu, rec->thread_masks[t].maps.bits);
		__set_bit(perf_cpu_map__cpu(cpus, t).cpu, rec->thread_masks[t].affinity.bits);
		if (verbose) {
		if (verbose > 0) {
			pr_debug("thread_masks[%d]: ", t);
			mmap_cpu_mask__scnprintf(&rec->thread_masks[t].maps, "maps");
			pr_debug("thread_masks[%d]: ", t);
@@ -3726,7 +3726,7 @@ static int record__init_thread_masks_spec(struct record *rec, struct perf_cpu_ma
		}
		rec->thread_masks = thread_masks;
		rec->thread_masks[t] = thread_mask;
		if (verbose) {
		if (verbose > 0) {
			pr_debug("thread_masks[%d]: ", t);
			mmap_cpu_mask__scnprintf(&rec->thread_masks[t].maps, "maps");
			pr_debug("thread_masks[%d]: ", t);
+1 −1
Original line number Diff line number Diff line
@@ -2233,7 +2233,7 @@ static void process_event(struct perf_script *script,
	if (PRINT_FIELD(METRIC))
		perf_sample__fprint_metric(script, thread, evsel, sample, fp);

	if (verbose)
	if (verbose > 0)
		fflush(fp);
}

+2 −2
Original line number Diff line number Diff line
@@ -266,7 +266,7 @@ static void evlist__check_cpu_maps(struct evlist *evlist)
		evsel__group_desc(leader, buf, sizeof(buf));
		pr_warning("  %s\n", buf);

		if (verbose) {
		if (verbose > 0) {
			cpu_map__snprint(leader->core.cpus, buf, sizeof(buf));
			pr_warning("     %s: %s\n", leader->name, buf);
			cpu_map__snprint(evsel->core.cpus, buf, sizeof(buf));
@@ -2493,7 +2493,7 @@ int cmd_stat(int argc, const char **argv)
		if (iostat_mode == IOSTAT_LIST) {
			iostat_list(evsel_list, &stat_config);
			goto out;
		} else if (verbose)
		} else if (verbose > 0)
			iostat_list(evsel_list, &stat_config);
		if (iostat_mode == IOSTAT_RUN && !target__has_cpu(&target))
			target.system_wide = true;
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ struct perf_dlfilter_fns perf_dlfilter_fns;
static int verbose;

#define pr_debug(fmt, ...) do { \
		if (verbose) \
		if (verbose > 0) \
			fprintf(stderr, fmt, ##__VA_ARGS__); \
	} while (0)

Loading