Skip to contentSkip to conversation

perf_counter: parse-events.c define separate declarations for H/W and S/W events

PATCH In review Jaswinder Singh Rajput 2 participants 14 messages Jun 22, 2009 – Jun 24, 2009 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 perf_counter: parse-events.c define separate declarations for H/W and S/W events

Define separate declarations for H/W and S/W events to :
1. shorten name to save some space so that we can add more members
2. Fix alignment
3. Avoid declaring HARDWARE/SOFTWARE again and again.

Removed unused CR(x, y)

---
 tools/perf/util/parse-events.c |   42 ++++++++++++++++++++--------------------
 1 files changed, 21 insertions(+), 21 deletions(-)
tools/perf/util/parse-events.c +22 -22
index 35d04da..12abab3 100644
@@ -18,30 +18,30 @@ struct event_symbol {
 	char	*symbol;
 };
 
-#define C(x, y) .type = PERF_TYPE_##x, .config = PERF_COUNT_##y
-#define CR(x, y) .type = PERF_TYPE_##x, .config = y
+#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
+#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
 
 static struct event_symbol event_symbols[] = {
-  { C(HARDWARE, HW_CPU_CYCLES),		"cpu-cycles",		},
-  { C(HARDWARE, HW_CPU_CYCLES),		"cycles",		},
-  { C(HARDWARE, HW_INSTRUCTIONS),	"instructions",		},
-  { C(HARDWARE, HW_CACHE_REFERENCES),	"cache-references",	},
-  { C(HARDWARE, HW_CACHE_MISSES),	"cache-misses",		},
-  { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branch-instructions",	},
-  { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branches",		},
-  { C(HARDWARE, HW_BRANCH_MISSES),	"branch-misses",	},
-  { C(HARDWARE, HW_BUS_CYCLES),		"bus-cycles",		},
-
-  { C(SOFTWARE, SW_CPU_CLOCK),		"cpu-clock",		},
-  { C(SOFTWARE, SW_TASK_CLOCK),		"task-clock",		},
-  { C(SOFTWARE, SW_PAGE_FAULTS),	"page-faults",		},
-  { C(SOFTWARE, SW_PAGE_FAULTS),	"faults",		},
-  { C(SOFTWARE, SW_PAGE_FAULTS_MIN),	"minor-faults",		},
-  { C(SOFTWARE, SW_PAGE_FAULTS_MAJ),	"major-faults",		},
-  { C(SOFTWARE, SW_CONTEXT_SWITCHES),	"context-switches",	},
-  { C(SOFTWARE, SW_CONTEXT_SWITCHES),	"cs",			},
-  { C(SOFTWARE, SW_CPU_MIGRATIONS),	"cpu-migrations",	},
-  { C(SOFTWARE, SW_CPU_MIGRATIONS),	"migrations",		},
+  { CHW(CPU_CYCLES),		"cpu-cycles",		},
+  { CHW(CPU_CYCLES),		"cycles",		},
+  { CHW(INSTRUCTIONS),		"instructions",		},
+  { CHW(CACHE_REFERENCES),	"cache-references",	},
+  { CHW(CACHE_MISSES),		"cache-misses",		},
+  { CHW(BRANCH_INSTRUCTIONS),	"branch-instructions",	},
+  { CHW(BRANCH_INSTRUCTIONS),	"branches",		},
+  { CHW(BRANCH_MISSES),		"branch-misses",	},
+  { CHW(BUS_CYCLES),		"bus-cycles",		},
+
+  { CSW(CPU_CLOCK),		"cpu-clock",		},
+  { CSW(TASK_CLOCK),		"task-clock",		},
+  { CSW(PAGE_FAULTS),		"page-faults",		},
+  { CSW(PAGE_FAULTS),		"faults",		},
+  { CSW(PAGE_FAULTS_MIN),	"minor-faults",		},
+  { CSW(PAGE_FAULTS_MAJ),	"major-faults",		},
+  { CSW(CONTEXT_SWITCHES),	"context-switches",	},
+  { CSW(CONTEXT_SWITCHES),	"cs",			},
+  { CSW(CPU_MIGRATIONS),	"cpu-migrations",	},
+  { CSW(CPU_MIGRATIONS),	"migrations",		},
 };
 
 #define __PERF_COUNTER_FIELD(config, name) \
Signature · 1 line
1.6.0.6
#1 lore raw

PATCH 2/2 perf_counter: parse-events.c introduce alias member in event_symbol

By introducing alias member in event_symbol :

1. duplicate lines are removed, like:
cpu-cycles and cycles
branch-instructions and branches
context-switches and cs
cpu-migrations and migrations

2. We can also add alias for another events.

Now ./perf list looks like :

List of pre-defined events (to be used in -e):

  cpu-cycles OR cycles                     [Hardware event]
  instructions                             [Hardware event]
  cache-references                         [Hardware event]
  cache-misses                             [Hardware event]
  branch-instructions OR branches          [Hardware event]
  branch-misses                            [Hardware event]
  bus-cycles                               [Hardware event]
  cpu-clock                                [Software event]
  task-clock                               [Software event]
  page-faults                              [Software event]
  faults                                   [Software event]
  minor-faults                             [Software event]
  major-faults                             [Software event]
  context-switches OR cs                   [Software event]
  cpu-migrations OR migrations             [Software event]

rNNN [raw hardware event descriptor]

---
 tools/perf/util/parse-events.c |   63 ++++++++++++++++++++++++----------------
 1 files changed, 38 insertions(+), 25 deletions(-)
tools/perf/util/parse-events.c +38 -25
index 12abab3..f569548 100644
@@ -16,32 +16,29 @@ struct event_symbol {
 	u8	type;
 	u64	config;
 	char	*symbol;
+	char	*alias;
 };
 
 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
 
 static struct event_symbol event_symbols[] = {
-  { CHW(CPU_CYCLES),		"cpu-cycles",		},
-  { CHW(CPU_CYCLES),		"cycles",		},
-  { CHW(INSTRUCTIONS),		"instructions",		},
-  { CHW(CACHE_REFERENCES),	"cache-references",	},
-  { CHW(CACHE_MISSES),		"cache-misses",		},
-  { CHW(BRANCH_INSTRUCTIONS),	"branch-instructions",	},
-  { CHW(BRANCH_INSTRUCTIONS),	"branches",		},
-  { CHW(BRANCH_MISSES),		"branch-misses",	},
-  { CHW(BUS_CYCLES),		"bus-cycles",		},
-
-  { CSW(CPU_CLOCK),		"cpu-clock",		},
-  { CSW(TASK_CLOCK),		"task-clock",		},
-  { CSW(PAGE_FAULTS),		"page-faults",		},
-  { CSW(PAGE_FAULTS),		"faults",		},
-  { CSW(PAGE_FAULTS_MIN),	"minor-faults",		},
-  { CSW(PAGE_FAULTS_MAJ),	"major-faults",		},
-  { CSW(CONTEXT_SWITCHES),	"context-switches",	},
-  { CSW(CONTEXT_SWITCHES),	"cs",			},
-  { CSW(CPU_MIGRATIONS),	"cpu-migrations",	},
-  { CSW(CPU_MIGRATIONS),	"migrations",		},
+  { CHW(CPU_CYCLES),		"cpu-cycles",		"cycles"	},
+  { CHW(INSTRUCTIONS),		"instructions",		""		},
+  { CHW(CACHE_REFERENCES),	"cache-references",	""		},
+  { CHW(CACHE_MISSES),		"cache-misses",		""		},
+  { CHW(BRANCH_INSTRUCTIONS),	"branch-instructions",	"branches"	},
+  { CHW(BRANCH_MISSES),		"branch-misses",	""		},
+  { CHW(BUS_CYCLES),		"bus-cycles",		""		},
+
+  { CSW(CPU_CLOCK),		"cpu-clock",		""		},
+  { CSW(TASK_CLOCK),		"task-clock",		""		},
+  { CSW(PAGE_FAULTS),		"page-faults",		""		},
+  { CSW(PAGE_FAULTS),		"faults",		""		},
+  { CSW(PAGE_FAULTS_MIN),	"minor-faults",		""		},
+  { CSW(PAGE_FAULTS_MAJ),	"major-faults",		""		},
+  { CSW(CONTEXT_SWITCHES),	"context-switches",	"cs"		},
+  { CSW(CPU_MIGRATIONS),	"cpu-migrations",	"migrations"	},
 };
 
 #define __PERF_COUNTER_FIELD(config, name) \
@@ -196,6 +193,19 @@ static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *a
 	return 0;
 }
 
+static int check_events(const char *str, unsigned int i)
+{
+	if (!strncmp(str, event_symbols[i].symbol,
+		     strlen(event_symbols[i].symbol)))
+		return 1;
+
+	if (strlen(event_symbols[i].alias))
+		if (!strncmp(str, event_symbols[i].alias,
+		      strlen(event_symbols[i].alias)))
+			return 1;
+	return 0;
+}
+
 /*
  * Each event can have multiple symbolic names.
  * Symbolic names are (almost) exactly matched.
@@ -235,9 +245,7 @@ static int parse_event_symbols(const char *str, struct perf_counter_attr *attr)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
-		if (!strncmp(str, event_symbols[i].symbol,
-			     strlen(event_symbols[i].symbol))) {
-
+		if (check_events(str, i)) {
 			attr->type = event_symbols[i].type;
 			attr->config = event_symbols[i].config;
 
@@ -289,6 +297,7 @@ void print_events(void)
 {
 	struct event_symbol *syms = event_symbols;
 	unsigned int i, type, prev_type = -1;
+	char name[40];
 
 	fprintf(stderr, "\n");
 	fprintf(stderr, "List of pre-defined events (to be used in -e):\n");
@@ -301,14 +310,18 @@ void print_events(void)
 		if (type != prev_type)
 			fprintf(stderr, "\n");
 
-		fprintf(stderr, "  %-30s [%s]\n", syms->symbol,
+		if (strlen(syms->alias))
+			sprintf(name, "%s OR %s", syms->symbol, syms->alias);
+		else
+			strcpy(name, syms->symbol);
+		fprintf(stderr, "  %-40s [%s]\n", name,
 			event_type_descriptors[type]);
 
 		prev_type = type;
 	}
 
 	fprintf(stderr, "\n");
-	fprintf(stderr, "  %-30s [raw hardware event descriptor]\n",
+	fprintf(stderr, "  %-40s [raw hardware event descriptor]\n",
 		"rNNN");
 	fprintf(stderr, "\n");
 
Signature · 1 line
1.6.0.6
#2 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

Quoted 32 lines · Jaswinder Singh Rajput

By introducing alias member in event_symbol :

1. duplicate lines are removed, like:
cpu-cycles and cycles
branch-instructions and branches
context-switches and cs
cpu-migrations and migrations

2. We can also add alias for another events.

Now ./perf list looks like :

List of pre-defined events (to be used in -e):

  cpu-cycles OR cycles                     [Hardware event]
  instructions                             [Hardware event]
  cache-references                         [Hardware event]
  cache-misses                             [Hardware event]
  branch-instructions OR branches          [Hardware event]
  branch-misses                            [Hardware event]
  bus-cycles                               [Hardware event]
  cpu-clock                                [Software event]
  task-clock                               [Software event]
  page-faults                              [Software event]
  faults                                   [Software event]
  minor-faults                             [Software event]
  major-faults                             [Software event]
  context-switches OR cs                   [Software event]
  cpu-migrations OR migrations             [Software event]
Quoted 6 lines

rNNN [raw hardware event descriptor]

---
 tools/perf/util/parse-events.c |   63 ++++++++++++++++++++++++----------------
 1 files changed, 38 insertions(+), 25 deletions(-)

That looks useful - applied, thanks!

Another nice thing would be for 'perf list' to actually start each counter and stop it - and see whether it ticks. Perhaps that could be a new sub-command: 'perf test' ?

New 'perf' subcommands are added easily:

create a new tools/perf/builtin-foo.c file, add it to command-list.txt and to the Makefile - add it to perf.c's array of built-in commands and add a Documentation/perf-foo.txt file to generate manpages and usage strings for it.

Ingo

#3 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

Quoted 11 lines · Ingo Molnar

Another nice thing would be for 'perf list' to actually start each counter and stop it - and see whether it ticks. Perhaps that could be a new sub-command: 'perf test' ?

New 'perf' subcommands are added easily:

create a new tools/perf/builtin-foo.c file, add it to command-list.txt and to the Makefile - add it to perf.c's array of built-in commands and add a Documentation/perf-foo.txt file to generate manpages and usage strings for it.

Ok this is just a ugly quick hack to get the idea what actually you are looking for :

[RFC] perf_counter tools: introduce perf test to test each event for ticks

perf test to Test all events for whether it ticks

  $ perf test

Performance counter stats for 'test':

  task-clock-msecs      Tick
  context-switches      Tick
  CPU-migrations        Tick
  page-faults           Tick
  cycles                Tick
  instructions          Tick
  cache-references      Tick
  cache-misses          Tick
     0.007693869  seconds time elapsed.
---
 tools/perf/Documentation/perf-test.txt |   24 ++
 tools/perf/Makefile                    |    1 +
 tools/perf/builtin-test.c              |  399 ++++++++++++++++++++++++++++++++
 tools/perf/builtin.h                   |    1 +
 tools/perf/command-list.txt            |    1 +
 tools/perf/perf.c                      |    1 +
 6 files changed, 427 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-test.txt
 create mode 100644 tools/perf/builtin-test.c
tools/perf/Documentation/perf-test.txt new file +24 -0
new file mode 100644
index 0000000..44cf495
@@ -0,0 +1,24 @@
+perf-test(1)
+============
+
+NAME
+----
+perf-test - Test all events for whether it ticks
+
+SYNOPSIS
+--------
+[verse]
+'perf test'
+
+DESCRIPTION
+-----------
+This command test all events whether it ticks.
+
+OPTIONS
+-------
+None
+
+SEE ALSO
+--------
+linkperf:perf-stat[1], linkperf:perf-top[1],
+linkperf:perf-record[1]
tools/perf/Makefile +1 -0
index 36d7eef..f5ac83f 100644
@@ -335,6 +335,7 @@ BUILTIN_OBJS += builtin-list.o
 BUILTIN_OBJS += builtin-record.o
 BUILTIN_OBJS += builtin-report.o
 BUILTIN_OBJS += builtin-stat.o
+BUILTIN_OBJS += builtin-test.o
 BUILTIN_OBJS += builtin-top.o
 
 PERFLIBS = $(LIB_FILE)
tools/perf/builtin-test.c new file +399 -0

399 lines not on this page · raw message

tools/perf/builtin.h +1 -0
index 51d1682..3ed0362 100644
@@ -22,5 +22,6 @@ extern int cmd_stat(int argc, const char **argv, const char *prefix);
 extern int cmd_top(int argc, const char **argv, const char *prefix);
 extern int cmd_version(int argc, const char **argv, const char *prefix);
 extern int cmd_list(int argc, const char **argv, const char *prefix);
+extern int cmd_test(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/command-list.txt +1 -0
index eebce30..f53544c 100644
@@ -7,4 +7,5 @@ perf-list			mainporcelain common
 perf-record			mainporcelain common
 perf-report			mainporcelain common
 perf-stat			mainporcelain common
+perf-test			mainporcelain common
 perf-top			mainporcelain common
tools/perf/perf.c +1 -0
index 4eb7259..9f98f5e 100644
@@ -262,6 +262,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "record", cmd_record, 0 },
 		{ "report", cmd_report, 0 },
 		{ "stat", cmd_stat, 0 },
+		{ "test", cmd_test, 0 },
 		{ "top", cmd_top, 0 },
 		{ "annotate", cmd_annotate, 0 },
 		{ "version", cmd_version, 0 },
Signature · 1 line
1.6.0.6
#4 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

Quoted 34 lines · Jaswinder Singh Rajput
Quoted 11 lines · Ingo Molnar

Another nice thing would be for 'perf list' to actually start each counter and stop it - and see whether it ticks. Perhaps that could be a new sub-command: 'perf test' ?

New 'perf' subcommands are added easily:

create a new tools/perf/builtin-foo.c file, add it to command-list.txt and to the Makefile - add it to perf.c's array of built-in commands and add a Documentation/perf-foo.txt file to generate manpages and usage strings for it.

Ok this is just a ugly quick hack to get the idea what actually you are looking for :

[RFC] perf_counter tools: introduce perf test to test each event for ticks

perf test to Test all events for whether it ticks

  $ perf test

Performance counter stats for 'test':

  task-clock-msecs      Tick
  context-switches      Tick
  CPU-migrations        Tick
  page-faults           Tick
  cycles                Tick
  instructions          Tick
  cache-references      Tick
  cache-misses          Tick
Quoted 1 line
     0.007693869  seconds time elapsed.

Please let me know should I need to test all events (Hardware + Software) and/or selective event based on user request. And what should be output looks like.

Thanks,
--
JSR

#5 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

In reply to Jaswinder Singh Rajput
Quoted 34 lines · Jaswinder Singh Rajput
Quoted 11 lines · Ingo Molnar

Another nice thing would be for 'perf list' to actually start each counter and stop it - and see whether it ticks. Perhaps that could be a new sub-command: 'perf test' ?

New 'perf' subcommands are added easily:

create a new tools/perf/builtin-foo.c file, add it to command-list.txt and to the Makefile - add it to perf.c's array of built-in commands and add a Documentation/perf-foo.txt file to generate manpages and usage strings for it.

Ok this is just a ugly quick hack to get the idea what actually you are looking for :

[RFC] perf_counter tools: introduce perf test to test each event for ticks

perf test to Test all events for whether it ticks

  $ perf test

Performance counter stats for 'test':

  task-clock-msecs      Tick
  context-switches      Tick
  CPU-migrations        Tick
  page-faults           Tick
  cycles                Tick
  instructions          Tick
  cache-references      Tick
  cache-misses          Tick
Quoted 1 line
     0.007693869  seconds time elapsed.

yeah, somethig like that. I'd suggest to print out the actual measured events:

cache-references 10123 events
cache-misses 15 events

and if something does not appear to be ticking then do something like:

cache-misses <inactive>

I.e. 'perf test' could be a quick way both to users and to developers to see all possible hw and sw events.

Perhaps builtin-test.c should also do specific testcases for certain counters - say intentionally migrate to a CPU and back to see the CPU-migration count.

Also, you seem to have copied builtin-stat.c, right? Try to librarize as much of the functionality (into util/*) to make the resulting linecount increase as small as possible.

Ingo

#6 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

Quoted 14 lines · Ingo Molnar

yeah, somethig like that. I'd suggest to print out the actual measured events:

cache-references 10123 events
cache-misses 15 events

and if something does not appear to be ticking then do something like:

cache-misses <inactive>

I.e. 'perf test' could be a quick way both to users and to developers to see all possible hw and sw events.

Quoted 8 lines

Perhaps builtin-test.c should also do specific testcases for certain counters - say intentionally migrate to a CPU and back to see the CPU-migration count.

Also, you seem to have copied builtin-stat.c, right? Try to librarize as much of the functionality (into util/*) to make the resulting linecount increase as small as possible.

perf test also need some command to execute otherwise it will also show long list of <inactive>

I think better I should support all events in perf stat so user can get better information from it and we can all add some other testing option to it.

Anyway currently it looks like this :

[RFC][PATCH] perf_counter tools: introduce perf test to test event for ticks

perf test to Test performance counter events, its output on AMD box :

./perf test -a -- ls -lR > /dev/null

Performance counter stats for 'ls' -lR:

cycles 1226819954
instructions 283680441
cache-references 144893559
cache-misses 3268438
branches 37488241
branch-misses 2464027
bus-cycles <inactive>
cpu-clock-msecs 17175506056
task-clock-msecs 17175086665
page-faults 488
minor-faults 488
major-faults <inactive>
context-switches 7956
CPU-migrations 7
L1-data-Cache-Load-Referencees 398303881
L1-data-Cache-Load-Misses 3552374
L1-data-Cache-Store-Referencees 270178
L1-data-Cache-Store-Misses <inactive>
L1-data-Cache-Prefetch-Referencees 611622
L1-data-Cache-Prefetch-Misses 399730
L1-instruction-Cache-Load-Referencees 124696447
L1-instruction-Cache-Load-Misses 2912802
L1-instruction-Cache-Store-Referencees <inactive>
L1-instruction-Cache-Store-Misses <inactive>
L1-instruction-Cache-Prefetch-Referencees 156576
L1-instruction-Cache-Prefetch-Misses <inactive>
L2-Cache-Load-Referencees 4312353
L2-Cache-Load-Misses 470382
L2-Cache-Store-Referencees 4392945

 L2-Cache-Store-Misses                              <inactive>
 L2-Cache-Prefetch-Referencees                      <inactive>
 L2-Cache-Prefetch-Misses                           <inactive>
 Data-TLB-Cache-Load-Referencees                     127076487
 Data-TLB-Cache-Load-Misses                            1930048
 Data-TLB-Cache-Store-Referencees                   <inactive>
 Data-TLB-Cache-Store-Misses                        <inactive>
 Data-TLB-Cache-Prefetch-Referencees                <inactive>
 Data-TLB-Cache-Prefetch-Misses                     <inactive>
 Instruction-TLB-Cache-Load-Referencees              132768077
 Instruction-TLB-Cache-Load-Misses                        6406
 Instruction-TLB-Cache-Store-Referencees            <inactive>
 Instruction-TLB-Cache-Store-Misses                 <inactive>
 Instruction-TLB-Cache-Prefetch-Referencees         <inactive>
 Instruction-TLB-Cache-Prefetch-Misses              <inactive>
 Branch-Cache-Load-Referencees                        58030210
 Branch-Cache-Load-Misses                              3257804
 Branch-Cache-Store-Referencees                     <inactive>
 Branch-Cache-Store-Misses                          <inactive>
 Branch-Cache-Prefetch-Referencees                  <inactive>
 Branch-Cache-Prefetch-Misses                       <inactive>
    8.681671511  seconds time elapsed.
---
 tools/perf/Documentation/perf-test.txt |   44 ++++
 tools/perf/Makefile                    |    1 +
 tools/perf/builtin-test.c              |  436 ++++++++++++++++++++++++++++++++
 tools/perf/builtin.h                   |    1 +
 tools/perf/command-list.txt            |    1 +
 tools/perf/perf.c                      |    1 +
 6 files changed, 484 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-test.txt
 create mode 100644 tools/perf/builtin-test.c
tools/perf/Documentation/perf-test.txt new file +44 -0
new file mode 100644
index 0000000..6233769
@@ -0,0 +1,44 @@
+perf-test(1)
+============
+
+NAME
+----
+perf-test - Run a command and gather performance counter event count if any
+
+SYNOPSIS
+--------
+[verse]
+'perf test' [-e <EVENT> | --event=EVENT] [-a] <command>
+'perf test' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>]
+
+DESCRIPTION
+-----------
+This command runs a command and gathers performance counter event count
+from it.
+
+
+OPTIONS
+-------
+<command>...::
+	Any command you can specify in a shell.
+
+
+-e::
+--event=::
+	Select the PMU event. Selection can be a symbolic event name
+	(use 'perf list' to list all events) or a raw PMU
+	event (eventsel+umask) in the form of rNNN where NNN is a
+	 hexadecimal event descriptor.
+
+-a::
+        system-wide collection
+
+EXAMPLES
+--------
+
+$ perf test -- make -j
+
+
+SEE ALSO
+--------
+linkperf:perf-stat[1], perf-top[1], linkperf:perf-list[1]
tools/perf/Makefile +1 -0
index 36d7eef..f5ac83f 100644
@@ -335,6 +335,7 @@ BUILTIN_OBJS += builtin-list.o
 BUILTIN_OBJS += builtin-record.o
 BUILTIN_OBJS += builtin-report.o
 BUILTIN_OBJS += builtin-stat.o
+BUILTIN_OBJS += builtin-test.o
 BUILTIN_OBJS += builtin-top.o
 
 PERFLIBS = $(LIB_FILE)
tools/perf/builtin-test.c new file +436 -0

436 lines not on this page · raw message

tools/perf/builtin.h +1 -0
index 51d1682..3ed0362 100644
@@ -22,5 +22,6 @@ extern int cmd_stat(int argc, const char **argv, const char *prefix);
 extern int cmd_top(int argc, const char **argv, const char *prefix);
 extern int cmd_version(int argc, const char **argv, const char *prefix);
 extern int cmd_list(int argc, const char **argv, const char *prefix);
+extern int cmd_test(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/command-list.txt +1 -0
index eebce30..f53544c 100644
@@ -7,4 +7,5 @@ perf-list			mainporcelain common
 perf-record			mainporcelain common
 perf-report			mainporcelain common
 perf-stat			mainporcelain common
+perf-test			mainporcelain common
 perf-top			mainporcelain common
tools/perf/perf.c +1 -0
index 4eb7259..9f98f5e 100644
@@ -262,6 +262,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "record", cmd_record, 0 },
 		{ "report", cmd_report, 0 },
 		{ "stat", cmd_stat, 0 },
+		{ "test", cmd_test, 0 },
 		{ "top", cmd_top, 0 },
 		{ "annotate", cmd_annotate, 0 },
 		{ "version", cmd_version, 0 },
Signature · 1 line
1.6.0.6
#7 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

Quoted 27 lines · Jaswinder Singh Rajput
Quoted 14 lines · Ingo Molnar

yeah, somethig like that. I'd suggest to print out the actual measured events:

cache-references 10123 events
cache-misses 15 events

and if something does not appear to be ticking then do something like:

cache-misses <inactive>

I.e. 'perf test' could be a quick way both to users and to developers to see all possible hw and sw events.

Quoted 8 lines

Perhaps builtin-test.c should also do specific testcases for certain counters - say intentionally migrate to a CPU and back to see the CPU-migration count.

Also, you seem to have copied builtin-stat.c, right? Try to librarize as much of the functionality (into util/*) to make the resulting linecount increase as small as possible.

perf test also need some command to execute otherwise it will also show long list of <inactive>

Quoted 7 lines

I think better I should support all events in perf stat so user can get better information from it and we can all add some other testing option to it.

Anyway currently it looks like this :

[RFC][PATCH] perf_counter tools: introduce perf test to test event for ticks

This fixes some style issues :

[RFC][PATCH] perf_counter tools: introduce perf test to test event for ticks

perf test to Test performance counter events, its output on AMD box :

./perf test -a -- ls -lR > /dev/null

Performance counter stats for 'ls' -lR:

cycles 1226819954
instructions 283680441
cache-references 144893559
cache-misses 3268438
branches 37488241
branch-misses 2464027
bus-cycles <inactive>
cpu-clock-msecs 17175506056
task-clock-msecs 17175086665
page-faults 488
minor-faults 488
major-faults <inactive>
context-switches 7956
CPU-migrations 7
L1-data-Cache-Load-Referencees 398303881
L1-data-Cache-Load-Misses 3552374
L1-data-Cache-Store-Referencees 270178
L1-data-Cache-Store-Misses <inactive>
L1-data-Cache-Prefetch-Referencees 611622
L1-data-Cache-Prefetch-Misses 399730
L1-instruction-Cache-Load-Referencees 124696447
L1-instruction-Cache-Load-Misses 2912802
L1-instruction-Cache-Store-Referencees <inactive>
L1-instruction-Cache-Store-Misses <inactive>
L1-instruction-Cache-Prefetch-Referencees 156576
L1-instruction-Cache-Prefetch-Misses <inactive>
L2-Cache-Load-Referencees 4312353
L2-Cache-Load-Misses 470382
L2-Cache-Store-Referencees 4392945

 L2-Cache-Store-Misses                              <inactive>
 L2-Cache-Prefetch-Referencees                      <inactive>
 L2-Cache-Prefetch-Misses                           <inactive>
 Data-TLB-Cache-Load-Referencees                     127076487
 Data-TLB-Cache-Load-Misses                            1930048
 Data-TLB-Cache-Store-Referencees                   <inactive>
 Data-TLB-Cache-Store-Misses                        <inactive>
 Data-TLB-Cache-Prefetch-Referencees                <inactive>
 Data-TLB-Cache-Prefetch-Misses                     <inactive>
 Instruction-TLB-Cache-Load-Referencees              132768077
 Instruction-TLB-Cache-Load-Misses                        6406
 Instruction-TLB-Cache-Store-Referencees            <inactive>
 Instruction-TLB-Cache-Store-Misses                 <inactive>
 Instruction-TLB-Cache-Prefetch-Referencees         <inactive>
 Instruction-TLB-Cache-Prefetch-Misses              <inactive>
 Branch-Cache-Load-Referencees                        58030210
 Branch-Cache-Load-Misses                              3257804
 Branch-Cache-Store-Referencees                     <inactive>
 Branch-Cache-Store-Misses                          <inactive>
 Branch-Cache-Prefetch-Referencees                  <inactive>
 Branch-Cache-Prefetch-Misses                       <inactive>
    8.681671511  seconds time elapsed.
---
 tools/perf/Documentation/perf-test.txt |   44 ++++
 tools/perf/Makefile                    |    1 +
 tools/perf/builtin-test.c              |  436 ++++++++++++++++++++++++++++++++
 tools/perf/builtin.h                   |    1 +
 tools/perf/command-list.txt            |    1 +
 tools/perf/perf.c                      |    1 +
 6 files changed, 484 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-test.txt
 create mode 100644 tools/perf/builtin-test.c
tools/perf/Documentation/perf-test.txt new file +44 -0
new file mode 100644
index 0000000..6233769
@@ -0,0 +1,44 @@
+perf-test(1)
+============
+
+NAME
+----
+perf-test - Run a command and gather performance counter event count if any
+
+SYNOPSIS
+--------
+[verse]
+'perf test' [-e <EVENT> | --event=EVENT] [-a] <command>
+'perf test' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>]
+
+DESCRIPTION
+-----------
+This command runs a command and gathers performance counter event count
+from it.
+
+
+OPTIONS
+-------
+<command>...::
+	Any command you can specify in a shell.
+
+
+-e::
+--event=::
+	Select the PMU event. Selection can be a symbolic event name
+	(use 'perf list' to list all events) or a raw PMU
+	event (eventsel+umask) in the form of rNNN where NNN is a
+	 hexadecimal event descriptor.
+
+-a::
+        system-wide collection
+
+EXAMPLES
+--------
+
+$ perf test -- make -j
+
+
+SEE ALSO
+--------
+linkperf:perf-stat[1], perf-top[1], linkperf:perf-list[1]
tools/perf/Makefile +1 -0
index 36d7eef..f5ac83f 100644
@@ -335,6 +335,7 @@ BUILTIN_OBJS += builtin-list.o
 BUILTIN_OBJS += builtin-record.o
 BUILTIN_OBJS += builtin-report.o
 BUILTIN_OBJS += builtin-stat.o
+BUILTIN_OBJS += builtin-test.o
 BUILTIN_OBJS += builtin-top.o
 
 PERFLIBS = $(LIB_FILE)
tools/perf/builtin-test.c new file +436 -0

436 lines not on this page · raw message

tools/perf/builtin.h +1 -0
index 51d1682..3ed0362 100644
@@ -22,5 +22,6 @@ extern int cmd_stat(int argc, const char **argv, const char *prefix);
 extern int cmd_top(int argc, const char **argv, const char *prefix);
 extern int cmd_version(int argc, const char **argv, const char *prefix);
 extern int cmd_list(int argc, const char **argv, const char *prefix);
+extern int cmd_test(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/command-list.txt +1 -0
index eebce30..f53544c 100644
@@ -7,4 +7,5 @@ perf-list			mainporcelain common
 perf-record			mainporcelain common
 perf-report			mainporcelain common
 perf-stat			mainporcelain common
+perf-test			mainporcelain common
 perf-top			mainporcelain common
tools/perf/perf.c +1 -0
index 4eb7259..9f98f5e 100644
@@ -262,6 +262,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "record", cmd_record, 0 },
 		{ "report", cmd_report, 0 },
 		{ "stat", cmd_stat, 0 },
+		{ "test", cmd_test, 0 },
 		{ "top", cmd_top, 0 },
 		{ "annotate", cmd_annotate, 0 },
 		{ "version", cmd_version, 0 },
Signature · 1 line
1.6.0.6
#8 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

Quoted 15 lines · Jaswinder Singh Rajput

L1-data-Cache-Load-Referencees 398303881
L1-data-Cache-Load-Misses 3552374
L1-data-Cache-Store-Referencees 270178
L1-data-Cache-Store-Misses <inactive>
L1-data-Cache-Prefetch-Referencees 611622
L1-data-Cache-Prefetch-Misses 399730
L1-instruction-Cache-Load-Referencees 124696447
L1-instruction-Cache-Load-Misses 2912802
L1-instruction-Cache-Store-Referencees <inactive>
L1-instruction-Cache-Store-Misses <inactive>
L1-instruction-Cache-Prefetch-Referencees 156576
L1-instruction-Cache-Prefetch-Misses <inactive>
L2-Cache-Load-Referencees 4312353
L2-Cache-Load-Misses 470382
L2-Cache-Store-Referencees 4392945

Quoted 14 lines
 L2-Cache-Store-Misses                              <inactive>
 L2-Cache-Prefetch-Referencees                      <inactive>
 L2-Cache-Prefetch-Misses                           <inactive>
 Data-TLB-Cache-Load-Referencees                     127076487
 Data-TLB-Cache-Load-Misses                            1930048
 Data-TLB-Cache-Store-Referencees                   <inactive>
 Data-TLB-Cache-Store-Misses                        <inactive>
 Data-TLB-Cache-Prefetch-Referencees                <inactive>
 Data-TLB-Cache-Prefetch-Misses                     <inactive>
 Instruction-TLB-Cache-Load-Referencees              132768077
 Instruction-TLB-Cache-Load-Misses                        6406
 Instruction-TLB-Cache-Store-Referencees            <inactive>
 Instruction-TLB-Cache-Store-Misses                 <inactive>
 Instruction-TLB-Cache-Prefetch-Referencees         <inactive>

there's a typo somewhere: it's References, not Referencees.

Quoted 7 lines

Instruction-TLB-Cache-Prefetch-Misses <inactive>
Branch-Cache-Load-Referencees 58030210
Branch-Cache-Load-Misses 3257804

 Branch-Cache-Store-Referencees                     <inactive>
 Branch-Cache-Store-Misses                          <inactive>
 Branch-Cache-Prefetch-Referencees                  <inactive>
 Branch-Cache-Prefetch-Misses                       <inactive>

btw., these names should be shortened somehow.

Instruction-TLB-Cache-Prefetch-Referencees could become:

iTLB-prefetch-refs

Data-TLB-Cache-Store-Referencees could become:

dTLB-store-refs

etc. (You might want to send us a list of abbreviations first, before coding it, to avoid unnecessary work - it will need a few iterations.)

The long versions should be recognized too, if someone prefers those (i.e. our alias detection should be extensive and permissive), but the names we _display_ should be short.

Ingo

#9 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

In reply to Jaswinder Singh Rajput
Quoted 19 lines · Jaswinder Singh Rajput
Quoted 18 lines · Ingo Molnar

yeah, somethig like that. I'd suggest to print out the actual measured events:

cache-references 10123 events
cache-misses 15 events

and if something does not appear to be ticking then do something like:

cache-misses <inactive>

I.e. 'perf test' could be a quick way both to users and to developers to see all possible hw and sw events.

Perhaps builtin-test.c should also do specific testcases for certain counters - say intentionally migrate to a CPU and back to see the CPU-migration count.

Quoted 6 lines
Quoted 3 lines

Also, you seem to have copied builtin-stat.c, right? Try to librarize as much of the functionality (into util/*) to make the resulting linecount increase as small as possible.

perf test also need some command to execute otherwise it will also show long list of <inactive>

I think what it should do is to execute test-cases _internally_. Not just execute some random command on the system and hope for events.

Quoted 3 lines

I think better I should support all events in perf stat so user can get better information from it and we can all add some other testing option to it.

I agree - see my previous mail about how to achieve this better: we should extend event string parsing with wildcards (regex) and with 'set of events' symbols that act as convenient specifiers for certain typical uses.

Quoted 10 lines

Anyway currently it looks like this :

[RFC][PATCH] perf_counter tools: introduce perf test to test event for ticks

perf test to Test performance counter events, its output on AMD box :

./perf test -a -- ls -lR > /dev/null

Performance counter stats for 'ls' -lR:

Quoted 12 lines

cycles 1226819954
instructions 283680441
cache-references 144893559
cache-misses 3268438
branches 37488241
branch-misses 2464027
bus-cycles <inactive>
cpu-clock-msecs 17175506056
task-clock-msecs 17175086665
page-faults 488
minor-faults 488
major-faults <inactive>

We should try to provoke a real major fault (i.e. a fault with IO) here. Not sure how though :-)

Quoted 2 lines

context-switches 7956
CPU-migrations 7

this needs to be provoked intentionally via sched_setaffinity():
first migrate to cpu0, then to cpu1.

Quoted 4 lines

L1-data-Cache-Load-Referencees 398303881
L1-data-Cache-Load-Misses 3552374
L1-data-Cache-Store-Referencees 270178
L1-data-Cache-Store-Misses <inactive>

this is probably inactive due to AMD not having events for that and the generic cache event being 0 there, right?

Quoted 33 lines

L1-data-Cache-Prefetch-Referencees 611622
L1-data-Cache-Prefetch-Misses 399730
L1-instruction-Cache-Load-Referencees 124696447
L1-instruction-Cache-Load-Misses 2912802
L1-instruction-Cache-Store-Referencees <inactive>
L1-instruction-Cache-Store-Misses <inactive>
L1-instruction-Cache-Prefetch-Referencees 156576
L1-instruction-Cache-Prefetch-Misses <inactive>
L2-Cache-Load-Referencees 4312353
L2-Cache-Load-Misses 470382
L2-Cache-Store-Referencees 4392945

 L2-Cache-Store-Misses                              <inactive>
 L2-Cache-Prefetch-Referencees                      <inactive>
 L2-Cache-Prefetch-Misses                           <inactive>
 Data-TLB-Cache-Load-Referencees                     127076487
 Data-TLB-Cache-Load-Misses                            1930048
 Data-TLB-Cache-Store-Referencees                   <inactive>
 Data-TLB-Cache-Store-Misses                        <inactive>
 Data-TLB-Cache-Prefetch-Referencees                <inactive>
 Data-TLB-Cache-Prefetch-Misses                     <inactive>
 Instruction-TLB-Cache-Load-Referencees              132768077
 Instruction-TLB-Cache-Load-Misses                        6406
 Instruction-TLB-Cache-Store-Referencees            <inactive>
 Instruction-TLB-Cache-Store-Misses                 <inactive>
 Instruction-TLB-Cache-Prefetch-Referencees         <inactive>
 Instruction-TLB-Cache-Prefetch-Misses              <inactive>
 Branch-Cache-Load-Referencees                        58030210
 Branch-Cache-Load-Misses                              3257804
 Branch-Cache-Store-Referencees                     <inactive>
 Branch-Cache-Store-Misses                          <inactive>
 Branch-Cache-Prefetch-Referencees                  <inactive>
 Branch-Cache-Prefetch-Misses                       <inactive>
Quoted 1 line
    8.681671511  seconds time elapsed.

looks nice.

Ingo

#10 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

Quoted 9 lines · Ingo Molnar
Quoted 3 lines · Jaswinder Singh Rajput

perf test also need some command to execute otherwise it will also show long list of <inactive>

I think what it should do is to execute test-cases _internally_. Not just execute some random command on the system and hope for events.

Can you suggest some good test cases where we can get numbers for almost all the events on each and every run.

Quoted 6 lines
Quoted 2 lines

context-switches 7956
CPU-migrations 7

this needs to be provoked intentionally via sched_setaffinity():
first migrate to cpu0, then to cpu1.

There should be some option from user or we test it each time.

Quoted 8 lines
Quoted 4 lines

L1-data-Cache-Load-Referencees 398303881
L1-data-Cache-Load-Misses 3552374
L1-data-Cache-Store-Referencees 270178
L1-data-Cache-Store-Misses <inactive>

this is probably inactive due to AMD not having events for that and the generic cache event being 0 there, right?

Yes, it is not set for AMD.

Thanks,
--
JSR

#11 lore raw

Re: [PATCH 2/2 -tip] perf_counter: parse-events.c introduce alias member in event_symbol

Quoted 4 lines · Jaswinder Singh Rajput
Quoted 3 lines · Ingo Molnar
Quoted 1 line · Jaswinder Singh Rajput
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

perf test also need some command to execute otherwise it will also show long list of <inactive>

I think what it should do is to execute test-cases _internally_. Not just execute some random command on the system and hope for events.

Can you suggest some good test cases where we can get numbers for almost all the events on each and every run.

the testcases should be specific to the counter type. Some counters are easy (such as cycles or instructions - you in fact cannot even get zero out of them even if you tried) - some are harder - such as migrations, or cache-misses or page-faults.

Small functions that trigger them for sure would do the trick. For example, to provoke a minor page fault:

static void trigger_minor_page_fault(void)

{
	void *page;

	page = mmap(0, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, -1, 0);

	/* Clearing the page will trigger a minor fault: */
	memset(page, 0, PAGE_SIZE);

	munmap(page, PAGE_SIZE);
}

