mirror of https://gitee.com/openkylin/linux.git
perf probe: Factor out the ftrace README scanning
Simplify and separate out the ftrace README scanning logic into a separate helper. This is used subsequently to scan for all patterns of interest and to cache the result. Since we are only interested in availability of probe argument type x, we will only scan for that. Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: linuxppc-dev@lists.ozlabs.org Link: http://lkml.kernel.org/r/6dc30edc747ba82a236593be6cf3a046fa9453b5.1488961018.git.naveen.n.rao@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
292c4a8f98
commit
3da3ea7a8e
|
@ -877,35 +877,31 @@ int probe_cache__show_all_caches(struct strfilter *filter)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ftrace_readme {
|
||||||
|
FTRACE_README_PROBE_TYPE_X = 0,
|
||||||
|
FTRACE_README_END,
|
||||||
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
const char *pattern;
|
const char *pattern;
|
||||||
bool avail;
|
bool avail;
|
||||||
bool checked;
|
} ftrace_readme_table[] = {
|
||||||
} probe_type_table[] = {
|
#define DEFINE_TYPE(idx, pat) \
|
||||||
#define DEFINE_TYPE(idx, pat, def_avail) \
|
[idx] = {.pattern = pat, .avail = false}
|
||||||
[idx] = {.pattern = pat, .avail = (def_avail)}
|
DEFINE_TYPE(FTRACE_README_PROBE_TYPE_X, "*type: * x8/16/32/64,*"),
|
||||||
DEFINE_TYPE(PROBE_TYPE_U, "* u8/16/32/64,*", true),
|
|
||||||
DEFINE_TYPE(PROBE_TYPE_S, "* s8/16/32/64,*", true),
|
|
||||||
DEFINE_TYPE(PROBE_TYPE_X, "* x8/16/32/64,*", false),
|
|
||||||
DEFINE_TYPE(PROBE_TYPE_STRING, "* string,*", true),
|
|
||||||
DEFINE_TYPE(PROBE_TYPE_BITFIELD,
|
|
||||||
"* b<bit-width>@<bit-offset>/<container-size>", true),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool probe_type_is_available(enum probe_type type)
|
static bool scan_ftrace_readme(enum ftrace_readme type)
|
||||||
{
|
{
|
||||||
|
int fd;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
bool target_line = false;
|
bool ret = false;
|
||||||
bool ret = probe_type_table[type].avail;
|
static bool scanned = false;
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (type >= PROBE_TYPE_END)
|
if (scanned)
|
||||||
return false;
|
goto result;
|
||||||
/* We don't have to check the type which supported by default */
|
|
||||||
if (ret || probe_type_table[type].checked)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
fd = open_trace_file("README", false);
|
fd = open_trace_file("README", false);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -917,21 +913,29 @@ bool probe_type_is_available(enum probe_type type)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (getline(&buf, &len, fp) > 0 && !ret) {
|
while (getline(&buf, &len, fp) > 0)
|
||||||
if (!target_line) {
|
for (enum ftrace_readme i = 0; i < FTRACE_README_END; i++)
|
||||||
target_line = !!strstr(buf, " type: ");
|
if (!ftrace_readme_table[i].avail)
|
||||||
if (!target_line)
|
ftrace_readme_table[i].avail =
|
||||||
continue;
|
strglobmatch(buf, ftrace_readme_table[i].pattern);
|
||||||
} else if (strstr(buf, "\t ") != buf)
|
scanned = true;
|
||||||
break;
|
|
||||||
ret = strglobmatch(buf, probe_type_table[type].pattern);
|
|
||||||
}
|
|
||||||
/* Cache the result */
|
|
||||||
probe_type_table[type].checked = true;
|
|
||||||
probe_type_table[type].avail = ret;
|
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
return ret;
|
result:
|
||||||
|
if (type >= FTRACE_README_END)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return ftrace_readme_table[type].avail;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool probe_type_is_available(enum probe_type type)
|
||||||
|
{
|
||||||
|
if (type >= PROBE_TYPE_END)
|
||||||
|
return false;
|
||||||
|
else if (type == PROBE_TYPE_X)
|
||||||
|
return scan_ftrace_readme(FTRACE_README_PROBE_TYPE_X);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue