Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57d52415 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

Merge branch 'perf/stat' into perf/core



Merge reason: the perf stat improvements are tested and ready now.

Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parents e04d1b23 c63ca0c0
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ static const u64 amd_perfmon_event_map[] =
  [PERF_COUNT_HW_CACHE_MISSES]			= 0x0081,
  [PERF_COUNT_HW_BRANCH_INSTRUCTIONS]		= 0x00c2,
  [PERF_COUNT_HW_BRANCH_MISSES]			= 0x00c3,
  [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND]	= 0x00d0, /* "Decoder empty" event */
  [PERF_COUNT_HW_STALLED_CYCLES_BACKEND]	= 0x00d1, /* "Dispatch stalls" event */
};

static u64 amd_pmu_event_map(int hw_event)
+21 −10
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ static u64 intel_perfmon_event_map[PERF_COUNT_HW_MAX] __read_mostly =
  [PERF_COUNT_HW_BUS_CYCLES]		= 0x013c,
};

static struct event_constraint intel_core_event_constraints[] =
static struct event_constraint intel_core_event_constraints[] __read_mostly =
{
	INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */
	INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */
@@ -47,7 +47,7 @@ static struct event_constraint intel_core_event_constraints[] =
	EVENT_CONSTRAINT_END
};

static struct event_constraint intel_core2_event_constraints[] =
static struct event_constraint intel_core2_event_constraints[] __read_mostly =
{
	FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
	FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
@@ -70,7 +70,7 @@ static struct event_constraint intel_core2_event_constraints[] =
	EVENT_CONSTRAINT_END
};

static struct event_constraint intel_nehalem_event_constraints[] =
static struct event_constraint intel_nehalem_event_constraints[] __read_mostly =
{
	FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
	FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
@@ -86,19 +86,19 @@ static struct event_constraint intel_nehalem_event_constraints[] =
	EVENT_CONSTRAINT_END
};

static struct extra_reg intel_nehalem_extra_regs[] =
static struct extra_reg intel_nehalem_extra_regs[] __read_mostly =
{
	INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0xffff),
	EVENT_EXTRA_END
};

static struct event_constraint intel_nehalem_percore_constraints[] =
static struct event_constraint intel_nehalem_percore_constraints[] __read_mostly =
{
	INTEL_EVENT_CONSTRAINT(0xb7, 0),
	EVENT_CONSTRAINT_END
};

static struct event_constraint intel_westmere_event_constraints[] =
static struct event_constraint intel_westmere_event_constraints[] __read_mostly =
{
	FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
	FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
@@ -110,7 +110,7 @@ static struct event_constraint intel_westmere_event_constraints[] =
	EVENT_CONSTRAINT_END
};

static struct event_constraint intel_snb_event_constraints[] =
static struct event_constraint intel_snb_event_constraints[] __read_mostly =
{
	FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
	FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
@@ -123,21 +123,21 @@ static struct event_constraint intel_snb_event_constraints[] =
	EVENT_CONSTRAINT_END
};

static struct extra_reg intel_westmere_extra_regs[] =
static struct extra_reg intel_westmere_extra_regs[] __read_mostly =
{
	INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0xffff),
	INTEL_EVENT_EXTRA_REG(0xbb, MSR_OFFCORE_RSP_1, 0xffff),
	EVENT_EXTRA_END
};

static struct event_constraint intel_westmere_percore_constraints[] =
static struct event_constraint intel_westmere_percore_constraints[] __read_mostly =
{
	INTEL_EVENT_CONSTRAINT(0xb7, 0),
	INTEL_EVENT_CONSTRAINT(0xbb, 0),
	EVENT_CONSTRAINT_END
};

static struct event_constraint intel_gen_event_constraints[] =
static struct event_constraint intel_gen_event_constraints[] __read_mostly =
{
	FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
	FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
@@ -1423,6 +1423,11 @@ static __init int intel_pmu_init(void)
		x86_pmu.enable_all = intel_pmu_nhm_enable_all;
		x86_pmu.extra_regs = intel_nehalem_extra_regs;

