lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 15 Jan 2013 14:39:53 +0100
From:	Jiri Olsa <jolsa@...hat.com>
To:	linux-kernel@...r.kernel.org
Cc:	Jiri Olsa <jolsa@...hat.com>,
	Arnaldo Carvalho de Melo <acme@...hat.com>,
	Namhyung Kim <namhyung@...nel.org>,
	Corey Ashford <cjashfor@...ux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Ingo Molnar <mingo@...e.hu>, Paul Mackerras <paulus@...ba.org>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Andi Kleen <andi@...stfloor.org>,
	David Ahern <dsahern@...il.com>,
	Ulrich Drepper <drepper@...il.com>
Subject: [PATCH 3/4] perf stat: Adding -f option to load and process ratios

Adding -f option to specify the formula definition to use.
Its value needs to be specified in following form:
  'file:set'

where 'file' is the formula definition file and the 'set'
is the name of the set to use for output.

With following formula.conf config file:
---
  cpi {
          events = {cycles,instructions}:u

          CPI {
                  formula = cycles / instructions
                  desc = cycles per instruction
          }
  }

  branch {
          events = {instructions,branch-instructions,branch-misses}:u

          branch-rate {
                  formula = branch-instructions / instructions
                  desc = branch rate
          }

          branch-miss-rate {
                  formula = branch-misses / instructions
                  desc = branch misprediction rate
          }

          branch-miss-ratio{
                  formula = branch-misses / branch-instructions
                  desc = branch misprediction ratio
          }
  }
---

You'll get following result:

  $ perf stat -f formula.conf:branch kill
  usage: kill [ -s signal | -p ] [ -a ] pid ...
         kill -l [ signal ]

   Performance counter stats for 'kill':

             184,195 instructions              #    0.00  insns per cycle
              40,907 branch-instructions
               4,815 branch-misses             #   11.77% of all branches

         0.000655767 seconds time elapsed

          0.22208529 branch-rate               #  branch rate
          0.02614077 branch-miss-rate          #  branch misprediction rate
          0.11770602 branch-miss-ratio         #  branch misprediction ratio

  $ perf stat -f formula.conf:cpi kill
  usage: kill [ -s signal | -p ] [ -a ] pid ...
         kill -l [ signal ]

   Performance counter stats for 'kill':

             356,635 cycles                    #    0.000 GHz
             187,191 instructions              #    0.52  insns per cycle

         0.001907600 seconds time elapsed

          1.90519309 CPI                       #  cycles per instruction

Signed-off-by: Jiri Olsa <jolsa@...hat.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Corey Ashford <cjashfor@...ux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Ingo Molnar <mingo@...e.hu>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Andi Kleen <andi@...stfloor.org>
Cc: David Ahern <dsahern@...il.com>
Cc: Ulrich Drepper <drepper@...il.com>
---
 tools/perf/builtin-stat.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 1c2ac14..06f79e5 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -56,6 +56,7 @@
 #include "util/cpumap.h"
 #include "util/thread.h"
 #include "util/thread_map.h"
+#include "util/formula.h"
 
 #include <stdlib.h>
 #include <sys/prctl.h>
@@ -67,6 +68,9 @@
 
 static struct perf_evlist	*evsel_list;
 
+static struct perf_formula	 formula;
+static struct perf_formula__set	*formula_set;
+
 static struct perf_target	target = {
 	.uid	= UINT_MAX,
 };
@@ -1065,6 +1069,42 @@ static int add_default_attributes(void)
 	return perf_evlist__add_default_attrs(evsel_list, very_very_detailed_attrs);
 }
 
+static int formula_option(const struct option *opt __maybe_unused,
+			  const char *str, int unset __maybe_unused)
+{
+	char *name;
+
+	if (no_aggr) {
+		pr_err("failed to run formulas with no aggr mode\n");
+		return -1;
+	}
+
+	name = strrchr(str, ':');
+	if (!name) {
+		pr_err("need to specify set name\n");
+		return -1;
+	}
+
+	*name++ = 0x0;
+
+	pr_debug("formula file '%s', name '%s'\n", str, name);
+
+	perf_formula__init(&formula);
+
+	if (perf_formula__load(&formula, (char *) str)) {
+		pr_err("failed to load formula file '%s'\n", str);
+		return -1;
+	}
+
+	formula_set = perf_formula__set(&formula, name);
+	if (!formula_set) {
+		pr_err("failed to find formula counter '%s'\n", name);
+		return -1;
+	}
+
+	return 0;
+}
+
 int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	bool append_file = false;
@@ -1076,6 +1116,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		     parse_events_option),
 	OPT_CALLBACK(0, "filter", &evsel_list, "filter",
 		     "event filter", parse_filter),
+	OPT_CALLBACK('f', "formula", NULL, "formula",
+		     "counters formula, file[:name]",
+		     formula_option),
 	OPT_BOOLEAN('i', "no-inherit", &no_inherit,
 		    "child tasks do not inherit counters"),
 	OPT_STRING('p', "pid", &target.pid, "pid",
@@ -1134,6 +1177,12 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	argc = parse_options(argc, argv, options, stat_usage,
 		PARSE_OPT_STOP_AT_NON_OPTION);
 
+	if (formula_set &&
+	    perf_formula__evlist(formula_set, evsel_list)) {
+		fprintf(stderr, "failed to load formula events\n");
+		usage_with_options(stat_usage, options);
+	}
+
 	output = stderr;
 	if (output_name && strcmp(output_name, "-"))
 		output = NULL;
@@ -1242,13 +1291,23 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		status = run_perf_stat(argc, argv);
 	}
 
-	if (status != -1)
+	if (status != -1) {
 		print_stat(argc, argv);
+
+		if (formula_set)
+			perf_formula__print(output, formula_set,
+					    evsel_list, NULL);
+	}
+
 out_free_fd:
 	list_for_each_entry(pos, &evsel_list->entries, node)
 		perf_evsel__free_stat_priv(pos);
 	perf_evlist__delete_maps(evsel_list);
 out:
 	perf_evlist__delete(evsel_list);
+
+	if (formula_set)
+		perf_formula__free(&formula);
+
 	return status;
 }
-- 
1.7.11.7

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