diff options
author | Feng Tang <feng.tang@intel.com> | 2012-09-07 04:42:26 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-17 12:11:26 -0400 |
commit | e5f3705e62b03251797a5173024184bfc223599d (patch) | |
tree | 0063204a6feb32eb63e5f06e5444ef6af0d6fbd0 | |
parent | 59cbea229473350168930941986ebe5bf685cc23 (diff) |
perf scripts: Export a find_scripts() function
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>
-rw-r--r-- | tools/perf/builtin-script.c | 55 | ||||
-rw-r--r-- | 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 76577e67c3b3..1be843aa1546 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -1032,6 +1032,61 @@ static int list_available_scripts(const struct option *opt __maybe_unused, | |||
1032 | exit(0); | 1032 | exit(0); |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | /* | ||
1036 | * Return -1 if none is found, otherwise the actual scripts number. | ||
1037 | * | ||
1038 | * Currently the only user of this function is the script browser, which | ||
1039 | * will list all statically runnable scripts, select one, execute it and | ||
1040 | * show the output in a perf browser. | ||
1041 | */ | ||
1042 | int find_scripts(char **scripts_array, char **scripts_path_array) | ||
1043 | { | ||
1044 | struct dirent *script_next, *lang_next, script_dirent, lang_dirent; | ||
1045 | char scripts_path[MAXPATHLEN]; | ||
1046 | DIR *scripts_dir, *lang_dir; | ||
1047 | char lang_path[MAXPATHLEN]; | ||
1048 | char *temp; | ||
1049 | int i = 0; | ||
1050 | |||
1051 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path()); | ||
1052 | |||
1053 | scripts_dir = opendir(scripts_path); | ||
1054 | if (!scripts_dir) | ||
1055 | return -1; | ||
1056 | |||
1057 | for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { | ||
1058 | snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, | ||
1059 | lang_dirent.d_name); | ||
1060 | #ifdef NO_LIBPERL | ||
1061 | if (strstr(lang_path, "perl")) | ||
1062 | continue; | ||
1063 | #endif | ||
1064 | #ifdef NO_LIBPYTHON | ||
1065 | if (strstr(lang_path, "python")) | ||
1066 | continue; | ||
1067 | #endif | ||
1068 | |||
1069 | lang_dir = opendir(lang_path); | ||
1070 | if (!lang_dir) | ||
1071 | continue; | ||
1072 | |||
1073 | for_each_script(lang_path, lang_dir, script_dirent, script_next) { | ||
1074 | /* Skip those real time scripts: xxxtop.p[yl] */ | ||
1075 | if (strstr(script_dirent.d_name, "top.")) | ||
1076 | continue; | ||
1077 | sprintf(scripts_path_array[i], "%s/%s", lang_path, | ||
1078 | script_dirent.d_name); | ||
1079 | temp = strchr(script_dirent.d_name, '.'); | ||
1080 | snprintf(scripts_array[i], | ||
1081 | (temp - script_dirent.d_name) + 1, | ||
1082 | "%s", script_dirent.d_name); | ||
1083 | i++; | ||
1084 | } | ||
1085 | } | ||
1086 | |||
1087 | return i; | ||
1088 | } | ||
1089 | |||
1035 | static char *get_script_path(const char *script_root, const char *suffix) | 1090 | static char *get_script_path(const char *script_root, const char *suffix) |
1036 | { | 1091 | { |
1037 | struct dirent *script_next, *lang_next, script_dirent, lang_dirent; | 1092 | struct dirent *script_next, *lang_next, script_dirent, lang_dirent; |
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index b382bd551aac..3ea74ed1b26b 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); | |||
36 | extern int cmd_test(int argc, const char **argv, const char *prefix); | 36 | extern int cmd_test(int argc, const char **argv, const char *prefix); |
37 | extern int cmd_inject(int argc, const char **argv, const char *prefix); | 37 | extern int cmd_inject(int argc, const char **argv, const char *prefix); |
38 | 38 | ||
39 | extern int find_scripts(char **scripts_array, char **scripts_path_array); | ||
39 | #endif | 40 | #endif |