		/* UOPS_ISSUED.STALLED_CYCLES */
		intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x180010e;
		/* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */
		intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x1803fb1;

		if (ebx & 0x40) {
			/*
			 * Erratum AAJ80 detected, we work it around by using
@@ -1463,6 +1468,12 @@ static __init int intel_pmu_init(void)
		x86_pmu.enable_all = intel_pmu_nhm_enable_all;
		x86_pmu.pebs_constraints = intel_westmere_pebs_event_constraints;
		x86_pmu.extra_regs = intel_westmere_extra_regs;

		/* UOPS_ISSUED.STALLED_CYCLES */
		intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x180010e;
		/* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */
		intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x1803fb1;

		pr_cont("Westmere events, ");
		break;

+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ enum perf_hw_id {
	PERF_COUNT_HW_BRANCH_INSTRUCTIONS	= 4,
	PERF_COUNT_HW_BRANCH_MISSES		= 5,
	PERF_COUNT_HW_BUS_CYCLES		= 6,
	PERF_COUNT_HW_STALLED_CYCLES_FRONTEND	= 7,
	PERF_COUNT_HW_STALLED_CYCLES_BACKEND	= 8,

	PERF_COUNT_HW_MAX,			/* non-ABI */
};
+249 −35
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#include "util/evlist.h"
#include "util/evsel.h"
#include "util/debug.h"
#include "util/color.h"
#include "util/header.h"
#include "util/cpumap.h"
#include "util/thread.h"
@@ -65,14 +66,56 @@ static struct perf_event_attr default_attrs[] = {
  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS		},

  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES		},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_FRONTEND	},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_BACKEND	},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_INSTRUCTIONS		},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS	},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_MISSES		},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CACHE_REFERENCES	},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CACHE_MISSES		},

};

/*
 * Detailed stats:
 */
static struct perf_event_attr detailed_attrs[] = {

  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK		},
  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES	},
  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CPU_MIGRATIONS		},
  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS		},

  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES		},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_FRONTEND	},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_BACKEND	},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_INSTRUCTIONS		},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS	},
  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_MISSES		},

  { .type = PERF_TYPE_HW_CACHE,
    .config =
	 PERF_COUNT_HW_CACHE_L1D		<<  0  |
	(PERF_COUNT_HW_CACHE_OP_READ		<<  8) |
	(PERF_COUNT_HW_CACHE_RESULT_ACCESS	<< 16)				},

  { .type = PERF_TYPE_HW_CACHE,
    .config =
	 PERF_COUNT_HW_CACHE_L1D		<<  0  |
	(PERF_COUNT_HW_CACHE_OP_READ		<<  8) |
	(PERF_COUNT_HW_CACHE_RESULT_MISS	<< 16)				},

  { .type = PERF_TYPE_HW_CACHE,
    .config =
	 PERF_COUNT_HW_CACHE_LL			<<  0  |
	(PERF_COUNT_HW_CACHE_OP_READ		<<  8) |
	(PERF_COUNT_HW_CACHE_RESULT_ACCESS	<< 16)				},

  { .type = PERF_TYPE_HW_CACHE,
    .config =
	 PERF_COUNT_HW_CACHE_LL			<<  0  |
	(PERF_COUNT_HW_CACHE_OP_READ		<<  8) |
	(PERF_COUNT_HW_CACHE_RESULT_MISS	<< 16)				},
};

struct perf_evlist		*evsel_list;

static bool			system_wide			=  false;
@@ -86,6 +129,8 @@ static pid_t target_pid = -1;
static pid_t			target_tid			= -1;
static pid_t			child_pid			= -1;
static bool			null_run			=  false;
static bool			detailed_run			=  false;
static bool			sync_run			=  false;
static bool			big_num				=  true;
static int			big_num_opt			=  -1;
static const char		*cpu_list;
@@ -156,7 +201,11 @@ static double stddev_stats(struct stats *stats)

