03-28-07 12:26 AM
"Christian Christmann" <plfriko@yahoo.de> wrote in message
news:pan.2007.03.27.11.16.31.197498@yahoo.de...
>
> I think that gcov is not what I'm looking for. With gcov I can
> determine
> how often a line has been executed in a program run. However, this
> profiling information is accumulated, i.e. I would know how often a
> loop was executed in total, but I still would not get any
> information
> on the single number of iterations. Or do I forget something?
>
Ah, I now see what you mean. Sorry, I did not understand your previous
post exactly.
So reading again, I think you just want the number of iterations spent
in a loop, for a single call each time?
In this case, I do not think gcov (or perhaps any code coverage tools)
will help you here.
As you may have noticed coverage / profiling tools collect data for a
whole execution to allow you to optimise etc... your program, while
what you want is more like "execution tracing" instead.
Unfortunately I cannot think of any solution except to use printfs
which you are already doing. If you find you do this a lot, maybe you
can make some #defines to make it easier to do. Here is a short
example below, however I could not think of a method #define for a for
loop, because you would have to change the code from "for (init;
predicate; increment;) to something like
"FOR(init,predicate,increment)" and even then, it would fail if there
are commas in "init".
#include <stdlib.h>
#include <stdio.h>
#define TRACE(x) printf("Looped %d times in %s at %s:%d\n", x,
__FUNCTION__, __FILE__, __LINE__)
#define CHECK_PRED(pred,var) ((pred) ? true : (TRACE(var),false))
#define APPLY(x,y) x(y)
#define MKVAR(x) var##x
#define VAR APPLY(MKVAR,__LINE__)
#define WHILE(pred) int VAR = 0; while(++VAR, CHECK_PRED(pred, VAR))
int main(void)
{
int nLoop = 0;
WHILE (nLoop < 30)
{
nLoop++;
}
return 0;
}
So, this is as good as I can think of. Anyone else have any ideas??
Mark
[ Post a follow-up to this message ]
|