Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 323838
b: refs/heads/master
c: e5f3705
h: refs/heads/master
v: v3
  • Loading branch information
Feng Tang authored and Arnaldo Carvalho de Melo committed Sep 17, 2012
1 parent cbab968 commit e738095
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 59cbea229473350168930941986ebe5bf685cc23
refs/heads/master: e5f3705e62b03251797a5173024184bfc223599d
55 changes: 55 additions & 0 deletions trunk/tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions trunk/tools/perf/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e738095

Please sign in to comment.