Make default formulas appear in 'perf list' command output
with [Formula counter].

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Ulrich Drepper <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Stephane Eranian <[email protected]>
---
 tools/perf/builtin-list.c      |  3 +++
 tools/perf/util/formula.c      | 34 ++++++++++++++++++++++++++++++++++
 tools/perf/util/formula.h      |  2 ++
 tools/perf/util/parse-events.c |  3 +++
 4 files changed, 42 insertions(+)

diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 1948ece..71e6d1f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -13,6 +13,7 @@
 
 #include "util/parse-events.h"
 #include "util/cache.h"
+#include "util/formula.h"
 
 int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 {
@@ -37,6 +38,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
                        else if (strcmp(argv[i], "cache") == 0 ||
                                 strcmp(argv[i], "hwcache") == 0)
                                print_hwcache_events(NULL, false);
+                       else if (strcmp(argv[i], "formulas") == 0)
+                               print_formulas();
                        else if (strcmp(argv[i], "--raw-dump") == 0)
                                print_events(NULL, true);
                        else {
diff --git a/tools/perf/util/formula.c b/tools/perf/util/formula.c
index b9d95b2..71ae117 100644
--- a/tools/perf/util/formula.c
+++ b/tools/perf/util/formula.c
@@ -564,3 +564,37 @@ int perf_formula__preload(struct perf_formula *f)
 
        return ret ? ret : perf_formula__preload_arch(f);
 }
+
+static int print_set_cb(struct perf_formula_set *set, void *data)
+{
+       bool *printed = (bool *) data;
+       char name[100];
+
+       scnprintf(name, 100, "formula-%s", set->name);
+       printf("  %-50s [Formula counter]\n", name);
+
+       if (!*printed)
+               *printed = true;
+
+       return CB_NEXT;
+}
+
+void print_formulas(void)
+{
+       struct perf_formula f;
+       bool printed = false;
+
+       perf_formula__init(&f);
+
+       if (perf_formula__preload(&f)) {
+               pr_err("formula: failed to preload formulas\n");
+               return;
+       }
+
+       printf("\n");
+
+       for_each_set(&f, print_set_cb, &printed);
+
+       if (printed)
+               printf("\n");
+}
diff --git a/tools/perf/util/formula.h b/tools/perf/util/formula.h
index b6437d8..5288bc6 100644
--- a/tools/perf/util/formula.h
+++ b/tools/perf/util/formula.h
@@ -137,4 +137,6 @@ double perf_formula_expr__resolve(struct perf_formula_expr 
*expr,
 
 int perf_formula__preload(struct perf_formula *f);
 int perf_formula__preload_arch(struct perf_formula *f);
+
+void print_formulas(void);
 #endif /* __PERF_FORMULA */
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index fe0a554..405f192 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -15,6 +15,7 @@
 #define YY_EXTRA_TYPE int
 #include "parse-events-flex.h"
 #include "pmu.h"
+#include "formula.h"
 
 #define MAX_NAME_LEN 100
 
@@ -1133,6 +1134,8 @@ void print_events(const char *event_glob, bool name_only)
 
        print_hwcache_events(event_glob, name_only);
 
+       print_formulas();
+
        if (event_glob != NULL)
                return;
 
-- 
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to