mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Andi Kleen <andi@firstfloor.org>, David Ahern <dsahern@gmail.com>,
	Ulrich Drepper <drepper@gmail.com>,
	Will Deacon <will.deacon@arm.com>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 5/8] perf tools: Add support to preload default formulas
Date: Wed,  1 May 2013 17:15:43 +0200	[thread overview]
Message-ID: <1367421346-18257-6-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1367421346-18257-1-git-send-email-jolsa@redhat.com>

Adding support to read all formula definition files
under common locations:

  'formula'
    - under perf developement tree
  'PREFIX/PERF_EXEC_PATH/formulas'
    - when installed

Plus adding very basic formula definitions for CPI
and branch related counters.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ulrich Drepper <drepper@gmail.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Stephane Eranian <eranian@google.com>
---
 tools/perf/Makefile              |  8 ++++++
 tools/perf/formulas/default.conf | 26 ++++++++++++++++++++
 tools/perf/util/formula.c        | 53 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/formula.h        |  3 +++
 4 files changed, 90 insertions(+)
 create mode 100644 tools/perf/formulas/default.conf

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index bcbc524..c35bb7f 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -1010,6 +1010,12 @@ $(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS
 		'-DPREFIX="$(prefix_SQ)"' \
 		$<
 
+$(OUTPUT)util/formula.o: util/formula.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
+		'-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \
+		'-DPREFIX="$(prefix_SQ)"' \
+		$<
+
 $(OUTPUT)tests/attr.o: tests/attr.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
 		'-DBINDIR="$(bindir_SQ)"' -DPYTHON='"$(PYTHON_WORD)"' \
@@ -1201,6 +1207,8 @@ install-bin: all
 	$(INSTALL) tests/attr.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'
 	$(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/formulas'
+	$(INSTALL) -m 644 formulas/* $(DESTDIR_SQ)$(perfexec_instdir_SQ)/formulas
 
 install: install-bin try-install-man
 
diff --git a/tools/perf/formulas/default.conf b/tools/perf/formulas/default.conf
new file mode 100644
index 0000000..56712d6
--- /dev/null
+++ b/tools/perf/formulas/default.conf
@@ -0,0 +1,26 @@
+cpi {
+	events {
+		CY = cycles:u
+		IN = instructions:u
+	}
+
+	cpi = CY / IN
+
+	print cpi
+}
+
+branch {
+	events {
+		IN = instructions:u
+		BI = branch-instructions:u
+		BM = branch-misses:u
+	}
+
+	branch-rate       = BI / IN
+	branch-miss-rate  = BM / IN
+	branch-miss-ratio = BM / BI
+
+	print branch-rate
+	print branch-miss-rate
+	print branch-miss-ratio
+}
diff --git a/tools/perf/util/formula.c b/tools/perf/util/formula.c
index 2edc720..b9d95b2 100644
--- a/tools/perf/util/formula.c
+++ b/tools/perf/util/formula.c
@@ -159,6 +159,35 @@ int perf_formula__load(struct perf_formula *f, char *path)
 	return ret;
 }
 
+int perf_formula__load_dir(struct perf_formula *f, char *path)
+{
+	struct dirent *ent;
+	DIR *dir;
+	int ret = 0;
+
+	dir = opendir(path);
+	if (!dir) {
+		pr_err("formula: can't open dir '%s' - %s\n",
+		       path, strerror(errno));
+		return -1;
+	}
+
+	while (!ret && (ent = readdir(dir))) {
+		char file[PATH_MAX];
+
+		if (!strcmp(ent->d_name, ".") ||
+		    !strcmp(ent->d_name, ".."))
+			continue;
+
+		scnprintf(file, PATH_MAX, "%s/%s", path, ent->d_name);
+
+		ret = perf_formula__load(f, file);
+	}
+
+	closedir(dir);
+	return ret;
+}
+
 int perf_formula__free(struct perf_formula *f)
 {
 	struct perf_formula_file *file;
@@ -511,3 +540,27 @@ double perf_formula_expr__resolve(struct perf_formula_expr *expr,
 	pr_debug2("formula resolve %s = %F\n", name, result);
 	return result;
 }
+
+
+__attribute__((weak))
+int perf_formula__preload_arch(struct perf_formula *f __maybe_unused)
+{
+	return 0;
+}
+
+int perf_formula__preload(struct perf_formula *f)
+{
+	struct stat st;
+	int ret = 0;
+
+	if (!lstat("./formulas", &st))
+		ret = perf_formula__load_dir(f, (char *) "./formulas");
+	else {
+		char path[PATH_MAX];
+
+		scnprintf(path, PATH_MAX, "%s/%s/formulas/", PREFIX, PERF_EXEC_PATH);
+		ret = perf_formula__load_dir(f, path);
+	}
+
+	return ret ? ret : perf_formula__preload_arch(f);
+}
diff --git a/tools/perf/util/formula.h b/tools/perf/util/formula.h
index 90325ec..b6437d8 100644
--- a/tools/perf/util/formula.h
+++ b/tools/perf/util/formula.h
@@ -106,6 +106,7 @@ struct perf_formula_config {
 void perf_formula__init(struct perf_formula *f);
 
 int perf_formula__load(struct perf_formula *f, char *path);
+int perf_formula__load_dir(struct perf_formula *f, char *path);
 int perf_formula__free(struct perf_formula *f);
 
 struct perf_formula_set*
@@ -134,4 +135,6 @@ perf_formula_set__new(char *name, struct list_head *head);
 double perf_formula_expr__resolve(struct perf_formula_expr *expr,
 				  char *name);
 
+int perf_formula__preload(struct perf_formula *f);
+int perf_formula__preload_arch(struct perf_formula *f);
 #endif /* __PERF_FORMULA */
-- 
1.7.11.7


  parent reply	other threads:[~2013-05-01 15:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-01 15:15 [RFCv2 0/8] perf tools: Adding formula support Jiri Olsa
2013-05-01 15:15 ` [PATCH 1/8] perf tools: Move start conditions to start of the flex file Jiri Olsa
2013-05-01 15:15 ` [PATCH 2/8] perf tools: Factorize event parsing to be more general Jiri Olsa
2013-05-01 15:15 ` [PATCH 3/8] perf tools: Add formula-* parsing support for events Jiri Olsa
2013-05-03 15:07   ` David Ahern
2013-05-06 17:47     ` Jiri Olsa
2013-05-01 15:15 ` [PATCH 4/8] perf tools: Add formula interface to interface formula definitions Jiri Olsa
2013-05-15  9:13   ` Peter Zijlstra
2013-05-01 15:15 ` Jiri Olsa [this message]
2013-05-03 15:11   ` [PATCH 5/8] perf tools: Add support to preload default formulas David Ahern
2013-05-06 17:48     ` Jiri Olsa
2013-05-01 15:15 ` [PATCH 6/8] perf tests: Add automated tests for formula object Jiri Olsa
2013-05-03 15:18   ` David Ahern
2013-05-06 17:54     ` Jiri Olsa
2013-05-06 18:08       ` David Ahern
2013-05-01 15:15 ` [PATCH 7/8] perf stat: Add support to process formulas Jiri Olsa
2013-05-01 15:15 ` [PATCH 8/8] perf list: List formulas counters Jiri Olsa
2013-05-06 17:44 ` [RFCv2 0/8] perf tools: Adding formula support Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1367421346-18257-6-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=drepper@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®