Skip to contentSkip to conversation

perf: add support for per-event sampling period or frequency in perf record (v2)

PATCH New Stephane Eranian 1 participant 1 message Nov 23, 2010 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: add support for per-event sampling period or frequency in perf record (v2)

This patch allows specifying a per event sampling period or frequency. Up until now, the same sampling period or frequency was applied to all the events specified on the command line of perf record. A sampling period depends on the event, thus it is necessary to specify it per event.

The per-event sampling period or frequency is specified as part of the event string, similar to the priv level mask. There are two new modifiers:
period, freq. They both take an integer value:

$ perf record -e cycles:u:period=100000,instructions:k:freq=1500 -a -- sleep 5

An event can have either period= or freq= but not both.

The -F and -c options are used whenever an event does not have an explicit period or frequency:

$ perf record -e cycles:period=100000,instructions -F 1000 -a -- sleep 5

Here instructions will be sampled at 1000Hz and cycles with the fixed period 100,000.

There is no requirement as to the ordering of those new modifiers.

This second version drops the comma-separated list of periods or frequencies in favor of new event modifiers.

---

tools/perf/Documentation/perf-record.txt +12 -2
index a91f9f9..86fc6f7 100644
@@ -39,6 +39,14 @@ OPTIONS
           be passed as follows: '\mem:addr[:[r][w][x]]'.
           If you want to profile read-write accesses in 0x1000, just set
           'mem:0x1000:rw'.
+
+	- a sampling period can be appended to the event using the :period=XX
+	  notation where XX is expressed in the unit of the measured event.
+	  This is mutually exclusive with the :freq mode.
+
+	- a sampling rate can be appended to the event using the :freq=XX
+	  notation where XX is in Hertz. This is mutually exclusive with the
+	  :period mode.
 -a::
         System-wide collection.
 
@@ -62,7 +70,8 @@ OPTIONS
 
 -c::
 --count=::
-	Event period to sample.
+	Default event sampling period. It is used whenever an event is
+	specified without the :period or :freq modifier.
 
 -o::
 --output=::
@@ -73,7 +82,8 @@ OPTIONS
 	Child tasks do not inherit counters.
 -F::
 --freq=::
-	Profile at this frequency.
+	Default event sampling frequency. It is used whenever an event is
+	specified without the :freq or :period modifier.
 
 -m::
 --mmap-pages=::
tools/perf/builtin-stat.c +10 -0
index 970a7f2..d009ddf 100644
@@ -696,6 +696,16 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
 		memcpy(attrs, default_attrs, sizeof(default_attrs));
 		nr_counters = ARRAY_SIZE(default_attrs);
 	}
+	/*
+	 * validate event attr as set by parse_event_symbols()
+	 */
+	for (i = 0; i < nr_counters; i++) {
+		if (attrs[i].sample_period) {
+			die("cannot set a sampling period or frequency with"
+			    " perf stat\n");
+			return -EINVAL;
+		}
+	}
 
 	if (system_wide)
 		nr_cpus = read_cpu_map(cpu_list);
tools/perf/util/parse-events.c +95 -14

147 lines not on this page · raw message