[ccan] New module: rprof, runtime profiler/timers
Rusty Russell
rusty at rustcorp.com.au
Mon Aug 29 15:04:41 EST 2011
On Fri, 26 Aug 2011 22:03:45 +0200, Christian Thaeter <ct at pipapo.org> wrote:
> Some observations: It is a bit exceptional as I designed it not to
code, I think.
> This possibly could
> improved with asserts or runtime checks, but I strive to make the
> timer function as deterministic AND small as possible. This makes
> writing tests a bit superfluous.
Err, no it doesn't!
Even a very simple program which mallocs a struct rprof, calls
rprof_init(), runs rprof_start() then rprof_stop(), then tests that
rprof_sum() >= 0 will test that you initialize all the fields correctly
(since it's run under valgrind).
Other suggestions:
1) Split the benchmark stuff into rprof_bench.h?
2) Use ccan/time?
3) Something to avoid compiler elimination of code, such as an
enhancement to RPROF_BENCH* which make sure gcc thinks it needs
the result?
4) #if HAVE_FOR_LOOP_DECLARATION || RPROF_STDC_VERSION >= 199901L
is ugly. Preferred is to include "config.h", maybe like:
#if 1 /* If you have a config.h, eg in ccan */
#include "config.h"
#else
# if __STDC_VERSION__ >= 199901L
# define HAVE_FOR_LOOP_DECLARATION 1
# endif
#endif
Though hacking up a config.h is expected abilities for someone using
ccan.
5) Your documentation style manages to be nonstandard *and* ugly,
but I'm sure you know that :)
> * How to disable valgrind for ccanlint testing?
(I answered this on IRC, but repeating here for posterity):
As a once-off:
ccanlint -x run_tests_valgrind
To suppress it in general, use _info. Either per-test:
* Ccanlint:
* // valgrind breaks on setsched().
* tests_pass_valgrind test/run.c:FAIL
Or to add some args to the valgrind cmdline:
* Ccanlint:
* // valgrind breaks on setsched().
* tests_pass_valgrind test/run.c:--args
Without the "testname:" prefix, it applies to all the tests.
> * This needs '-lrt' any way to put that in the metadata?
Yep! _info can tell what libraries to use:
if (strcmp(argv[1], "libs") == 0) {
printf("rt\n");
return 0;
}
It can depend on config.h #ifdefs, but I wouldn't worry about that until
someone ports it and fails...
Thanks!
Rusty.
More information about the ccan
mailing list