These small test-functions should be attached to the event array as function pointers - hence the generic testing code would just do a ->event.trigger_event() callback, it wouldnt need to know much about the event itself.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

context-switches 7956
CPU-migrations 7

this needs to be provoked intentionally via sched_setaffinity():
first migrate to cpu0, then to cpu1.

There should be some option from user or we test it each time.

If this is builtin-test.c - then yes, testing it all the time would be a good default. (there might be other aspects of testing that would require options to this command in the future.)

Ingo

#12 lore raw

[tip:perfcounters/urgent] perf_counter tools: Introduce alias member in event_symbol

In reply to Jaswinder Singh Rajput
Commit-ID:  74d5b5889ea71a95d8924c08f8a7c6e2bdcbc0ba
Gitweb:     http://git.kernel.org/tip/74d5b5889ea71a95d8924c08f8a7c6e2bdcbc0ba
Author:     Jaswinder Singh Rajput <[email protected]>
AuthorDate: Mon, 22 Jun 2009 16:44:28 +0530
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 22 Jun 2009 13:29:58 +0200

perf_counter tools: Introduce alias member in event_symbol

By introducing alias member in event_symbol :

1. duplicate lines are removed, like:
cpu-cycles and cycles
branch-instructions and branches
context-switches and cs
cpu-migrations and migrations