struct stats			runtime_nsecs_stats[MAX_NR_CPUS];
struct stats			runtime_cycles_stats[MAX_NR_CPUS];
struct stats			runtime_stalled_cycles_front_stats[MAX_NR_CPUS];
struct stats			runtime_stalled_cycles_back_stats[MAX_NR_CPUS];
struct stats			runtime_branches_stats[MAX_NR_CPUS];
struct stats			runtime_cacherefs_stats[MAX_NR_CPUS];
struct stats			runtime_l1_dcache_stats[MAX_NR_CPUS];
struct stats			walltime_nsecs_stats;

static int create_perf_stat_counter(struct perf_evsel *evsel)
@@ -192,6 +241,29 @@ static inline int nsec_counter(struct perf_evsel *evsel)
	return 0;
}

/*
 * Update various tracking values we maintain to print
 * more semantic information such as miss/hit ratios,
 * instruction rates, etc:
 */
static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
{
	if (perf_evsel__match(counter, SOFTWARE, SW_TASK_CLOCK))
		update_stats(&runtime_nsecs_stats[0], count[0]);
	else if (perf_evsel__match(counter, HARDWARE, HW_CPU_CYCLES))
		update_stats(&runtime_cycles_stats[0], count[0]);
	else if (perf_evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_FRONTEND))
		update_stats(&runtime_stalled_cycles_front_stats[0], count[0]);
	else if (perf_evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_BACKEND))
		update_stats(&runtime_stalled_cycles_back_stats[0], count[0]);
	else if (perf_evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS))
		update_stats(&runtime_branches_stats[0], count[0]);
	else if (perf_evsel__match(counter, HARDWARE, HW_CACHE_REFERENCES))
		update_stats(&runtime_cacherefs_stats[0], count[0]);
	else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_L1D))
		update_stats(&runtime_l1_dcache_stats[0], count[0]);
}

/*
 * Read out the results of a single counter:
 * aggregate counts across CPUs in system-wide mode
@@ -217,12 +289,7 @@ static int read_counter_aggr(struct perf_evsel *counter)
	/*
	 * Save the full runtime - to allow normalization during printout:
	 */
	if (perf_evsel__match(counter, SOFTWARE, SW_TASK_CLOCK))
		update_stats(&runtime_nsecs_stats[0], count[0]);
	if (perf_evsel__match(counter, HARDWARE, HW_CPU_CYCLES))
		update_stats(&runtime_cycles_stats[0], count[0]);
	if (perf_evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS))
		update_stats(&runtime_branches_stats[0], count[0]);
	update_shadow_stats(counter, count);

	return 0;
}
@@ -242,12 +309,7 @@ static int read_counter(struct perf_evsel *counter)

		count = counter->counts->cpu[cpu].values;

		if (perf_evsel__match(counter, SOFTWARE, SW_TASK_CLOCK))
			update_stats(&runtime_nsecs_stats[cpu], count[0]);
		if (perf_evsel__match(counter, HARDWARE, HW_CPU_CYCLES))
			update_stats(&runtime_cycles_stats[cpu], count[0]);
		if (perf_evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS))
			update_stats(&runtime_branches_stats[cpu], count[0]);
		update_shadow_stats(counter, count);
	}

	return 0;
@@ -315,13 +377,18 @@ static int run_perf_stat(int argc __used, const char **argv)

	list_for_each_entry(counter, &evsel_list->entries, node) {
		if (create_perf_stat_counter(counter) < 0) {
			if (errno == -EPERM || errno == -EACCES) {
			if (errno == EINVAL || errno == ENOSYS || errno == ENOENT) {
				if (verbose)
					ui__warning("%s event is not supported by the kernel.\n",
						    event_name(counter));
				continue;
			}

			if (errno == EPERM || errno == EACCES) {
				error("You may not have permission to collect %sstats.\n"
				      "\t Consider tweaking"
				      " /proc/sys/kernel/perf_event_paranoid or running as root.",
				      system_wide ? "system-wide " : "");
			} else if (errno == ENOENT) {
				error("%s event is not supported. ", event_name(counter));
			} else {
				error("open_counter returned with %d (%s). "
				      "/bin/dmesg may provide additional information.\n",
@@ -372,6 +439,16 @@ static int run_perf_stat(int argc __used, const char **argv)
	return WEXITSTATUS(status);
}

static void print_noise_pct(double total, double avg)
{
	double pct = 0.0;

	if (avg)
		pct = 100.0*total/avg;

	fprintf(stderr, "  ( +-%6.2f%% )", pct);
}

static void print_noise(struct perf_evsel *evsel, double avg)
{
	struct perf_stat *ps;
@@ -380,8 +457,7 @@ static void print_noise(struct perf_evsel *evsel, double avg)
		return;

	ps = evsel->priv;
	fprintf(stderr, "   ( +- %7.3f%% )",
			100 * stddev_stats(&ps->res_stats[0]) / avg);
	print_noise_pct(stddev_stats(&ps->res_stats[0]), avg);
}

static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg)
@@ -404,8 +480,99 @@ static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg)
		return;

	if (perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK))
		fprintf(stderr, " # %10.3f CPUs ",
				avg / avg_stats(&walltime_nsecs_stats));
		fprintf(stderr, " # %8.3f CPUs utilized          ", avg / avg_stats(&walltime_nsecs_stats));
}

