Provide a small tool which translates an event string + modifiers to a raw
event code for use with the perf tool.

This example is very simple and takes a single event string as an argument.

Signed-off-by: Corey Ashford <cjash...@us.ibm.com>
---
 perf_examples/Makefile  |    2 +-
 perf_examples/evt2raw.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 1 deletions(-)
 create mode 100644 perf_examples/evt2raw.c

diff --git a/perf_examples/Makefile b/perf_examples/Makefile
index 1d353d4..8ebb290 100644
--- a/perf_examples/Makefile
+++ b/perf_examples/Makefile
@@ -55,7 +55,7 @@ ifeq ($(SYS),Linux)
 LPC_UTILS=perf_util.o
 TARGETS+=self self_basic self_count task task_attach_timeout syst \
        notify_self notify_group task_smpl self_smpl_multi \
-       self_pipe syst_count task_cpu syst_smpl
+       self_pipe syst_count task_cpu syst_smpl evt2raw
 
 #XTRA += rtop
 endif
diff --git a/perf_examples/evt2raw.c b/perf_examples/evt2raw.c
new file mode 100644
index 0000000..917420f
--- /dev/null
+++ b/perf_examples/evt2raw.c
@@ -0,0 +1,74 @@
+/*
+ * evt2raw.c - example which converts an event string (event + modifiers) to
+ * a raw event code usable by the perf tool.
+ *
+ * Copyright (c) 2010 IBM Corp.
+ * Contributed by Corey Ashford <cjash...@us.ibm.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies
+ * of the Software, and to permit persons to whom the Software is furnished to 
do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in 
all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR 
A
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <perfmon/pfmlib_perf_event.h>
+
+static void
+usage(void)
+{
+       printf("usage: evt2raw <event>\n"
+               "<event> is the symbolic event, including modifiers, to "
+               "translate to a raw code.\n");
+}
+
+int
+main(int argc, char **argv)
+{
+       int ret;
+       struct perf_event_attr pea;
+       char *event_str;
+
+       if (argc != 2) {
+               usage();
+               return 1;
+       }
+       event_str = argv[1];
+
+       ret = pfm_initialize();
+       if (ret != PFM_SUCCESS) {
+               printf("Internal error: pfm_initialize returned %s\n",
+                       pfm_strerror(ret));
+               return 1;
+       }
+
+       ret = pfm_get_perf_event_encoding(event_str, PFM_PLM0|PFM_PLM3, &pea,
+               NULL, NULL);
+       if (ret != PFM_SUCCESS) {
+               printf("Error: pfm_get_perf_encoding returned %s\n",
+                       pfm_strerror(ret));
+               return 1;
+       }
+
+       if (pea.type != PERF_TYPE_RAW) {
+               printf("Error: %s is not a raw hardware event\n", event_str);
+               return 1;
+       }
+
+       printf("r%llx\n", pea.config);
+
+       return 0;
+}
-- 
1.7.0.4


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
perfmon2-devel mailing list
perfmon2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perfmon2-devel

Reply via email to