All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH lttng-tools v2 2/3] Test the parsing of perf raw context
       [not found] <1466623636-24179-1-git-send-email-jdesfossez@efficios.com>
@ 2016-06-22 19:27 ` Julien Desfossez
  2016-06-22 19:27 ` [PATCH lttng-tools v2 3/3] Create a dedicated test suite for Perf Julien Desfossez
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: Julien Desfossez @ 2016-06-22 19:27 UTC (permalink / raw)
  To: jgalar, mathieu.desnoyers; +Cc: lttng-dev, Julien Desfossez

Only test the parsing of the new option in fast_regression since the
real integration test requires particular hardware and kernel
configuration which might not be available.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
---
 tests/fast_regression                |  1 +
 tests/regression/ust/test_event_perf | 46 ++++++++++++++++++++++++++----------
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/tests/fast_regression b/tests/fast_regression
index 0c4f079..ab5521f 100644
--- a/tests/fast_regression
+++ b/tests/fast_regression
@@ -30,3 +30,4 @@ regression/ust/clock-override/test_clock_override
 regression/ust/rotation-destroy-flush/test_rotation_destroy_flush
 regression/ust/test_event_basic
 regression/ust/test_event_tracef
+regression/ust/test_event_perf
diff --git a/tests/regression/ust/test_event_perf b/tests/regression/ust/test_event_perf
index 7dc2168..38ac061 100755
--- a/tests/regression/ust/test_event_perf
+++ b/tests/regression/ust/test_event_perf
@@ -23,7 +23,7 @@ TESTDIR=$CURDIR/../..
 LTTNG_BIN="lttng"
 SESSION_NAME="perf_counters"
 EVENT_NAME="tp:tptest"
-NUM_TESTS=10
+NUM_TESTS=23
 NR_ITER=1
 NR_USEC_WAIT=1
 TESTAPP_PATH="$TESTDIR/utils/testapp"
@@ -42,14 +42,32 @@ function enable_ust_lttng_event_per_chan()
 	ok $? "Enable event $event_name for session $sess_name in channel $chan_name"
 }
 
-function add_ust_lttng_context()
+# Only test parsing of the enabling by raw ID
+function test_parsing_raw()
 {
-	sess_name="$1"
-	chan_name="$2"
-	type="$3"
+	TRACE_PATH=$(mktemp -d)
+	SESSION_NAME="ust_event_basic"
+	CHAN_NAME="mychan"
+
+	create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+
+	enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
+
+	enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
 
-	$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $sess_name -c $chan_name -t $type -u >/dev/null 2>&1
-	ok $? "Add context $type for session $sess_name in channel $chan_name"
+	add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110:test"
+	add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:b0110:test"
+	add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110:"
+	add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110::"
+	add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r:test"
+	add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r::"
+	add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw::"
+	add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw"
+	add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110:test:wrong"
+
+	destroy_lttng_session_ok $SESSION_NAME
+
+	rm -rf $TRACE_PATH
 }
 
 function test_event_basic()
@@ -64,7 +82,7 @@ function test_event_basic()
 
 	enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
 
-	add_ust_lttng_context $SESSION_NAME $CHAN_NAME "perf:thread:page-fault"
+	add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:page-fault"
 
 	start_lttng_tracing_ok
 
@@ -96,11 +114,13 @@ else
         isroot=0
 fi
 
-skip $isroot "Root access is needed. Skipping UST perf tests." ${NUM_TESTS} ||
-{
-	start_lttng_sessiond
+start_lttng_sessiond
 
-	test_event_basic
+test_parsing_raw
 
-	stop_lttng_sessiond
+skip $isroot "Root access is needed. Skipping UST perf tests." 8 ||
+{
+	test_event_basic
 }
+
+stop_lttng_sessiond
-- 
1.9.1

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH lttng-tools v2 3/3] Create a dedicated test suite for Perf
       [not found] <1466623636-24179-1-git-send-email-jdesfossez@efficios.com>
  2016-06-22 19:27 ` [PATCH lttng-tools v2 2/3] Test the parsing of perf raw context Julien Desfossez
@ 2016-06-22 19:27 ` Julien Desfossez
  2016-07-05  2:31 ` [PATCH lttng-tools v2 1/3] Enable perf PMU counters by raw ID Jérémie Galarneau
       [not found] ` <1466623636-24179-3-git-send-email-jdesfossez@efficios.com>
  3 siblings, 0 replies; 4+ messages in thread