static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __used, double avg)
{
	double total, ratio = 0.0;
	const char *color;

	total = avg_stats(&runtime_cycles_stats[cpu]);

	if (total)
		ratio = avg / total * 100.0;

	color = PERF_COLOR_NORMAL;
	if (ratio > 50.0)
		color = PERF_COLOR_RED;
	else if (ratio > 30.0)
		color = PERF_COLOR_MAGENTA;
	else if (ratio > 10.0)
		color = PERF_COLOR_YELLOW;

	fprintf(stderr, " #  ");
	color_fprintf(stderr, color, "%6.2f%%", ratio);
	fprintf(stderr, " frontend cycles idle   ");
}

static void print_stalled_cycles_backend(int cpu, struct perf_evsel *evsel __used, double avg)
{
	double total, ratio = 0.0;
	const char *color;

	total = avg_stats(&runtime_cycles_stats[cpu]);

	if (total)
		ratio = avg / total * 100.0;

	color = PERF_COLOR_NORMAL;
	if (ratio > 75.0)
		color = PERF_COLOR_RED;
	else if (ratio > 50.0)
		color = PERF_COLOR_MAGENTA;
	else if (ratio > 20.0)
		color = PERF_COLOR_YELLOW;

	fprintf(stderr, " #  ");
	color_fprintf(stderr, color, "%6.2f%%", ratio);
	fprintf(stderr, " backend  cycles idle   ");
}

static void print_branch_misses(int cpu, struct perf_evsel *evsel __used, double avg)
{
	double total, ratio = 0.0;
	const char *color;

	total = avg_stats(&runtime_branches_stats[cpu]);

	if (total)
		ratio = avg / total * 100.0;

	color = PERF_COLOR_NORMAL;
	if (ratio > 20.0)
		color = PERF_COLOR_RED;
	else if (ratio > 10.0)
		color = PERF_COLOR_MAGENTA;
	else if (ratio > 5.0)
		color = PERF_COLOR_YELLOW;

	fprintf(stderr, " #  ");
	color_fprintf(stderr, color, "%6.2f%%", ratio);
	fprintf(stderr, " of all branches        ");
}

static void print_l1_dcache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
{
	double total, ratio = 0.0;
	const char *color;

	total = avg_stats(&runtime_l1_dcache_stats[cpu]);

	if (total)
		ratio = avg / total * 100.0;

	color = PERF_COLOR_NORMAL;
	if (ratio > 20.0)
		color = PERF_COLOR_RED;
	else if (ratio > 10.0)
		color = PERF_COLOR_MAGENTA;
	else if (ratio > 5.0)
		color = PERF_COLOR_YELLOW;

	fprintf(stderr, " #  ");
	color_fprintf(stderr, color, "%6.2f%%", ratio);
	fprintf(stderr, " of all L1-dcache hits  ");
}

