linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Feng Tang <feng.tang@intel.com>
To: acme@redhat.com
Cc: mingo@elte.hu, a.p.zijlstra@chello.nl, andi@firstfloor.org,
	namhyung@kernel.org, dsahern@gmail.com,
	linux-kernel@vger.kernel.org, Feng Tang <feng.tang@intel.com>
Subject: [PATCH v2 4/7] perf scripts: Export a find_scripts() function
Date: Fri,  7 Sep 2012 16:42:26 +0800	[thread overview]
Message-ID: <1347007349-3102-5-git-send-email-feng.tang@intel.com> (raw)
In-Reply-To: <1347007349-3102-1-git-send-email-feng.tang@intel.com>

So that other perf commands/browser has a way to dig out the available
scripts info in system, this is a preparation for the script browser.

Signed-off-by: Feng Tang <feng.tang@intel.com>
---
 tools/perf/builtin-script.c |   55 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h        |    1 +
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 7ab86bb..79f21d5 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1031,6 +1031,61 @@ static int list_available_scripts(const struct option *opt __used,
 	exit(0);
 }
 
+/*
+ * Return -1 if none is found, otherwise the actual scripts number.
+ *
+ * Currently the only user of this function is the script browser, which
+ * will list all statically runnable scripts, select one, execute it and
+ * show the output in a perf browser.
+ */
+int find_scripts(char **scripts_array, char **scripts_path_array)
+{
+	struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
+	char scripts_path[MAXPATHLEN];
+	DIR *scripts_dir, *lang_dir;
+	char lang_path[MAXPATHLEN];
+	char *temp;
+	int i = 0;
+
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+
+	scripts_dir = opendir(scripts_path);
+	if (!scripts_dir)
+		return -1;
+
+	for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
+		snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
+			 lang_dirent.d_name);
+#ifdef NO_LIBPERL
+		if (strstr(lang_path, "perl"))
+			continue;
+#endif
+#ifdef NO_LIBPYTHON
+		if (strstr(lang_path, "python"))
+			continue;
+#endif
+
+		lang_dir = opendir(lang_path);
+		if (!lang_dir)
+			continue;
+
+		for_each_script(lang_path, lang_dir, script_dirent, script_next) {
+			/* Skip those real time scripts: xxxtop.p[yl] */
+			if (strstr(script_dirent.d_name, "top."))
+				continue;
+			sprintf(scripts_path_array[i], "%s/%s", lang_path,
+				script_dirent.d_name);
+			temp = strchr(script_dirent.d_name, '.');
+			snprintf(scripts_array[i],
+				(temp - script_dirent.d_name) + 1,
+				"%s", script_dirent.d_name);
+			i++;
+		}
+	}
+
+	return i;
+}
+
 static char *get_script_path(const char *script_root, const char *suffix)
 {
 	struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index b382bd5..3ea74ed 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -36,4 +36,5 @@ extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 extern int cmd_test(int argc, const char **argv, const char *prefix);
 extern int cmd_inject(int argc, const char **argv, const char *prefix);
 
+extern int find_scripts(char **scripts_array, char **scripts_path_array);
 #endif
-- 
1.7.1


  parent reply	other threads:[~2012-09-07  8:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-07  8:42 [PATCH v2 0/7] perf ui/browser: Add browser for perf script Feng Tang
2012-09-07  8:42 ` [PATCH v2 1/7] perf symbols: Filter samples with unresolved symbol when "--symbols" option is used Feng Tang
2012-09-19 15:21   ` [tip:perf/core] " tip-bot for Feng Tang
2012-09-07  8:42 ` [PATCH v2 2/7] perf scripts: Add --symbols option to handle specific symbols Feng Tang
2012-09-19 15:22   ` [tip:perf/core] " tip-bot for Feng Tang
2012-09-07  8:42 ` [PATCH v2 3/7] perf scripts: Add event_analyzing_sample-record/report Feng Tang
2012-09-19 15:23   ` [tip:perf/core] perf scripts: Add event_analyzing_sample-record/ report tip-bot for Feng Tang
2012-09-07  8:42 ` Feng Tang [this message]
2012-09-19 15:24   ` [tip:perf/core] perf scripts: Export a find_scripts() function tip-bot for Feng Tang
2012-09-07  8:42 ` [PATCH v2 5/7] perf ui/browser: Add a browser for perf script Feng Tang
2012-09-07  8:42 ` [PATCH v2 6/7] perf ui/browser: Integrate script browser into annotation browser Feng Tang
2012-09-17 15:23   ` Arnaldo Carvalho de Melo
2012-09-18  7:40     ` Feng Tang
2012-09-18 11:30       ` Arnaldo Carvalho de Melo
2012-09-18 15:56         ` Feng Tang
2012-09-07  8:42 ` [PATCH v2 7/7] perf ui/browser: Integrate script browser into main hists browser Feng Tang
2012-09-10  1:35 ` [PATCH v2 0/7] perf ui/browser: Add browser for perf script Namhyung Kim

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=1347007349-3102-5-git-send-email-feng.tang@intel.com \
    --to=feng.tang@intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=dsahern@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).