From: Julien Desfossez @ 2016-06-22 19:27 UTC (permalink / raw)
  To: jgalar, mathieu.desnoyers; +Cc: lttng-dev, Julien Desfossez

Introduce the perf_regression test suite that must be run manually to
check if the support for the Perf-related features are available on the
current machine. This test cannot be run automatically since there are
some platforms where it can fail.

For now, the test only makes sure that we can trace events with perf
contexts enabled by raw ID in kernel and user-space. The test only works
if libpfm is installed on the system and fails if it is not installed.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
---
 .gitignore               |   1 +
 README.md                |   2 +
 configure.ac             |   8 +++
 tests/Makefile.am        |   8 +--
 tests/perf/Makefile.am   |   6 +++
 tests/perf/find_event.c  |  83 ++++++++++++++++++++++++++++++
 tests/perf/test_perf_raw | 129 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/perf_regression    |   1 +
 8 files changed, 234 insertions(+), 4 deletions(-)
 create mode 100644 tests/perf/Makefile.am
 create mode 100644 tests/perf/find_event.c
 create mode 100755 tests/perf/test_perf_raw
 create mode 100644 tests/perf_regression

diff --git a/.gitignore b/.gitignore
index ac78292..c31dbc5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -106,6 +106,7 @@ tests/regression/ust/python-logging/test_python_logging
 /tests/utils/testapp/gen-ust-tracef/gen-ust-tracef
 /tests/regression/tools/live/live_test
 /tests/unit/ini_config/ini_config