2. We can also add alias for another events.

Now ./perf list looks like :

List of pre-defined events (to be used in -e):

  cpu-cycles OR cycles                     [Hardware event]
  instructions                             [Hardware event]
  cache-references                         [Hardware event]
  cache-misses                             [Hardware event]
  branch-instructions OR branches          [Hardware event]
  branch-misses                            [Hardware event]
  bus-cycles                               [Hardware event]
  cpu-clock                                [Software event]
  task-clock                               [Software event]
  page-faults                              [Software event]
  faults                                   [Software event]
  minor-faults                             [Software event]
  major-faults                             [Software event]
  context-switches OR cs                   [Software event]
  cpu-migrations OR migrations             [Software event]

rNNN [raw hardware event descriptor]

LKML-Reference: <[email protected]>

---
 tools/perf/util/parse-events.c |   63 ++++++++++++++++++++++++----------------
 1 files changed, 38 insertions(+), 25 deletions(-)
tools/perf/util/parse-events.c +38 -25
index 12abab3..f569548 100644
@@ -16,32 +16,29 @@ struct event_symbol {
 	u8	type;
 	u64	config;
 	char	*symbol;
+	char	*alias;
 };
 
 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
 
 static struct event_symbol event_symbols[] = {
-  { CHW(CPU_CYCLES),		"cpu-cycles",		},
-  { CHW(CPU_CYCLES),		"cycles",		},
-  { CHW(INSTRUCTIONS),		"instructions",		},
-  { CHW(CACHE_REFERENCES),	"cache-references",	},
-  { CHW(CACHE_MISSES),		"cache-misses",		},
-  { CHW(BRANCH_INSTRUCTIONS),	"branch-instructions",	},
-  { CHW(BRANCH_INSTRUCTIONS),	"branches",		},
-  { CHW(BRANCH_MISSES),		"branch-misses",	},
-  { CHW(BUS_CYCLES),		"bus-cycles",		},
-
-  { CSW(CPU_CLOCK),		"cpu-clock",		},
-  { CSW(TASK_CLOCK),		"task-clock",		},
-  { CSW(PAGE_FAULTS),		"page-faults",		},
-  { CSW(PAGE_FAULTS),		"faults",		},
-  { CSW(PAGE_FAULTS_MIN),	"minor-faults",		},
-  { CSW(PAGE_FAULTS_MAJ),	"major-faults",		},
-  { CSW(CONTEXT_SWITCHES),	"context-switches",	},
-  { CSW(CONTEXT_SWITCHES),	"cs",			},
-  { CSW(CPU_MIGRATIONS),	"cpu-migrations",	},
-  { CSW(CPU_MIGRATIONS),	"migrations",		},
+  { CHW(CPU_CYCLES),		"cpu-cycles",		"cycles"	},
+  { CHW(INSTRUCTIONS),		"instructions",		""		},
+  { CHW(CACHE_REFERENCES),	"cache-references",	""		},
+  { CHW(CACHE_MISSES),		"cache-misses",		""		},
+  { CHW(BRANCH_INSTRUCTIONS),	"branch-instructions",	"branches"	},
+  { CHW(BRANCH_MISSES),		"branch-misses",	""		},
+  { CHW(BUS_CYCLES),		"bus-cycles",		""		},
+
+  { CSW(CPU_CLOCK),		"cpu-clock",		""		},
+  { CSW(TASK_CLOCK),		"task-clock",		""		},
+  { CSW(PAGE_FAULTS),		"page-faults",		""		},
+  { CSW(PAGE_FAULTS),		"faults",		""		},
+  { CSW(PAGE_FAULTS_MIN),	"minor-faults",		""		},
+  { CSW(PAGE_FAULTS_MAJ),	"major-faults",		""		},
+  { CSW(CONTEXT_SWITCHES),	"context-switches",	"cs"		},
+  { CSW(CPU_MIGRATIONS),	"cpu-migrations",	"migrations"	},
 };
 
 #define __PERF_COUNTER_FIELD(config, name) \
