[Click] Feature: debug_output

Harald Schiöberg harald at net.t-labs.tu-berlin.de
Thu Mar 4 05:18:39 EST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

since 1.8.0 is out, lets talk about features;)

here are some thoughts how we do debugging output in our Elements. I
think they would fit in the Element class itself.
What do you think ?

Here is the idea:
################
code like this:

void SomeElement::push(Packet *p){
  debug_output(VERB_PACKETS,
	"packet with ip %s pushed",
	 ntoa( p->ip_header->ip_src ) );
}

given this config: (see notes below)
 -> foo:SomeElement(VERBOSITY VERB_PACKETS)  ->

should produce this output:
[foo] packet with ip 1.2.3.4 pushed

and close to 0 overhead if VERB_PACKETS is not set, especially no string
unparsing

####################

1): /* make the verbosity of Elements configurable.
Element::configure() { ...
	if (cp_va_kparse(conf, this, errh,
			"VERBOSITY", 0, cpUnsigned, &(_verbosity),

/* Question: any way of making this happen? without adding cpIgnoreRest
and a call to Element::configure to all Elements? (actually it's not
soooo bad, because it only needs to be added to those, who actually use
debug_output)   */


2): /* get an accessor */
	int Element::verbosity() const { return _verbosity; }

3): /* define a base unparse method, but allow for fancier things */
virtual String Element::unparse() const { return "[" + name() + "] " ; }

4) /* define verbosity levels, this could be an enum, of maybe some kind
of magic Info thingies,  */

#define VERB_NONE 		0
#define VERB_ALL  		0xffffffff
#define VERB_ERRORS 	0x01
#define VERB_WARNINGS 	0x02
#define VERB_INFO		0x04
#define VERB_DEBUG		0x08
#define VERB_MFD_QUEUES 0x10 // for the MFD Handler Queues
#define VERB_PACKETS 	0x20 // triggered on packet handling/traversal events
#define VERB_DISPATCH   0x40 // for anything related to interconnecting
handlers
#define VERB_MFH_STATE  0x80 /

3) /*define debug_output macro
* use of a macro allows to not even evaluate the parameters if the
* verbosity bit is not set -> only one bit-comparision of overhead in
* this case */

#define debug_output(mask, formatstring, args...) \

    if ((mask) & (this->verbosity())) { \

        ErrorHandler *errh = ErrorHandler::default_handler(); \

        errh->xmessage( this->unparse(), errh->format( (formatstring) ,
##args ) ); \
    }

Open Issues
###########

We can currently only do
- -> foo::SomeElement(VERBOSITY 0x20) ->

I know that there are provivisions for parsing named values like
"VERB_ERRORS" from configure files, and I suspect there might even be
stuff for "VERB_ERRORS | VERB_WARNINGS" but I haven't looked into that yet.

The macro definitely needs another definition for kernel level...


- --
Harald Schiöberg
Technische Universität Berlin | T-Laboratories | FG INET
www: http://www.net.t-labs.tu-berlin.de
Phone: +49-(0)30-8353-58476 | Fax: +49-(0)391 534 783 47
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFLj4j+y8wrZ9OvkU0RAkHYAJ9Dlvk9o9HaW6jJiBwrTzhimfbccwCg8ruW
RcapoedRI1Ah/ZrzZZLlAe0=
=z1jC
-----END PGP SIGNATURE-----



More information about the click mailing list