• Steven Rostedt's avatar
    ftrace: trace different functions with a different tracer · 59df055f
    Steven Rostedt authored
    Impact: new feature
    
    Currently, the function tracer only gives you an ability to hook
    a tracer to all functions being traced. The dynamic function trace
    allows you to pick and choose which of those functions will be
    traced, but all functions being traced will call all tracers that
    registered with the function tracer.
    
    This patch adds a new feature that allows a tracer to hook to specific
    functions, even when all functions are being traced. It allows for
    different functions to call different tracer hooks.
    
    The way this is accomplished is by a special function that will hook
    to the function tracer and will set up a hash table knowing which
    tracer hook to call with which function. This is the most general
    and easiest method to accomplish this. Later, an arch may choose
    to supply their own method in changing the mcount call of a function
    to call a different tracer. But that will be an exercise for the
    future.
    
    To register a function:
    
     struct ftrace_hook_ops {
    	void			(*func)(unsigned long ip,
    					unsigned long parent_ip,
    					void **data);
    	int			(*callback)(unsigned long ip, void **data);
    	void			(*free)(void **data);
     };
    
     int register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
    				  void *data);
    
    glob is a simple glob to search for the functions to hook.
    ops is a pointer to the operations (listed below)
    data is the default data to be passed to the hook functions when traced
    
    ops:
     func is the hook function to call when the functions are traced
     callback is a callback function that is called when setting up the hash.
       That is, if the tracer needs to do something special for each
       function, that is being traced, and wants to give each function
       its own data. The address of the entry data is passed to this
       callback, so that the callback may wish to update the entry to
       whatever it would like.
     free is a callback for when the entry is freed. In case the tracer
       allocated any data, it is give the chance to free it.
    
    To unregister we have three functions:
    
      void
      unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
    				void *data)
    
    This will unregister all hooks that match glob, point to ops, and
    have its data matching data. (note, if glob is NULL, blank or '*',
    all functions will be tested).
    
      void
      unregister_ftrace_function_hook_func(char *glob,
    				 struct ftrace_hook_ops *ops)
    
    This will unregister all functions matching glob that has an entry
    pointing to ops.
    
      void unregister_ftrace_function_hook_all(char *glob)
    
    This simply unregisters all funcs.
    Signed-off-by: default avatarSteven Rostedt <srostedt@redhat.com>
    59df055f
ftrace.c 53 KB