static void abs_printout(int cpu, struct perf_evsel *evsel, double avg)
@@ -442,23 +609,55 @@ static void abs_printout(int cpu, struct perf_evsel *evsel, double avg)
		if (total)
			ratio = avg / total;

		fprintf(stderr, " # %10.3f IPC  ", ratio);
		fprintf(stderr, " #   %5.2f  insns per cycle        ", ratio);

		total = avg_stats(&runtime_stalled_cycles_front_stats[cpu]);
		total = max(total, avg_stats(&runtime_stalled_cycles_back_stats[cpu]));

		if (total && avg) {
			ratio = total / avg;
			fprintf(stderr, "\n                                            #   %5.2f  stalled cycles per insn", ratio);
		}

	} else if (perf_evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES) &&
			runtime_branches_stats[cpu].n != 0) {
		total = avg_stats(&runtime_branches_stats[cpu]);
		print_branch_misses(cpu, evsel, avg);
	} else if (
		evsel->attr.type == PERF_TYPE_HW_CACHE &&
		evsel->attr.config ==  ( PERF_COUNT_HW_CACHE_L1D |
					((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
					((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
			runtime_l1_dcache_stats[cpu].n != 0) {
		print_l1_dcache_misses(cpu, evsel, avg);
	} else if (perf_evsel__match(evsel, HARDWARE, HW_CACHE_MISSES) &&
			runtime_cacherefs_stats[cpu].n != 0) {
		total = avg_stats(&runtime_cacherefs_stats[cpu]);

		if (total)
			ratio = avg * 100 / total;

		fprintf(stderr, " # %10.3f %%    ", ratio);
		fprintf(stderr, " # %8.3f %% of all cache refs    ", ratio);

	} else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_FRONTEND)) {
		print_stalled_cycles_frontend(cpu, evsel, avg);
	} else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_BACKEND)) {
		print_stalled_cycles_backend(cpu, evsel, avg);
	} else if (perf_evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) {
		total = avg_stats(&runtime_nsecs_stats[cpu]);

		if (total)
			ratio = 1.0 * avg / total;

		fprintf(stderr, " # %8.3f GHz                    ", ratio);
	} else if (runtime_nsecs_stats[cpu].n != 0) {
		total = avg_stats(&runtime_nsecs_stats[cpu]);

		if (total)
			ratio = 1000.0 * avg / total;

		fprintf(stderr, " # %10.3f M/sec", ratio);
		fprintf(stderr, " # %8.3f M/sec                  ", ratio);
	} else {
		fprintf(stderr, "                                   ");
	}
}

@@ -505,8 +704,7 @@ static void print_counter_aggr(struct perf_evsel *counter)
		avg_enabled = avg_stats(&ps->res_stats[1]);
		avg_running = avg_stats(&ps->res_stats[2]);

		fprintf(stderr, "  (scaled from %.2f%%)",
				100 * avg_running / avg_enabled);
		fprintf(stderr, "  (%.2f%%)", 100 * avg_running / avg_enabled);
	}
	fprintf(stderr, "\n");
}
@@ -548,10 +746,8 @@ static void print_counter(struct perf_evsel *counter)
		if (!csv_output) {
			print_noise(counter, 1.0);

			if (run != ena) {
				fprintf(stderr, "  (scaled from %.2f%%)",
					100.0 * run / ena);
			}
			if (run != ena)
				fprintf(stderr, "  (%.2f%%)", 100.0 * run / ena);
		}
		fputc('\n', stderr);
	}
@@ -595,8 +791,7 @@ static void print_stat(int argc, const char **argv)
		fprintf(stderr, " %18.9f  seconds time elapsed",
				avg_stats(&walltime_nsecs_stats)/1e9);
		if (run_count > 1) {
			fprintf(stderr, "   ( +- %7.3f%% )",
				100*stddev_stats(&walltime_nsecs_stats) /
			print_noise_pct(stddev_stats(&walltime_nsecs_stats),
					avg_stats(&walltime_nsecs_stats));
		}
		fprintf(stderr, "\n\n");
@@ -659,6 +854,10 @@ static const struct option options[] = {
		    "repeat command and print average + stddev (max: 100)"),
	OPT_BOOLEAN('n', "null", &null_run,
		    "null run - dont start any counters"),
	OPT_BOOLEAN('d', "detailed", &detailed_run,
		    "detailed run - start a lot of events"),
	OPT_BOOLEAN('S', "sync", &sync_run,
		    "call sync() before starting a run"),
	OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL, 
			   "print large numbers with thousands\' separators",
			   stat__set_big_num),
