aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>2017-03-08 03:26:08 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-03-14 14:17:38 -0400
commit3da3ea7a8e205edc24b9491a459b46527c70b5b1 (patch)
treefb90ea7b0eea010c27ca1407bd044020272ff553 /tools/perf
parent292c4a8f985b35b3738d5900fe256c4fed4cd3f5 (diff)
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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/probe-file.c70
1 files changed, 37 insertions, 33 deletions
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 1a62daceb028..8a219cd831b7 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -877,35 +877,31 @@ int probe_cache__show_all_caches(struct strfilter *filter)
877 return 0; 877 return 0;
878} 878}
879 879
880enum ftrace_readme {
881 FTRACE_README_PROBE_TYPE_X = 0,
882 FTRACE_README_END,
883};
884
880static struct { 885static struct {
881 const char *pattern; 886 const char *pattern;
882 bool avail; 887 bool avail;
883 bool checked; 888} ftrace_readme_table[] = {
884} probe_type_table[] = { 889#define DEFINE_TYPE(idx, pat) \
885#define DEFINE_TYPE(idx, pat, def_avail) \ 890 [idx] = {.pattern = pat, .avail = false}
886 [idx] = {.pattern = pat, .avail = (def_avail)} 891 DEFINE_TYPE(FTRACE_README_PROBE_TYPE_X, "*type: * x8/16/32/64,*"),
887 DEFINE_TYPE(PROBE_TYPE_U, "* u8/16/32/64,*", true),
888 DEFINE_TYPE(PROBE_TYPE_S, "* s8/16/32/64,*", true),
889 DEFINE_TYPE(PROBE_TYPE_X, "* x8/16/32/64,*", false),
890 DEFINE_TYPE(PROBE_TYPE_STRING, "* string,*", true),
891 DEFINE_TYPE(PROBE_TYPE_BITFIELD,
892 "* b<bit-width>@<bit-offset>/<container-size>", true),
893}; 892};
894 893
895bool probe_type_is_available(enum probe_type type) 894static bool scan_ftrace_readme(enum ftrace_readme type)
896{ 895{
896 int fd;
897 FILE *fp; 897 FILE *fp;
898 char *buf = NULL; 898 char *buf = NULL;
899 size_t len = 0; 899 size_t len = 0;
900 bool target_line = false; 900 bool ret = false;
901 bool ret = probe_type_table[type].avail; 901 static bool scanned = false;
902 int fd;
903 902
904 if (type >= PROBE_TYPE_END) 903 if (scanned)
905 return false; 904 goto result;
906 /* We don't have to check the type which supported by default */
907 if (ret || probe_type_table[type].checked)
908 return ret;
909 905
910 fd = open_trace_file("README", false); 906 fd = open_trace_file("README", false);
911 if (fd < 0) 907 if (fd < 0)
@@ -917,21 +913,29 @@ bool probe_type_is_available(enum probe_type type)
917 return ret; 913 return ret;
918 } 914 }
919 915
920 while (getline(&buf, &len, fp) > 0 && !ret) { 916 while (getline(&buf, &len, fp) > 0)
921 if (!target_line) { 917 for (enum ftrace_readme i = 0; i < FTRACE_README_END; i++)
922 target_line = !!strstr(buf, " type: "); 918 if (!ftrace_readme_table[i].avail)
923 if (!target_line) 919 ftrace_readme_table[i].avail =
924 continue; 920 strglobmatch(buf, ftrace_readme_table[i].pattern);
925 } else if (strstr(buf, "\t ") != buf) 921 scanned = true;
926 break;
927 ret = strglobmatch(buf, probe_type_table[type].pattern);
928 }
929 /* Cache the result */
930 probe_type_table[type].checked = true;
931 probe_type_table[type].avail = ret;
932 922
933 fclose(fp); 923 fclose(fp);
934 free(buf); 924 free(buf);
935 925
936 return ret; 926result:
927 if (type >= FTRACE_README_END)
928 return false;
929
930 return ftrace_readme_table[type].avail;
931}
932
933bool probe_type_is_available(enum probe_type type)
934{
935 if (type >= PROBE_TYPE_END)
936 return false;
937 else if (type == PROBE_TYPE_X)
938 return scan_ftrace_readme(FTRACE_README_PROBE_TYPE_X);
939
940 return true;
937} 941}