2009-01-13 04:40:13 +05:00
|
|
|
#ifndef FILE_NG_PROFILER
|
|
|
|
#define FILE_NG_PROFILER
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* File: profiler.hpp */
|
|
|
|
/* Author: Joachim Schoeberl */
|
|
|
|
/* Date: 5. Jan. 2005 */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef VTRACE
|
|
|
|
#include "vt_user.h"
|
|
|
|
#else
|
|
|
|
#define VT_USER_START(n)
|
|
|
|
#define VT_USER_END(n)
|
|
|
|
#define VT_TRACER(n)
|
|
|
|
#endif
|
|
|
|
|
2017-11-13 15:57:10 +05:00
|
|
|
|
|
|
|
// #define USE_TSC
|
|
|
|
#ifdef USE_TSC
|
|
|
|
#include <x86intrin.h> // for __rdtsc() CPU time step counter
|
|
|
|
#endif
|
|
|
|
|
2009-07-20 14:36:36 +06:00
|
|
|
namespace netgen
|
|
|
|
{
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
class NgProfiler
|
|
|
|
{
|
|
|
|
enum { SIZE = 1000 };
|
|
|
|
|
|
|
|
static long int tottimes[SIZE];
|
|
|
|
static long int starttimes[SIZE];
|
|
|
|
static long int counts[SIZE];
|
|
|
|
static string names[SIZE];
|
|
|
|
static int usedcounter[SIZE];
|
|
|
|
|
|
|
|
int total_timer;
|
|
|
|
public:
|
|
|
|
NgProfiler();
|
|
|
|
~NgProfiler();
|
|
|
|
static int CreateTimer (const string & name);
|
2017-11-13 15:57:10 +05:00
|
|
|
#ifndef USE_TSC
|
2009-01-13 04:40:13 +05:00
|
|
|
static void StartTimer (int nr)
|
|
|
|
{
|
|
|
|
starttimes[nr] = clock(); counts[nr]++;
|
2011-08-09 01:48:12 +06:00
|
|
|
// VT_USER_START (const_cast<char*> (names[nr].c_str()));
|
|
|
|
VT_USER_START ( (char * const) (names[nr].c_str()));
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
static void StopTimer (int nr)
|
|
|
|
{
|
|
|
|
tottimes[nr] += clock()-starttimes[nr];
|
|
|
|
VT_USER_END (const_cast<char*> (names[nr].c_str()));
|
|
|
|
}
|
2017-11-13 15:57:10 +05:00
|
|
|
#else
|
|
|
|
static void StartTimer (int nr)
|
|
|
|
{
|
|
|
|
starttimes[nr] = __rdtsc(); counts[nr]++;
|
|
|
|
// VT_USER_START (const_cast<char*> (names[nr].c_str()));
|
|
|
|
// VT_USER_START ( (char * const) (names[nr].c_str()));
|
|
|
|
}
|
|
|
|
static void StopTimer (int nr)
|
|
|
|
{
|
|
|
|
tottimes[nr] += __rdtsc()-starttimes[nr];
|
|
|
|
VT_USER_END (const_cast<char*> (names[nr].c_str()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
//static void Print (ostream & ost);
|
|
|
|
static void Print (FILE * prof);
|
|
|
|
|
2012-10-27 17:47:21 +06:00
|
|
|
static void ClearTimers ();
|
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
class RegionTimer
|
|
|
|
{
|
|
|
|
int nr;
|
|
|
|
public:
|
|
|
|
RegionTimer (int anr) : nr(anr)
|
|
|
|
{ StartTimer (nr); }
|
|
|
|
~RegionTimer () { StopTimer (nr); }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-07-20 14:36:36 +06:00
|
|
|
}
|
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
#endif
|