Re: tracepoint maintainance models

From: Mathieu Desnoyers
Date: Mon Sep 18 2006 - 11:51:58 EST


Hi Ingo,

If it is less visually intrusive to declare markers as a macro, let's do it this
way. I have no preference : as long as both dynamic probes and static ones can
be hooked and that it does imply so much black magic that kernel developers
won't know what code will be called from the marker when tracing is enabled.

Back in 2005, I made a quick macro example that would benefit to everybody. It
changes following config options to either :

- nothing
- a call to printk
- a call to a static tracer (either inline function or a real call)
- no operations (a 5 bytes site for an enhanced kprobe)

The 5 bytes of NOOP used here is absolutely not the way to go : djprobes guys
has much better alternatives.

Note that this example is a userspace program that can be trivially moved to a
kernel header (printf->printk, etc).

I also wanted to identify the trace point by a symbol, so it could be easily
found dynamically, but this part is not completed.

What are your thoughts about it ? (think of it as a proof of concept, and
search+replace MAGIC_TRACE for MARK). :)


Mathieu


----- BEGIN -----


/* ltt-macro.c
*
* Macro example for instrumentation
*
* Version 0.0.1
*
* Mathieu Desnoyers mathieu.desnoyers@xxxxxxxxxx
*
* This is released under the GPL v2 (or better) license.
*/



/* This is an example of noop, get this from the current arch header */
#define GENERIC_NOP1 ".byte 0x90\n"


/* PUT THIS IN A INCLUDE/LINUX HEADER */

#define __stringify_1(x) #x //see include/linux/stringify.h
#define __stringify(x) __stringify_1(x)

#define KBUILD_BASENAME basename
#define KBUILD_MODNAME modulename

#define MAGIC_TRACE_SYM(event) \
char * __trace_symbol_##event =__stringify(KBUILD_MODNAME) "_" \
__stringify(KBUILD_BASENAME) "_" \
#event ;

/* With config menu mutual exclusion of choice */
#ifdef CONFIG_NOLOG
#define MAGIC_TRACE(event, format, args...)
#endif

#ifdef CONFIG_PRINTLOG
#define MAGIC_TRACE(event, format, args...) \
printf(format, ##args);
#endif

#ifdef CONFIG_TRACELOG
#define MAGIC_TRACE(event, format, args...) \
trace_##event( args );
#endif

#ifdef CONFIG_KPROBELOG
#define MAGIC_TRACE(event, format, args...) \
__asm__ ( GENERIC_NOP1 GENERIC_NOP1 GENERIC_NOP1 GENERIC_NOP1 GENERIC_NOP1 )
#endif

/* PUT THIS IN A HEADER NEAR THE .C FILE */
#ifdef CONFIG_TRACELOG
static inline void trace_eventname(int a, char *b)
{
/* log.... */
printf("Tracing event : first arg %d, second arg %s", a, b);
}
#endif

/* PUT THIS IN THE .C FILE */

MAGIC_TRACE_SYM(eventname);

int main()
{
int myint = 55;
char * mystring = "blah";

MAGIC_TRACE(eventname, "%d %s", myint, mystring);

printf("\n");

return 0;
}

------ END -----




OpenPGP public key: http://krystal.dyndns.org:8080/key/compudj.gpg
Key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/