lkml.org 
[lkml]   [2018]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 08/18] tracing: Add "unsigned" to function based events
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add "unsigned" to the format processing to creating dynamic function based
events. For example: "unsigned long" now works.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
Documentation/trace/function-based-events.rst | 47 ++++++++++++++++++++++++++-
kernel/trace/trace_event_ftrace.c | 23 ++++++++++---
2 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/Documentation/trace/function-based-events.rst b/Documentation/trace/function-based-events.rst
index 2a002c8a500b..72e3e7730d63 100644
--- a/Documentation/trace/function-based-events.rst
+++ b/Documentation/trace/function-based-events.rst
@@ -93,7 +93,7 @@ as follows:

ARG := TYPE FIELD | ARG '|' ARG

- TYPE := ATOM
+ TYPE := ATOM | 'unsigned' ATOM

ATOM := 'u8' | 'u16' | 'u32' | 'u64' |
's8' | 's16' | 's32' | 's64' |
@@ -176,3 +176,48 @@ an argument:
<idle>-0 [003] ..s3 904.075848: __netif_receive_skb_core->ip_rcv(skb=ffff88011396e800, skb=52, dev=ffff880115204000)
<idle>-0 [003] ..s3 904.725486: __netif_receive_skb_core->ip_rcv(skb=ffff88011396e800, skb=194, dev=ffff880115204000)
<idle>-0 [003] ..s3 905.152537: __netif_receive_skb_core->ip_rcv(skb=ffff88011396f200, skb=88, dev=ffff880115204000)
+
+
+Unsigned usage
+==============
+
+One can also use "unsigned" to make some types unsigned. It works against
+"long", "int", "short" and "char". It doesn't error against other types but
+may not make any sense.
+
+ # echo 'ip_rcv(int skb[32])' > function_events
+ # cat events/functions/ip_rcv/format
+name: ip_rcv
+ID: 1397
+format:
+ field:unsigned short common_type; offset:0; size:2; signed:0;
+ field:unsigned char common_flags; offset:2; size:1; signed:0;
+ field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
+ field:int common_pid; offset:4; size:4; signed:1;
+
+ field:unsigned long __parent_ip; offset:8; size:8; signed:0;
+ field:unsigned long __ip; offset:16; size:8; signed:0;
+ field:int skb; offset:24; size:4; signed:1;
+
+print fmt: "%pS->%pS(skb=%d)", REC->__ip, REC->__parent_ip, REC->skb
+
+
+Notice that REC->skb is printed with "%d". By adding "unsigned"
+
+ # echo 'ip_rcv(unsigned int skb[32])' > function_events
+ # cat events/functions/ip_rcv/format
+name: ip_rcv
+ID: 1398
+format:
+ field:unsigned short common_type; offset:0; size:2; signed:0;
+ field:unsigned char common_flags; offset:2; size:1; signed:0;
+ field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
+ field:int common_pid; offset:4; size:4; signed:1;
+
+ field:unsigned long __parent_ip; offset:8; size:8; signed:0;
+ field:unsigned long __ip; offset:16; size:8; signed:0;
+ field:unsigned int skb; offset:24; size:4; signed:0;
+
+print fmt: "%pS->%pS(skb=%u)", REC->__ip, REC->__parent_ip, REC->skb
+
+It is now printed with a "%u".
diff --git a/kernel/trace/trace_event_ftrace.c b/kernel/trace/trace_event_ftrace.c
index 8c9d4a92deab..9548b93eb8cd 100644
--- a/kernel/trace/trace_event_ftrace.c
+++ b/kernel/trace/trace_event_ftrace.c
@@ -60,6 +60,7 @@ enum func_states {
FUNC_STATE_BRACKET,
FUNC_STATE_BRACKET_END,
FUNC_STATE_INDIRECT,
+ FUNC_STATE_UNSIGNED,
FUNC_STATE_PIPE,
FUNC_STATE_TYPE,
FUNC_STATE_VAR,
@@ -198,7 +199,7 @@ static char *next_token(char **ptr, char *last)
return arg;
}

-static int add_arg(struct func_event *fevent, int ftype)
+static int add_arg(struct func_event *fevent, int ftype, int unsign)
{
struct func_type *func_type = &func_types[ftype];
struct func_arg *arg;
@@ -211,13 +212,18 @@ static int add_arg(struct func_event *fevent, int ftype)
if (!arg)
return -ENOMEM;

- arg->type = kstrdup(func_type->name, GFP_KERNEL);
+ if (unsign)
+ arg->type = kasprintf(GFP_KERNEL, "unsigned %s",
+ func_type->name);
+ else
+ arg->type = kstrdup(func_type->name, GFP_KERNEL);
if (!arg->type) {
kfree(arg);
return -ENOMEM;
}
arg->size = func_type->size;
- arg->sign = func_type->sign;
+ if (!unsign)
+ arg->sign = func_type->sign;
arg->offset = ALIGN(fevent->arg_offset, arg->size);
arg->arg = fevent->arg_cnt;
fevent->arg_offset = arg->offset + arg->size;
@@ -232,12 +238,14 @@ static int add_arg(struct func_event *fevent, int ftype)
static enum func_states
process_event(struct func_event *fevent, const char *token, enum func_states state)
{
+ static int unsign;
long val;
int ret;
int i;

switch (state) {
case FUNC_STATE_INIT:
+ unsign = 0;
if (!isalpha(token[0]))
break;
/* Do not allow wild cards */
@@ -262,13 +270,20 @@ process_event(struct func_event *fevent, const char *token, enum func_states sta
/* Fall through */
case FUNC_STATE_COMMA:
comma:
+ if (strcmp(token, "unsigned") == 0) {
+ unsign = 2;
+ return FUNC_STATE_UNSIGNED;
+ }
+ /* Fall through */
+ case FUNC_STATE_UNSIGNED:
for (i = 0; func_types[i].size; i++) {
if (strcmp(token, func_types[i].name) == 0)
break;
}
if (!func_types[i].size)
break;
- ret = add_arg(fevent, i);
+ ret = add_arg(fevent, i, unsign);
+ unsign = 0;
if (ret < 0)
break;
return FUNC_STATE_TYPE;
--
2.15.1

\
 
 \ /
  Last update: 2018-02-03 00:14    [W:0.418 / U:5.792 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site