Skip to content

Commit 180b206

Browse files
mhiramatacmel
authored andcommitted
perf probe: Add supported for type casting by the running kernel
Add a checking routine what types are supported by the running kernel by finding the pattern in <debugfs>/tracing/README. Signed-off-by: Masami Hiramatsu <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Hemant Kumar <[email protected]> Cc: Naohiro Aota <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/r/147151071172.12957.3340095690753291085.stgit@devbox [ 'enum probe_type' has no negative entries, so ends up as 'unsigned', remove '< 0' test to fix the build on at least centos:5, debian:7 & ubuntu:12.04.5 ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 8642562 commit 180b206

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

tools/perf/util/probe-file.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,60 @@ int probe_cache__show_all_caches(struct strfilter *filter)
877877

878878
return 0;
879879
}
880+
881+
static struct {
882+
const char *pattern;
883+
bool avail;
884+
bool checked;
885+
} probe_type_table[] = {
886+
#define DEFINE_TYPE(idx, pat, def_avail) \
887+
[idx] = {.pattern = pat, .avail = (def_avail)}
888+
DEFINE_TYPE(PROBE_TYPE_U, "* u8/16/32/64,*", true),
889+
DEFINE_TYPE(PROBE_TYPE_S, "* s8/16/32/64,*", true),
890+
DEFINE_TYPE(PROBE_TYPE_X, "* x8/16/32/64,*", false),
891+
DEFINE_TYPE(PROBE_TYPE_STRING, "* string,*", true),
892+
DEFINE_TYPE(PROBE_TYPE_BITFIELD,
893+
"* b<bit-width>@<bit-offset>/<container-size>", true),
894+
};
895+
896+
bool probe_type_is_available(enum probe_type type)
897+
{
898+
FILE *fp;
899+
char *buf = NULL;
900+
size_t len = 0;
901+
bool target_line = false;
902+
bool ret = probe_type_table[type].avail;
903+
904+
if (type >= PROBE_TYPE_END)
905+
return false;
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+
910+
if (asprintf(&buf, "%s/README", tracing_path) < 0)
911+
return ret;
912+
913+
fp = fopen(buf, "r");
914+
if (!fp)
915+
goto end;
916+
917+
zfree(&buf);
918+
while (getline(&buf, &len, fp) > 0 && !ret) {
919+
if (!target_line) {
920+
target_line = !!strstr(buf, " type: ");
921+
if (!target_line)
922+
continue;
923+
} else if (strstr(buf, "\t ") != buf)
924+
break;
925+
ret = strglobmatch(buf, probe_type_table[type].pattern);
926+
}
927+
/* Cache the result */
928+
probe_type_table[type].checked = true;
929+
probe_type_table[type].avail = ret;
930+
931+
fclose(fp);
932+
end:
933+
free(buf);
934+
935+
return ret;
936+
}

tools/perf/util/probe-file.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ struct probe_cache {
1919
struct list_head entries;
2020
};
2121

22+
enum probe_type {
23+
PROBE_TYPE_U = 0,
24+
PROBE_TYPE_S,
25+
PROBE_TYPE_X,
26+
PROBE_TYPE_STRING,
27+
PROBE_TYPE_BITFIELD,
28+
PROBE_TYPE_END,
29+
};
30+
2231
#define PF_FL_UPROBE 1
2332
#define PF_FL_RW 2
2433
#define for_each_probe_cache_entry(entry, pcache) \
@@ -54,6 +63,7 @@ struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
5463
struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
5564
const char *group, const char *event);
5665
int probe_cache__show_all_caches(struct strfilter *filter);
66+
bool probe_type_is_available(enum probe_type type);
5767
#else /* ! HAVE_LIBELF_SUPPORT */
5868
static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused)
5969
{

tools/perf/util/probe-finder.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "util.h"
4040
#include "symbol.h"
4141
#include "probe-finder.h"
42+
#include "probe-file.h"
4243

4344
/* Kprobe tracer basic type is up to u64 */
4445
#define MAX_BASIC_TYPE_BITS 64

0 commit comments

Comments
 (0)