• Li Zefan's avatar
    tracing/events: introduce __dynamic_array() · 7fcb7c47
    Li Zefan authored
    __string() is limited:
    
      - it's a char array, but we may want to define array with other types
      - a source string should be available, but we may just know the string size
    
    We introduce __dynamic_array() to break those limitations, and __string()
    becomes a wrapper of it. As a side effect, now __get_str() can be used
    in TP_fast_assign but not only TP_print.
    
    Take XFS for example, we have the string length in the dirent, but the
    string itself is not NULL-terminated, so __dynamic_array() can be used:
    
    TRACE_EVENT(xfs_dir2,
    	TP_PROTO(struct xfs_da_args *args),
    	TP_ARGS(args),
    
    	TP_STRUCT__entry(
    		__field(int, namelen)
    		__dynamic_array(char, name, args->namelen + 1)
    		...
    	),
    
    	TP_fast_assign(
    		char *name = __get_str(name);
    
    		if (args->namelen)
    			memcpy(name, args->name, args->namelen);
    		name[args->namelen] = '\0';
    
    		__entry->namelen = args->namelen;
    	),
    
    	TP_printk("name %.*s namelen %d",
    		  __entry->namelen ? __get_str(name) : NULL
    		  __entry->namelen)
    );
    
    [ Impact: allow defining dynamic size arrays ]
    Signed-off-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
    LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
    Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
    7fcb7c47
ftrace.h 14.9 KB