]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
perf scripts: Export a find_scripts() function
authorFeng Tang <feng.tang@intel.com>
Fri, 7 Sep 2012 08:42:26 +0000 (16:42 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 17 Sep 2012 16:11:26 +0000 (13:11 -0300)
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>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1347007349-3102-5-git-send-email-feng.tang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-script.c
tools/perf/builtin.h

index 76577e67c3b35a8f26f10ff83f78f9515dde6d6e..1be843aa1546ed1df603119e3cec193d04cf0673 100644 (file)
@@ -1032,6 +1032,61 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
        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;
index b382bd551aacd3d427522400fe11be1cbeb9f435..3ea74ed1b26b799620e53484dcf4e60c3bad6019 100644 (file)
@@ -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