Path: blob/devel/ElmerGUI/netgen/libsrc/general/profiler.cpp
3206 views
/**************************************************************************/1/* File: profiler.cpp */2/* Author: Joachim Schoeberl */3/* Date: 19. Apr. 2002 */4/**************************************************************************/567#include <myadt.hpp>8#define PROF_ACTIVE 0910namespace netgen11{12//using namespace netgen;1314long int NgProfiler::tottimes[SIZE];15long int NgProfiler::starttimes[SIZE];16long int NgProfiler::counts[SIZE];17string NgProfiler::names[SIZE];18int NgProfiler::usedcounter[SIZE];192021NgProfiler :: NgProfiler()22{23for (int i = 0; i < SIZE; i++)24{25tottimes[i] = 0;26usedcounter[i] = 0;27}2829total_timer = CreateTimer ("total CPU time");30StartTimer (total_timer);31}3233NgProfiler :: ~NgProfiler()34{35StopTimer (total_timer);3637//ofstream prof;38//prof.open("ng.prof");3940// ofstream-constructor may be called after STL-stuff is destructed,41// which leads to an "order of destruction"-problem,42// thus we use the C-variant:4344#if PROF_ACTIVE45char filename[100];46#ifdef PARALLEL47sprintf (filename, "netgen.prof.%d", id);48#else49sprintf (filename, "netgen.prof");50#endif51FILE *prof = fopen(filename,"w");52Print (prof);53fclose(prof);54#endif55}565758// void NgProfiler :: Print (ostream & prof)59// {60// for (int i = 0; i < SIZE; i++)61// if (counts[i] != 0 || usedcounter[i] != 0)62// {63// prof.setf (ios::fixed, ios::floatfield);64// prof.setf (ios::showpoint);6566// prof // << "job " << setw(3) << i67// << "calls " << setw(8) << counts[i]68// << ", time " << setprecision(2) << setw(6) << double(tottimes[i]) / CLOCKS_PER_SEC << " sec";6970// if (usedcounter[i])71// prof << " " << names[i];72// else73// prof << " " << i;7475// prof << endl;76// }77// }787980void NgProfiler :: Print (FILE * prof)81{82#if PROF_ACTIVE83for (int i = 0; i < SIZE; i++)84if (counts[i] != 0 || usedcounter[i] != 0)85{86fprintf(prof,"calls %8i, time %6.2f sec",counts[i],double(tottimes[i]) / CLOCKS_PER_SEC);87if(usedcounter[i])88fprintf(prof," %s",names[i].c_str());89else90fprintf(prof," %i",i);91fprintf(prof,"\n");92}93#endif94}9596int NgProfiler :: CreateTimer (const string & name)97{98for (int i = SIZE-1; i > 0; i--)99if(names[i] == name)100return i;101102for (int i = SIZE-1; i > 0; i--)103if (!usedcounter[i])104{105usedcounter[i] = 1;106names[i] = name;107return i;108}109return -1;110}111112113NgProfiler prof;114}115116117