+/tests/perf/find_event
 
 # man pages
 /doc/man/*.1
diff --git a/README.md b/README.md
index 22de252..3156a15 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,8 @@ The following items are _optional_ dependencies:
     pages with the `--help` option or with the `lttng help` command.
     Note that without `man`, you cannot get offline help with
     LTTng-tools commands, not even their usage.
+  - **`libpfm`**: needed to run the perf regression test suite.
+    - Debian/Ubuntu package: `libpfm4-dev`
 
 LTTng-tools supports both the [LTTng Linux Kernel tracer](https://lttng.org)
 and [LTTng user space tracer](https://lttng.org) released as part of the same
diff --git a/configure.ac b/configure.ac
index d6149fe..5d5f001 100644
--- a/configure.ac
+++ b/configure.ac
@@ -467,6 +467,13 @@ AC_CHECK_LIB([c], [open_memstream],
 ]
 )
 
+# check for libpfm
+AC_CHECK_LIB([pfm], [pfm_initialize],
+	     [
+	      have_libpfm=yes
+	      ])
+AM_CONDITIONAL([LTTNG_TOOLS_BUILD_WITH_LIBPFM], [test "x$have_libpfm" = "xyes"])
+
 AC_ARG_ENABLE([git-version],
               [AC_HELP_STRING([--disable-git-version],
                               [Do not use the git version for the build])],
@@ -1005,6 +1012,7 @@ AC_CONFIG_FILES([
 	tests/regression/ust/clock-override/Makefile
 	tests/regression/ust/type-declarations/Makefile
 	tests/regression/ust/rotation-destroy-flush/Makefile
+	tests/regression/ust/perf/Makefile
 	tests/stress/Makefile
 	tests/unit/Makefile
 	tests/unit/ini_config/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3600e99..d460fb6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,8 +1,8 @@
 SUBDIRS =
-DIST_SUBDIRS = utils regression unit stress destructive
+DIST_SUBDIRS = utils regression unit stress destructive perf
 
 if BUILD_TESTS
-SUBDIRS += . utils regression unit stress destructive
+SUBDIRS += . utils regression unit stress destructive perf
 if HAS_PGREP
 check-am:
 	$(top_srcdir)/tests/utils/warn_processes.sh $(PGREP)
@@ -14,8 +14,8 @@ else
 endif
 
 
-dist_noinst_SCRIPTS = run.sh fast_regression long_regression root_regression root_destructive_tests
-EXTRA_DIST = run.sh fast_regression long_regression root_regression README root_destructive_tests
+dist_noinst_SCRIPTS = run.sh fast_regression long_regression root_regression root_destructive_tests perf_regression
+EXTRA_DIST = run.sh fast_regression long_regression root_regression README root_destructive_tests perf_regression
 
 all-local:
 	@if [ x"$(srcdir)" != x"$(builddir)" ]; then \
diff --git a/tests/perf/Makefile.am b/tests/perf/Makefile.am
new file mode 100644
index 0000000..40bb754
--- /dev/null
+++ b/tests/perf/Makefile.am
@@ -0,0 +1,6 @@
+if LTTNG_TOOLS_BUILD_WITH_LIBPFM
+LIBS += -lpfm
+
+noinst_PROGRAMS = find_event
+find_event_SOURCES = find_event.c
+endif
diff --git a/tests/perf/find_event.c b/tests/perf/find_event.c
new file mode 100644
index 0000000..ae63800
--- /dev/null
+++ b/tests/perf/find_event.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c)  2016 Julien Desfossez <jdesfossez@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * as published by the Free Software Foundation; only version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <perfmon/pfmlib.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+	int ret, i;
+	unsigned int j;
+	pfm_pmu_info_t pinfo;
+
+	if (argc != 2) {
+		fprintf(stderr, "Usage: %s <pmu counter to find>\n"
+				"ex: %s UNHALTED_REFERENCE_CYCLES\n"
+				"Returns the first occurence it finds with "
+				"return code 0.\n"
+				"If not found returns 1, on error returns -1\n",
+				argv[0], argv[0]);
+		ret = -1;
+		goto end;
+	}
+
+	memset(&pinfo, 0, sizeof(pinfo));
+	pinfo.size = sizeof(pinfo);
+
+	ret = pfm_initialize();
+	if (ret != PFM_SUCCESS) {
+		fprintf(stderr, "Failed to initialise libpfm: %s",
+				pfm_strerror(ret));
+		ret = -1;
+		goto end;
+	}
+
+	pfm_for_all_pmus(j) {
+		ret = pfm_get_pmu_info(j, &pinfo);
+		if (ret != PFM_SUCCESS) {
+			continue;
+		}
+
+		for (i = pinfo.first_event; i != -1; i = pfm_get_event_next(i)) {
+			pfm_event_info_t info;
+
+			ret = pfm_get_event_info(i, PFM_OS_NONE, &info);
+			if (ret != PFM_SUCCESS) {
+				fprintf(stderr, "Cannot get event info: %s\n",
+						pfm_strerror(ret));
+				ret = -1;
+				goto end;
+			}
+
+			if (info.pmu != j)
+				continue;
+
+			if (strcmp(info.name, argv[1]) == 0) {
+				fprintf(stdout, "r%lx\n", info.code);
+				ret = 0;
+				goto end;
+			}
+		}
+	}
+
+	ret = 1;
+
+end:
+	return ret;
+}
diff --git a/tests/perf/test_perf_raw b/tests/perf/test_perf_raw
new file mode 100755
index 0000000..68b12d7
--- /dev/null
+++ b/tests/perf/test_perf_raw
@@ -0,0 +1,129 @@
+#!/bin/bash
+#
+# Copyright (C) - 2016 Julien Desfossez <jdesfossez@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+TEST_DESC="Perf counters"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/..
+LTTNG_BIN="lttng"
+SESSION_NAME="perf_counters"
+NUM_TESTS=20
+NR_ITER=1
+NR_USEC_WAIT=1
+TESTAPP_PATH="$TESTDIR/utils/testapp"
+TESTAPP_NAME="gen-ust-events"
+TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
+
+source $TESTDIR/utils/utils.sh
+
+function enable_ust_lttng_event_per_chan()
+{
+	sess_name="$1"
+	event_name="$2"
+	chan_name="$3"
+
+	$TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -c $chan_name -u >/dev/null 2>&1
+	ok $? "Enable event $event_name for session $sess_name in channel $chan_name"
+}
+
+function test_ust_raw()
+{
+	TRACE_PATH=$(mktemp -d)
+	SESSION_NAME="ust_perf"
+	CHAN_NAME="mychan"
+	EVENT_NAME="tp:tptest"
+	PMU="UNHALTED_REFERENCE_CYCLES"
+	PERFID=$($CURDIR/find_event $PMU)
+	test $? -eq "0"
+	ok $? "Find PMU $PMU"
+
+	create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+
+	enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
+
+	enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
+
+	add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
+
+	start_lttng_tracing_ok
+
+	$TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1
+
+	stop_lttng_tracing_ok
+
+	destroy_lttng_session_ok $SESSION_NAME
+
+	validate_trace "perf_thread_raw_${PERFID}_test" $TRACE_PATH
+
+	rm -rf $TRACE_PATH
+}
+
+function test_kernel_raw()
+{
+	TRACE_PATH=$(mktemp -d)
+	SESSION_NAME="kernel_perf"
+	CHAN_NAME="mychan"
+	EVENT_NAME="lttng_test_filter_event"
+	PMU="UNHALTED_REFERENCE_CYCLES"
+	PERFID=$($CURDIR/find_event $PMU)
+	test $? -eq "0"
+	ok $? "Find PMU $PMU"
+
+	create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+
+	lttng_enable_kernel_channel_ok $SESSION_NAME $CHAN_NAME
+
+	enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
+
+	add_context_kernel_ok $SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
+
+	start_lttng_tracing_ok
+
+	echo -n 10 > /proc/lttng-test-filter-event
+
+	stop_lttng_tracing_ok
+
+	destroy_lttng_session_ok $SESSION_NAME
+
+	validate_trace "perf_cpu_raw_${PERFID}_test" $TRACE_PATH
+
+	rm -rf $TRACE_PATH
+}
+
+if [ "$(id -u)" == "0" ]; then
+	isroot=1
+else
+	isroot=0
+fi
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+start_lttng_sessiond
+
+test_ust_raw
+
+skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
+{
+	modprobe lttng-test
+	test_kernel_raw
+	rmmod lttng-test
+}
+
+stop_lttng_sessiond
diff --git a/tests/perf_regression b/tests/perf_regression
new file mode 100644
index 0000000..c4b9b86
--- /dev/null
+++ b/tests/perf_regression
@@ -0,0 +1 @@
+perf/test_perf_raw
-- 
1.9.1

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH lttng-tools v2 1/3] Enable perf PMU counters by raw ID
       [not found] <1466623636-24179-1-git-send-email-jdesfossez@efficios.com>
  2016-06-22 19:27 ` [PATCH lttng-tools v2 2/3] Test the parsing of perf raw context Julien Desfossez
  2016-06-22 19:27 ` [PATCH lttng-tools v2 3/3] Create a dedicated test suite for Perf Julien Desfossez
@ 2016-07-05  2:31 ` Jérémie Galarneau
       [not found] ` <1466623636-24179-3-git-send-email-jdesfossez@efficios.com>
  3 siblings, 0 replies; 4+ messages in thread
From: Jérémie Galarneau @ 2016-07-05  2:31 UTC (permalink / raw)
  To: Julien Desfossez; +Cc: lttng-dev, Jeremie Galarneau

On Wed, Jun 22, 2016 at 3:27 PM, Julien Desfossez
<jdesfossez@efficios.com> wrote:
> Allow enabling perf PMU counters by raw ID in addition to the generic
> list already provided. The format for kernel tracing is
> "perf:cpu:raw:rNNN:<name>" and "perf:thread:raw:rNNN:<name> for
> user-space. The rNNN format is the same as perf-record(1) where NNN is a
> hexadecimal event descriptor in the form of umask+eventsel. The <name>
> field allows the user to give a more friendly name.

to associate a clearer name to the counter.

>
> Example usage on Intel i7-3520M to get the unhalted reference cycles
> (eventsel: 0x13c) count at privilege level 0 (umask: 0x00):
> lttng add-context -k -t perf:cpu:raw:r0013c:x86unhalted
>
> Result in the trace:
> sched_switch: { cpu_id = 3 }, {
>         perf_cpu_raw_r0013c_x86unhalted = 27632578 }, [...]
>
> Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
> ---
>  doc/man/lttng-add-context.1.txt      |  8 +++
>  src/bin/lttng/commands/add_context.c | 94 +++++++++++++++++++++++++++++++++++-
>  2 files changed, 101 insertions(+), 1 deletion(-)
>
> diff --git a/doc/man/lttng-add-context.1.txt b/doc/man/lttng-add-context.1.txt
> index f995a7f..c43581a 100644
> --- a/doc/man/lttng-add-context.1.txt
> +++ b/doc/man/lttng-add-context.1.txt
> @@ -45,6 +45,14 @@ per-thread (`perf:thread:` prefix) counters. Currently, per-CPU counters
>  can only be used in the Linux kernel tracing domain, while per-thread
>  counters can only be used in the user space tracing domain.
>
> +It is also possible to enable PMU counters by raw ID using the
> +`perf:cpu:raw:r<N>:<name>` or `perf:thread:raw:r<N>:<name>` format for the
> +kernel and user-space respectively. `<N>` is a hexadecimal event descriptor
> +which is the same format as perf-record(1): a concatenation of the `Umask
> +value` and `Event number` provided by the processors manufacturer. The possible
> +values for this field are processor-specific. The `<name>` field is used to
> +give a symbolic name to the counter in the trace.

...to associate a...

> +
>  Application-specific context fields can be added to a channel using the
>  following syntax:
>
> diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c
> index 2f43dc7..711c1e0 100644
> --- a/src/bin/lttng/commands/add_context.c
> +++ b/src/bin/lttng/commands/add_context.c
> @@ -87,6 +87,7 @@ enum perf_type {
>         PERF_TYPE_HARDWARE = 0,
>         PERF_TYPE_SOFTWARE = 1,
>         PERF_TYPE_HW_CACHE = 3,
> +       PERF_TYPE_RAW = 4,
>  };
>
>  enum perf_count_hard {
> @@ -688,9 +689,88 @@ end:
>  }
>
>  static
> +int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type)
> +{
> +       char *next;

Reduce scope of "next" to the "for" loop.

> +       int ret;
> +       int field_pos = 0;
> +       char *tmp_list;
> +
> +       tmp_list = strdup(ctx);
> +       if (!tmp_list) {
> +               PERROR("strdup temp list");
> +               ret = -ENOMEM;
> +               goto error;

No need for a separate error label to skip the free() as tmp_list is NULL.

> +       }
> +
> +       /* Looking for "perf:[cpu|thread]:raw:<mask>:<name>". */
> +       for (;;) {
> +               next = strtok(tmp_list, ":");
> +               if (!next) {
> +                       break;
> +               }
> +               tmp_list = NULL;

tmp_list is leaked.

> +               switch (field_pos) {
> +               case 0:
> +                       if (strncmp(next, "perf", 4) != 0) {
> +                               ret = -1;
> +                               goto end;
> +                       }
> +                       break;
> +               case 1:
> +                       if (strncmp(next, "cpu", 3) == 0) {
> +                               type->opt->ctx_type = CONTEXT_PERF_CPU_COUNTER;
> +                       } else if (strncmp(next, "thread", 4) == 0) {
> +                               type->opt->ctx_type = CONTEXT_PERF_THREAD_COUNTER;
> +                       } else {
> +                               ret = -1;
> +                               goto end;
> +                       }
> +                       break;
> +               case 2:
> +                       if (strncmp(next, "raw", 3) != 0) {
> +                               ret = -1;
> +                               goto end;
> +                       }
> +                       break;
> +               case 3:
> +                       if (strlen(next) < 2 || next[0] != 'r') {
> +                               ERR("Wrong perf raw mask format: rNNN");
> +                               ret = -1;
> +                               goto end;
> +                       }
> +                       type->opt->u.perf.config = strtoll(next +  1, NULL, 16);

strtoll() should be checked for error (setting errno to 0 beforehand,
and checking after for EINVAL and ERANGE, but also using the endptr).

This currently allows, for instance:
lttng add-context -u -t perf:thread:raw:rXYZ:oops

Such malformed cases should be added to the test suite.

> +                       break;
> +               case 4:
> +                       /* name */
> +                       break;
> +               case 5:
> +                       ERR("Too many ':' in perf raw format");
> +                       ret = -1;
> +                       goto end;
> +               };
> +               field_pos++;
> +       }
> +
> +       if (field_pos < 5) {
> +               ERR("Wrong perf raw format");

"Invalid perf counter specifier, expected a specifier of the form
perf:cpu:raw:rNNN:<name> or perf:thread:raw:rNNN:<name>"

> +               ret = -1;
> +               goto end;
> +       }
> +
> +       ret = 0;
> +       goto end;
> +
> +end:
> +       free(tmp_list);
> +error:
> +       return ret;
> +}
> +
> +static
>  struct ctx_type *get_context_type(const char *ctx)
>  {
> -       int opt_index;
> +       int opt_index, ret;
>         struct ctx_type *type = NULL;
>         const char app_ctx_prefix[] = "$app.";
>         char *provider_name = NULL, *ctx_name = NULL;
> @@ -713,6 +793,18 @@ struct ctx_type *get_context_type(const char *ctx)
>                 goto found;
>         }
>
> +       /* Check if ctx is a raw perf context. */
> +       ret = find_ctx_type_perf_raw(ctx, type);
> +       if (ret == 0) {
> +               type->opt->u.perf.type = PERF_TYPE_RAW;
> +               type->opt->symbol = strdup(ctx);
> +               if (!type->opt->symbol) {
> +                       PERROR("Copy perf field name");
> +                       goto not_found;
> +               }
> +               goto found;
> +       }
> +
>         /*
>          * No match found against static contexts; check if it is an app
>          * context.
> --
> 1.9.1
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH lttng-tools v2 3/3] Create a dedicated test suite for Perf
       [not found] ` <1466623636-24179-3-git-send-email-jdesfossez@efficios.com>
@ 2016-07-05  2:31   ` Jérémie Galarneau
  0 siblings, 0 replies; 4+ messages in thread
From: Jérémie Galarneau @ 2016-07-05  2:31 UTC (permalink / raw)
  To: Julien Desfossez; +Cc: lttng-dev, Jeremie Galarneau

On Wed, Jun 22, 2016 at 3:27 PM, Julien Desfossez
<jdesfossez@efficios.com> wrote:
> Introduce the perf_regression test suite that must be run manually to
> check if the support for the Perf-related features are available on the
> current machine. This test cannot be run automatically since there are
> some platforms where it can fail.
>
> For now, the test only makes sure that we can trace events with perf
> contexts enabled by raw ID in kernel and user-space. The test only works
> if libpfm is installed on the system and fails if it is not installed.
>
> Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
> ---
>  .gitignore               |   1 +
>  README.md                |   2 +
>  configure.ac             |   8 +++
>  tests/Makefile.am        |   8 +--
>  tests/perf/Makefile.am   |   6 +++
>  tests/perf/find_event.c  |  83 ++++++++++++++++++++++++++++++
>  tests/perf/test_perf_raw | 129 +++++++++++++++++++++++++++++++++++++++++++++++
>  tests/perf_regression    |   1 +
>  8 files changed, 234 insertions(+), 4 deletions(-)
>  create mode 100644 tests/perf/Makefile.am
>  create mode 100644 tests/perf/find_event.c
>  create mode 100755 tests/perf/test_perf_raw
>  create mode 100644 tests/perf_regression
>
> diff --git a/.gitignore b/.gitignore
> index ac78292..c31dbc5 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -106,6 +106,7 @@ tests/regression/ust/python-logging/test_python_logging
>  /tests/utils/testapp/gen-ust-tracef/gen-ust-tracef
>  /tests/regression/tools/live/live_test
>  /tests/unit/ini_config/ini_config
> +/tests/perf/find_event
>
>  # man pages
>  /doc/man/*.1
> diff --git a/README.md b/README.md
> index 22de252..3156a15 100644
> --- a/README.md
> +++ b/README.md
> @@ -57,6 +57,8 @@ The following items are _optional_ dependencies:
>      pages with the `--help` option or with the `lttng help` command.
>      Note that without `man`, you cannot get offline help with
>      LTTng-tools commands, not even their usage.
> +  - **`libpfm`**: needed to run the perf regression test suite.
> +    - Debian/Ubuntu package: `libpfm4-dev`
>
>  LTTng-tools supports both the [LTTng Linux Kernel tracer](https://lttng.org)
>  and [LTTng user space tracer](https://lttng.org) released as part of the same
> diff --git a/configure.ac b/configure.ac
> index d6149fe..5d5f001 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -467,6 +467,13 @@ AC_CHECK_LIB([c], [open_memstream],
>  ]
>  )
>
> +# check for libpfm
> +AC_CHECK_LIB([pfm], [pfm_initialize],
> +            [
> +             have_libpfm=yes
> +             ])
> +AM_CONDITIONAL([LTTNG_TOOLS_BUILD_WITH_LIBPFM], [test "x$have_libpfm" = "xyes"])
> +
>  AC_ARG_ENABLE([git-version],
>                [AC_HELP_STRING([--disable-git-version],
>                                [Do not use the git version for the build])],
> @@ -1005,6 +1012,7 @@ AC_CONFIG_FILES([
>         tests/regression/ust/clock-override/Makefile
>         tests/regression/ust/type-declarations/Makefile
>         tests/regression/ust/rotation-destroy-flush/Makefile
> +       tests/regression/ust/perf/Makefile

This patch does not build here.

I think this should point to
tests/perf/Makefile

>         tests/stress/Makefile
>         tests/unit/Makefile
>         tests/unit/ini_config/Makefile
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 3600e99..d460fb6 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -1,8 +1,8 @@
>  SUBDIRS =
> -DIST_SUBDIRS = utils regression unit stress destructive
> +DIST_SUBDIRS = utils regression unit stress destructive perf
>
>  if BUILD_TESTS
> -SUBDIRS += . utils regression unit stress destructive
> +SUBDIRS += . utils regression unit stress destructive perf
>  if HAS_PGREP
>  check-am:
>         $(top_srcdir)/tests/utils/warn_processes.sh $(PGREP)
> @@ -14,8 +14,8 @@ else
>  endif
>
>
> -dist_noinst_SCRIPTS = run.sh fast_regression long_regression root_regression root_destructive_tests
> -EXTRA_DIST = run.sh fast_regression long_regression root_regression README root_destructive_tests
> +dist_noinst_SCRIPTS = run.sh fast_regression long_regression root_regression root_destructive_tests perf_regression
> +EXTRA_DIST = run.sh fast_regression long_regression root_regression README root_destructive_tests perf_regression
>
>  all-local:
>         @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
> diff --git a/tests/perf/Makefile.am b/tests/perf/Makefile.am
> new file mode 100644
> index 0000000..40bb754
> --- /dev/null
> +++ b/tests/perf/Makefile.am
> @@ -0,0 +1,6 @@
> +if LTTNG_TOOLS_BUILD_WITH_LIBPFM
> +LIBS += -lpfm
> +
> +noinst_PROGRAMS = find_event
> +find_event_SOURCES = find_event.c
> +endif
> diff --git a/tests/perf/find_event.c b/tests/perf/find_event.c
> new file mode 100644
> index 0000000..ae63800
> --- /dev/null
> +++ b/tests/perf/find_event.c
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright (c)  2016 Julien Desfossez <jdesfossez@efficios.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * as published by the Free Software Foundation; only version 2
> + * of the License.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#include <stdio.h>
> +#include <perfmon/pfmlib.h>
> +#include <string.h>
> +
> +int main(int argc, char **argv)
> +{
> +       int ret, i;
> +       unsigned int j;
> +       pfm_pmu_info_t pinfo;
> +
> +       if (argc != 2) {
> +               fprintf(stderr, "Usage: %s <pmu counter to find>\n"
> +                               "ex: %s UNHALTED_REFERENCE_CYCLES\n"
> +                               "Returns the first occurence it finds with "
> +                               "return code 0.\n"
> +                               "If not found returns 1, on error returns -1\n",
> +                               argv[0], argv[0]);
> +               ret = -1;
> +               goto end;
> +       }
> +
> +       memset(&pinfo, 0, sizeof(pinfo));
> +       pinfo.size = sizeof(pinfo);
> +
> +       ret = pfm_initialize();
> +       if (ret != PFM_SUCCESS) {
> +               fprintf(stderr, "Failed to initialise libpfm: %s",
> +                               pfm_strerror(ret));
> +               ret = -1;
> +               goto end;
> +       }
> +
> +       pfm_for_all_pmus(j) {
> +               ret = pfm_get_pmu_info(j, &pinfo);
> +               if (ret != PFM_SUCCESS) {
> +                       continue;
> +               }
> +
> +               for (i = pinfo.first_event; i != -1; i = pfm_get_event_next(i)) {
> +                       pfm_event_info_t info;
> +
> +                       ret = pfm_get_event_info(i, PFM_OS_NONE, &info);
> +                       if (ret != PFM_SUCCESS) {
> +                               fprintf(stderr, "Cannot get event info: %s\n",
> +                                               pfm_strerror(ret));
> +                               ret = -1;
> +                               goto end;
> +                       }
> +
> +                       if (info.pmu != j)
> +                               continue;
> +
> +                       if (strcmp(info.name, argv[1]) == 0) {
> +                               fprintf(stdout, "r%lx\n", info.code);
> +                               ret = 0;
> +                               goto end;
> +                       }
> +               }
> +       }
> +
> +       ret = 1;
> +
> +end:
> +       return ret;
> +}
> diff --git a/tests/perf/test_perf_raw b/tests/perf/test_perf_raw
> new file mode 100755
> index 0000000..68b12d7
> --- /dev/null
> +++ b/tests/perf/test_perf_raw
> @@ -0,0 +1,129 @@
> +#!/bin/bash
> +#
> +# Copyright (C) - 2016 Julien Desfossez <jdesfossez@efficios.com>
> +#
> +# This program is free software; you can redistribute it and/or modify it
> +# under the terms of the GNU General Public License, version 2 only, as
> +# published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it will be useful, but WITHOUT
> +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> +# more details.
> +#
> +# You should have received a copy of the GNU General Public License along with
> +# this program; if not, write to the Free Software Foundation, Inc., 51
> +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> +
> +TEST_DESC="Perf counters"
> +
> +CURDIR=$(dirname $0)/
> +TESTDIR=$CURDIR/..
> +LTTNG_BIN="lttng"
> +SESSION_NAME="perf_counters"
> +NUM_TESTS=20
> +NR_ITER=1
> +NR_USEC_WAIT=1
> +TESTAPP_PATH="$TESTDIR/utils/testapp"
> +TESTAPP_NAME="gen-ust-events"
> +TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
> +
> +source $TESTDIR/utils/utils.sh
> +
> +function enable_ust_lttng_event_per_chan()
> +{
> +       sess_name="$1"
> +       event_name="$2"
> +       chan_name="$3"
> +
> +       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -c $chan_name -u >/dev/null 2>&1
> +       ok $? "Enable event $event_name for session $sess_name in channel $chan_name"
> +}
> +
> +function test_ust_raw()
> +{
> +       TRACE_PATH=$(mktemp -d)
> +       SESSION_NAME="ust_perf"
> +       CHAN_NAME="mychan"
> +       EVENT_NAME="tp:tptest"
> +       PMU="UNHALTED_REFERENCE_CYCLES"
> +       PERFID=$($CURDIR/find_event $PMU)
> +       test $? -eq "0"
> +       ok $? "Find PMU $PMU"
> +
> +       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
> +
> +       enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
> +
> +       enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
> +
> +       add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
> +
> +       start_lttng_tracing_ok
> +
> +       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1
> +
> +       stop_lttng_tracing_ok
> +
> +       destroy_lttng_session_ok $SESSION_NAME
> +
> +       validate_trace "perf_thread_raw_${PERFID}_test" $TRACE_PATH
> +
> +       rm -rf $TRACE_PATH
> +}
> +
> +function test_kernel_raw()
> +{
> +       TRACE_PATH=$(mktemp -d)
> +       SESSION_NAME="kernel_perf"
> +       CHAN_NAME="mychan"
> +       EVENT_NAME="lttng_test_filter_event"
> +       PMU="UNHALTED_REFERENCE_CYCLES"
> +       PERFID=$($CURDIR/find_event $PMU)
> +       test $? -eq "0"
> +       ok $? "Find PMU $PMU"
> +
> +       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
> +
> +       lttng_enable_kernel_channel_ok $SESSION_NAME $CHAN_NAME
> +
> +       enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
> +
> +       add_context_kernel_ok $SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
> +
> +       start_lttng_tracing_ok
> +
> +       echo -n 10 > /proc/lttng-test-filter-event
> +
> +       stop_lttng_tracing_ok
> +
> +       destroy_lttng_session_ok $SESSION_NAME
> +
> +       validate_trace "perf_cpu_raw_${PERFID}_test" $TRACE_PATH
> +
> +       rm -rf $TRACE_PATH
> +}
> +
> +if [ "$(id -u)" == "0" ]; then
> +       isroot=1
> +else
> +       isroot=0
> +fi
> +
> +# MUST set TESTDIR before calling those functions
> +plan_tests $NUM_TESTS
> +
> +print_test_banner "$TEST_DESC"
> +
> +start_lttng_sessiond
> +
> +test_ust_raw
> +
> +skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
> +{
> +       modprobe lttng-test
> +       test_kernel_raw
> +       rmmod lttng-test
> +}
> +
> +stop_lttng_sessiond
> diff --git a/tests/perf_regression b/tests/perf_regression
> new file mode 100644
> index 0000000..c4b9b86
> --- /dev/null
> +++ b/tests/perf_regression
> @@ -0,0 +1 @@
> +perf/test_perf_raw
> --
> 1.9.1
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-05  2:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1466623636-24179-1-git-send-email-jdesfossez@efficios.com>
2016-06-22 19:27 ` [PATCH lttng-tools v2 2/3] Test the parsing of perf raw context Julien Desfossez
2016-06-22 19:27 ` [PATCH lttng-tools v2 3/3] Create a dedicated test suite for Perf Julien Desfossez
2016-07-05  2:31 ` [PATCH lttng-tools v2 1/3] Enable perf PMU counters by raw ID Jérémie Galarneau
     [not found] ` <1466623636-24179-3-git-send-email-jdesfossez@efficios.com>
2016-07-05  2:31   ` [PATCH lttng-tools v2 3/3] Create a dedicated test suite for Perf Jérémie Galarneau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.