int TraceTimer::initializer()
{
  static bool initialized = false;
  if (initialized) return -11;

#ifndef CH_NTIMER
  const char* rootName = "main";
  TraceTimer* rootTimer = new TraceTimer(rootName, NULL, 0);
  rootTimer->m_thread_id = 0;
  char mutex = 0;
  s_roots.resize(1);
  s_roots[0] = rootTimer;
  s_currentTimer.resize(1);
  s_currentTimer[0]=rootTimer;

  char* timerEnv = getenv("CH_TIMER");
  if (timerEnv == NULL)
    {
      rootTimer->m_pruned = true;
    }
  else
    {
      s_traceMemory = false;
      if (strcmp(timerEnv, "MEMORY")==0)
        {
#ifdef  CH_USE_MEMORY_TRACKING
          s_traceMemory = true;
#endif

        }
      if (strncmp(timerEnv, "SAMPLE=",7)==0)
        {
          sampleFrequency = atoi(timerEnv+7);
#ifdef CH_DISABLE_SIGNALS
          std::cout<<"You requested profile "<<timerEnv
                   <<"  but CH_DISABLE_SIGNALS is turned on, no sampling possible\n";
#else
          signal(SIGALRM, sampleMem);
          ualarm( sampleFrequency, sampleFrequency );
#endif


        }
    }
  rootTimer->start(&mutex);
  zeroTime = TimerGetTimeStampWC();
  zeroTicks = ch_ticks();
  //  OK, I think I have the atexit vs. static objects bug under AIX worked out. we'll see.
  //#ifndef CH_AIX
  // petermc, 21 April 2006:
  // put "#ifndef CH_AIX" around this because on seaborg,
  // the presence of this line causes a segfault at the termination
  // of the program.
  //   OK, last time around the maypole.  It just seems that atexit and MPI_Finalize are
  //   not going to be cooperative.  bvs
#ifndef CH_MPI
  if (timerEnv != NULL) atexit(writeOnExit);
#endif

  //#endif
#endif // CH_NTIMER
  initialized = true;
  return 0;
}
Esempio n. 2
0
int TraceTimer::initializer()
{
#ifdef _OPENMP
  if(onThread0()){
#endif
  static bool initialized = false;
  if (initialized) return -11;

#ifndef CH_NTIMER
  // flop-counting breaks multidim

  //FORTRAN_BASENAME(FLOPINIT,flopinit)() ;

  CountersInit();

  const char* rootName = "main";
  TraceTimer* rootTimer = new TraceTimer(rootName, NULL, 0);
  rootTimer->m_thread_id = 0;
  char mutex = 0;
  s_roots.resize(1);
  s_roots[0] = rootTimer;
  s_currentTimer.resize(1);
  s_currentTimer[0]=rootTimer;

  char* timerEnv = getenv("CH_TIMER");
  s_memorySampling = false;
  s_tracing= false;
  rootTimer->start(&mutex);
  zeroTime = TimerGetTimeStampWC();
  zeroTicks = ch_ticks();

  if (timerEnv == NULL)
    {
      rootTimer->m_pruned = true;
    }
  else if (strncmp(timerEnv, "SAMPLE=",7)==0)
    {
#ifdef CH_USE_MEMORY_TRACKING
#ifndef CH_DISABLE_SIGNALS
      sampleFrequency = atoi(timerEnv+7);
      signal(SIGALRM, sampleMem);
      ualarm( sampleFrequency, sampleFrequency );
      s_memorySampling = true;
#else 
      std::cout<<"Chombo was compiled with memory tracking, but CH_DISABLE_SIGNALS was set.  no samples created"<<std::endl;
#endif
#else
      std::cout<<"CH_USE_MEMORY_TRACKING was not used during compilation, so no memory sampling will happen"<<std::endl;
#endif
      
    } else if (strncmp(timerEnv, "TRACING",7)==0)
    {
#ifdef CH_USE_MEMORY_TRACKING
#ifndef CH_DISABLE_SIGNALS
      s_tracing = true;
#else 
      std::cout<<"Chombo was compiled with memory tracking, but CH_DISABLE_SIGNALS was set.  no samples created"<<std::endl;
#endif
#else
      std::cout<<"CH_USE_MEMORY_TRACKING was not used during compilation, so no memory sampling will happen"<<std::endl;
#endif
    }

  //  OK, I think I have the atexit vs. static objects bug under AIX worked out. we'll see.
  //#ifndef CH_AIX
  // petermc, 21 April 2006:
  // put "#ifndef CH_AIX" around this because on seaborg,
  // the presence of this line causes a segfault at the termination
  // of the program.
  //   OK, last time around the maypole.  It just seems that atexit and MPI_Finalize are
  //   not going to be cooperative.  bvs
//#ifndef CH_MPI
  if (timerEnv != NULL)
   { 
      atexit(writeOnExit);
#ifndef CH_DISABLE_SIGNALS
      signal(SIGABRT, writeOnAbort);
#endif
   }
//#endif

  //#endif
#endif // CH_NTIMER

  initialized = true;
  if (s_memorySampling)
    samplingOn = true;
#ifdef _OPENMP
  }
#endif
  return 0;
}