@@ -720,7 +919,18 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
	}

	/* Set attrs and nr_counters if no event is selected and !null_run */
	if (!null_run && !evsel_list->nr_entries) {
	if (detailed_run) {
		size_t c;

		for (c = 0; c < ARRAY_SIZE(detailed_attrs); ++c) {
			pos = perf_evsel__new(&detailed_attrs[c], c);
			if (pos == NULL)
				goto out;
			perf_evlist__add(evsel_list, pos);
		}
	}
	/* Set attrs and nr_counters if no event is selected and !null_run */
	if (!detailed_run && !null_run && !evsel_list->nr_entries) {
		size_t c;

		for (c = 0; c < ARRAY_SIZE(default_attrs); ++c) {
@@ -773,6 +983,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
	for (run_idx = 0; run_idx < run_count; run_idx++) {
		if (run_count != 1 && verbose)
			fprintf(stderr, "[ perf stat: executing run #%d ... ]\n", run_idx + 1);

		if (sync_run)
			sync();

		status = run_perf_stat(argc, argv);
	}

+69 −51
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ char debugfs_path[MAXPATHLEN];

static struct event_symbol event_symbols[] = {
  { CHW(CPU_CYCLES),			"cpu-cycles",			"cycles"		},
  { CHW(STALLED_CYCLES_FRONTEND),	"stalled-cycles-frontend",	"idle-cycles-frontend"	},
  { CHW(STALLED_CYCLES_BACKEND),	"stalled-cycles-backend",	"idle-cycles-backend"	},
  { CHW(INSTRUCTIONS),			"instructions",			""			},
  { CHW(CACHE_REFERENCES),		"cache-references",		""			},
  { CHW(CACHE_MISSES),			"cache-misses",			""			},
@@ -58,7 +60,7 @@ static struct event_symbol event_symbols[] = {
#define PERF_EVENT_TYPE(config)		__PERF_EVENT_FIELD(config, TYPE)
#define PERF_EVENT_ID(config)		__PERF_EVENT_FIELD(config, EVENT)

static const char *hw_event_names[] = {
static const char *hw_event_names[PERF_COUNT_HW_MAX] = {
	"cycles",
	"instructions",
	"cache-references",
@@ -66,11 +68,13 @@ static const char *hw_event_names[] = {
	"branches",
	"branch-misses",
	"bus-cycles",
	"stalled-cycles-frontend",
	"stalled-cycles-backend",
};

static const char *sw_event_names[] = {
	"cpu-clock-msecs",
	"task-clock-msecs",
static const char *sw_event_names[PERF_COUNT_SW_MAX] = {
	"cpu-clock",
	"task-clock",
	"page-faults",
	"context-switches",
	"CPU-migrations",
@@ -307,7 +311,7 @@ const char *__event_name(int type, u64 config)

	switch (type) {
	case PERF_TYPE_HARDWARE:
		if (config < PERF_COUNT_HW_MAX)
		if (config < PERF_COUNT_HW_MAX && hw_event_names[config])
			return hw_event_names[config];
		return "unknown-hardware";

@@ -333,7 +337,7 @@ const char *__event_name(int type, u64 config)
	}

	case PERF_TYPE_SOFTWARE:
		if (config < PERF_COUNT_SW_MAX)
		if (config < PERF_COUNT_SW_MAX && sw_event_names[config])
			return sw_event_names[config];
		return "unknown-software";

@@ -648,13 +652,15 @@ static int check_events(const char *str, unsigned int i)
	int n;

	n = strlen(event_symbols[i].symbol);
	if (!strncmp(str, event_symbols[i].symbol, n))
	if (!strncasecmp(str, event_symbols[i].symbol, n))
		return n;

	n = strlen(event_symbols[i].alias);
	if (n)
		if (!strncmp(str, event_symbols[i].alias, n))
	if (n) {
		if (!strncasecmp(str, event_symbols[i].alias, n))
			return n;
	}

	return 0;
}

@@ -718,15 +724,19 @@ parse_numeric_event(const char **strp, struct perf_event_attr *attr)
	return EVT_FAILED;
}

static enum event_result
static int
parse_event_modifier(const char **strp, struct perf_event_attr *attr)
{
	const char *str = *strp;
	int exclude = 0;
	int eu = 0, ek = 0, eh = 0, precise = 0;

	if (*str++ != ':')
	if (!*str)
		return 0;

	if (*str++ != ':')
		return -1;

	while (*str) {
		if (*str == 'u') {
			if (!exclude)
@@ -747,14 +757,16 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr)

		++str;
	}
	if (str >= *strp + 2) {
	if (str < *strp + 2)
		return -1;

	*strp = str;

	attr->exclude_user   = eu;
	attr->exclude_kernel = ek;
	attr->exclude_hv     = eh;
	attr->precise_ip     = precise;
		return 1;
	}

	return 0;
}

@@ -797,7 +809,12 @@ parse_event_symbols(const struct option *opt, const char **str,
	return EVT_FAILED;

modifier:
	parse_event_modifier(str, attr);
	if (parse_event_modifier(str, attr) < 0) {
		fprintf(stderr, "invalid event modifier: '%s'\n", *str);
		fprintf(stderr, "Run 'perf list' for a list of valid events and modifiers\n");

		return EVT_FAILED;
	}

	return ret;
}
@@ -912,7 +929,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob)

			snprintf(evt_path, MAXPATHLEN, "%s:%s",
				 sys_dirent.d_name, evt_dirent.d_name);
			printf("  %-42s [%s]\n", evt_path,
			printf("  %-50s [%s]\n", evt_path,
				event_type_descriptors[PERF_TYPE_TRACEPOINT]);
		}
		closedir(evt_dir);
@@ -977,7 +994,7 @@ void print_events_type(u8 type)
		else
			snprintf(name, sizeof(name), "%s", syms->symbol);

		printf("  %-42s [%s]\n", name,
		printf("  %-50s [%s]\n", name,
			event_type_descriptors[type]);
	}
}
@@ -995,11 +1012,10 @@ int print_hwcache_events(const char *event_glob)
			for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
				char *name = event_cache_name(type, op, i);

				if (event_glob != NULL && 
				    !strglobmatch(name, event_glob))
				if (event_glob != NULL && !strglobmatch(name, event_glob))
					continue;

				printf("  %-42s [%s]\n", name,
				printf("  %-50s [%s]\n", name,
					event_type_descriptors[PERF_TYPE_HW_CACHE]);
				++printed;
			}
@@ -1009,14 +1025,16 @@ int print_hwcache_events(const char *event_glob)
	return printed;
}

#define MAX_NAME_LEN 100

/*
 * Print the help text for the event symbols:
 */
void print_events(const char *event_glob)
{
	struct event_symbol *syms = event_symbols;
	unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0;
	char name[40];
	struct event_symbol *syms = event_symbols;
	char name[MAX_NAME_LEN];

	printf("\n");
	printf("List of pre-defined events (to be used in -e):\n");
@@ -1036,10 +1054,10 @@ void print_events(const char *event_glob)
			continue;

		if (strlen(syms->alias))
			sprintf(name, "%s OR %s", syms->symbol, syms->alias);
			snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
		else
			strcpy(name, syms->symbol);
		printf("  %-42s [%s]\n", name,
			strncpy(name, syms->symbol, MAX_NAME_LEN);
		printf("  %-50s [%s]\n", name,
			event_type_descriptors[type]);

		prev_type = type;
@@ -1056,12 +1074,12 @@ void print_events(const char *event_glob)
		return;

	printf("\n");
	printf("  %-42s [%s]\n",
	printf("  %-50s [%s]\n",
		"rNNN (see 'perf list --help' on how to encode it)",
	       event_type_descriptors[PERF_TYPE_RAW]);
	printf("\n");

	printf("  %-42s [%s]\n",
	printf("  %-50s [%s]\n",
			"mem:<addr>[:access]",
			event_type_descriptors[PERF_TYPE_BREAKPOINT]);
	printf("\n");
Loading