Skip to content

Commit 9254378

Browse files
mhiramatacmel
authored andcommitted
perf probe: Support hexadecimal casting
Support hexadecimal unsigned integer casting by 'x'. This allows user to explicitly specify the output format of the probe arguments as hexadecimal. 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/147151072679.12957.4458656416765710753.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 180b206 commit 9254378

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

tools/perf/Documentation/perf-probe.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ Each probe argument follows below syntax.
176176

177177
'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
178178
'$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
179-
'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
179+
'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x/x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
180180

181181
On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
182182

183183
TYPES
184184
-----
185-
Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
185+
Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. Moreover, you can use 'x' to explicitly specify to be shown in hexadecimal (the size is also auto-detected).
186186
String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
187187
Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
188188

tools/perf/util/probe-finder.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,
298298
char sbuf[STRERR_BUFSIZE];
299299
int bsize, boffs, total;
300300
int ret;
301-
char sign;
301+
char prefix;
302302

303303
/* TODO: check all types */
304-
if (cast && strcmp(cast, "string") != 0 &&
304+
if (cast && strcmp(cast, "string") != 0 && strcmp(cast, "x") != 0 &&
305305
strcmp(cast, "s") != 0 && strcmp(cast, "u") != 0) {
306306
/* Non string type is OK */
307-
/* and respect signedness cast */
307+
/* and respect signedness/hexadecimal cast */
308308
tvar->type = strdup(cast);
309309
return (tvar->type == NULL) ? -ENOMEM : 0;
310310
}
@@ -366,11 +366,14 @@ static int convert_variable_type(Dwarf_Die *vr_die,
366366
}
367367

368368
if (cast && (strcmp(cast, "u") == 0))
369-
sign = 'u';
369+
prefix = 'u';
370370
else if (cast && (strcmp(cast, "s") == 0))
371-
sign = 's';
371+
prefix = 's';
372+
else if (cast && (strcmp(cast, "x") == 0) &&
373+
probe_type_is_available(PROBE_TYPE_X))
374+
prefix = 'x';
372375
else
373-
sign = die_is_signed_type(&type) ? 's' : 'u';
376+
prefix = die_is_signed_type(&type) ? 's' : 'u';
374377

375378
ret = dwarf_bytesize(&type);
376379
if (ret <= 0)
@@ -384,7 +387,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
384387
dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
385388
ret = MAX_BASIC_TYPE_BITS;
386389
}
387-
ret = snprintf(buf, 16, "%c%d", sign, ret);
390+
ret = snprintf(buf, 16, "%c%d", prefix, ret);
388391

389392
formatted:
390393
if (ret < 0 || ret >= 16) {

0 commit comments

Comments
 (0)