@@ -196,6 +193,19 @@ static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *a
 	return 0;
 }
 
+static int check_events(const char *str, unsigned int i)
+{
+	if (!strncmp(str, event_symbols[i].symbol,
+		     strlen(event_symbols[i].symbol)))
+		return 1;
+
+	if (strlen(event_symbols[i].alias))
+		if (!strncmp(str, event_symbols[i].alias,
+		      strlen(event_symbols[i].alias)))
+			return 1;
+	return 0;
+}
+
 /*
  * Each event can have multiple symbolic names.
  * Symbolic names are (almost) exactly matched.
@@ -235,9 +245,7 @@ static int parse_event_symbols(const char *str, struct perf_counter_attr *attr)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
-		if (!strncmp(str, event_symbols[i].symbol,
-			     strlen(event_symbols[i].symbol))) {
-
+		if (check_events(str, i)) {
 			attr->type = event_symbols[i].type;
 			attr->config = event_symbols[i].config;
 
@@ -289,6 +297,7 @@ void print_events(void)
 {
 	struct event_symbol *syms = event_symbols;
 	unsigned int i, type, prev_type = -1;
+	char name[40];
 
 	fprintf(stderr, "\n");
 	fprintf(stderr, "List of pre-defined events (to be used in -e):\n");
@@ -301,14 +310,18 @@ void print_events(void)
 		if (type != prev_type)
 			fprintf(stderr, "\n");
 
-		fprintf(stderr, "  %-30s [%s]\n", syms->symbol,
+		if (strlen(syms->alias))
+			sprintf(name, "%s OR %s", syms->symbol, syms->alias);
+		else
+			strcpy(name, syms->symbol);
+		fprintf(stderr, "  %-40s [%s]\n", name,
 			event_type_descriptors[type]);
 
 		prev_type = type;
 	}
 
 	fprintf(stderr, "\n");
-	fprintf(stderr, "  %-30s [raw hardware event descriptor]\n",
+	fprintf(stderr, "  %-40s [raw hardware event descriptor]\n",
 		"rNNN");
 	fprintf(stderr, "\n");
 
#13 lore raw

[tip:perfcounters/urgent] perf_counter tools: Define separate declarations for H/W and S/W events

In reply to Jaswinder Singh Rajput
Commit-ID:  51e268423151fc7bb41945bde7843160b6a14c32
Gitweb:     http://git.kernel.org/tip/51e268423151fc7bb41945bde7843160b6a14c32
Author:     Jaswinder Singh Rajput <[email protected]>
AuthorDate: Mon, 22 Jun 2009 16:43:14 +0530
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 22 Jun 2009 13:29:57 +0200

perf_counter tools: Define separate declarations for H/W and S/W events

Define separate declarations for H/W and S/W events to:

1. Shorten name to save some space so that we can add more members
2. Fix alignment
3. Avoid declaring HARDWARE/SOFTWARE again and again.

Removed unused CR(x, y)

LKML-Reference: <[email protected]>

---
 tools/perf/util/parse-events.c |   42 ++++++++++++++++++++--------------------
 1 files changed, 21 insertions(+), 21 deletions(-)
tools/perf/util/parse-events.c +22 -22
index 35d04da..12abab3 100644
@@ -18,30 +18,30 @@ struct event_symbol {
 	char	*symbol;
 };
 
-#define C(x, y) .type = PERF_TYPE_##x, .config = PERF_COUNT_##y
-#define CR(x, y) .type = PERF_TYPE_##x, .config = y
+#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
+#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
 
 static struct event_symbol event_symbols[] = {
-  { C(HARDWARE, HW_CPU_CYCLES),		"cpu-cycles",		},
-  { C(HARDWARE, HW_CPU_CYCLES),		"cycles",		},
-  { C(HARDWARE, HW_INSTRUCTIONS),	"instructions",		},
-  { C(HARDWARE, HW_CACHE_REFERENCES),	"cache-references",	},
-  { C(HARDWARE, HW_CACHE_MISSES),	"cache-misses",		},
-  { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branch-instructions",	},
-  { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branches",		},
-  { C(HARDWARE, HW_BRANCH_MISSES),	"branch-misses",	},
-  { C(HARDWARE, HW_BUS_CYCLES),		"bus-cycles",		},
-
-  { C(SOFTWARE, SW_CPU_CLOCK),		"cpu-clock",		},
-  { C(SOFTWARE, SW_TASK_CLOCK),		"task-clock",		},
-  { C(SOFTWARE, SW_PAGE_FAULTS),	"page-faults",		},
-  { C(SOFTWARE, SW_PAGE_FAULTS),	"faults",		},
-  { C(SOFTWARE, SW_PAGE_FAULTS_MIN),	"minor-faults",		},
-  { C(SOFTWARE, SW_PAGE_FAULTS_MAJ),	"major-faults",		},
-  { C(SOFTWARE, SW_CONTEXT_SWITCHES),	"context-switches",	},
-  { C(SOFTWARE, SW_CONTEXT_SWITCHES),	"cs",			},
-  { C(SOFTWARE, SW_CPU_MIGRATIONS),	"cpu-migrations",	},
-  { C(SOFTWARE, SW_CPU_MIGRATIONS),	"migrations",		},
+  { CHW(CPU_CYCLES),		"cpu-cycles",		},
+  { CHW(CPU_CYCLES),		"cycles",		},
+  { CHW(INSTRUCTIONS),		"instructions",		},
+  { CHW(CACHE_REFERENCES),	"cache-references",	},
+  { CHW(CACHE_MISSES),		"cache-misses",		},
+  { CHW(BRANCH_INSTRUCTIONS),	"branch-instructions",	},
+  { CHW(BRANCH_INSTRUCTIONS),	"branches",		},
+  { CHW(BRANCH_MISSES),		"branch-misses",	},
+  { CHW(BUS_CYCLES),		"bus-cycles",		},
+
+  { CSW(CPU_CLOCK),		"cpu-clock",		},
+  { CSW(TASK_CLOCK),		"task-clock",		},
+  { CSW(PAGE_FAULTS),		"page-faults",		},
+  { CSW(PAGE_FAULTS),		"faults",		},
+  { CSW(PAGE_FAULTS_MIN),	"minor-faults",		},
+  { CSW(PAGE_FAULTS_MAJ),	"major-faults",		},
+  { CSW(CONTEXT_SWITCHES),	"context-switches",	},
+  { CSW(CONTEXT_SWITCHES),	"cs",			},
+  { CSW(CPU_MIGRATIONS),	"cpu-migrations",	},
+  { CSW(CPU_MIGRATIONS),	"migrations",		},
 };
 
 #define __PERF_COUNTER_FIELD(config, name) \