Let the tracer also output the function name.
This makes it easier when multiple tracers are used. When using gcc a more verbose, non-standard, method is used.
This commit is contained in:
parent
947e32057b
commit
b6e5b4b6e6
2 changed files with 16 additions and 6 deletions
|
@ -31,7 +31,7 @@ ttracer::tprint::~tprint()
|
|||
return;
|
||||
}
|
||||
|
||||
std::cerr << "Run statistics:\n"
|
||||
std::cerr << "Run statistics for " << tracer->function << ":\n"
|
||||
<< "Runs:\t" << std::dec << tracer->run << "\n";
|
||||
|
||||
typedef std::pair<std::pair<int, std::string>, int> thack;
|
||||
|
@ -58,8 +58,9 @@ ttracer::tprint::~tprint()
|
|||
std::cerr.setf(original_flag, std::ios_base::adjustfield);
|
||||
}
|
||||
|
||||
ttracer::ttracer()
|
||||
ttracer::ttracer(const char* const function__)
|
||||
: run(0)
|
||||
, function(function__)
|
||||
, counters()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -49,11 +49,14 @@ struct ttracer
|
|||
const ttracer* const tracer;
|
||||
};
|
||||
|
||||
ttracer();
|
||||
explicit ttracer(const char* const function__);
|
||||
|
||||
/** The total number of runs. */
|
||||
int run;
|
||||
|
||||
/** The function being traced. */
|
||||
const char* const function;
|
||||
|
||||
/**
|
||||
* The tracer counters.
|
||||
*
|
||||
|
@ -77,9 +80,15 @@ struct ttracer
|
|||
*
|
||||
* @param interval The interval between printing the statistics.
|
||||
*/
|
||||
#define TRACER_ENTRY(interval) \
|
||||
static ttracer tracer; \
|
||||
#ifdef __GNUC__
|
||||
#define TRACER_ENTRY(interval) \
|
||||
static ttracer tracer(__PRETTY_FUNCTION__); \
|
||||
ttracer::tprint print((++tracer.run % interval) == 0 ? &tracer : NULL)
|
||||
#else
|
||||
#define TRACER_ENTRY(interval) \
|
||||
static ttracer tracer(__FUNCTION__); \
|
||||
ttracer::tprint print((++tracer.run % interval) == 0 ? &tracer : NULL)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A trace count point.
|
||||
|
@ -88,7 +97,7 @@ struct ttracer
|
|||
*
|
||||
* @param marker A string with the name of the marker.
|
||||
*/
|
||||
#define TRACER_COUNT(marker) \
|
||||
#define TRACER_COUNT(marker) \
|
||||
do { \
|
||||
++tracer.counters[std::make_pair(__LINE__, marker)]; \
|
||||
} while(0)
|
||||
|
|
Loading…
Add table
Reference in a new issue