19 typedef std::map<std::string, double>
Event;
26 typedef std::map<std::string, double>::iterator
E_iter;
52 gettimeofday(&tv, NULL);
53 return double(tv.tv_sec+tv.tv_usec*1e-6);
71 file.open((folder +
"/time").c_str());
72 stepFile.open((folder +
"/profiling").c_str());
73 legendFile.open((folder +
"/profiling_legend").c_str());
106 timeStep[event] += toc - tic[event];
107 timer[event] += toc - tic[event];
109 std::cout <<
event <<
" : " << timer[event] << std::endl;
127 for(
E_iter E=timer.begin(); E!=timer.end(); ++E )
136 for (
E_iter E=timeStep.begin(); E!=timeStep.end(); ++E )
148 memory[event] += bytes;
159 memory[event] -= bytes;
169 std::cout <<
event <<
" : " << timer[event] << std::endl;
179 std::cout <<
event <<
" : " << memory[event] << std::endl;
187 double totalTime = 0.0;
188 std::cout << std::endl;
189 for(
E_iter E=timer.begin(); E!=timer.end(); ++E )
191 totalTime += E->second;
192 std::cout << std::setw(24) << E->first << std::setw(13) << std::fixed \
193 << std::setprecision(4) << E->second << std::endl;
195 std::cout <<
"-------------------------------------" << std::endl;
196 std::cout << std::setw(24) <<
"TOTAL" << std::setw(13) << std::fixed \
197 << std::setprecision(4) << totalTime << std::endl;
205 for(
E_iter E=timer.begin(); E!=timer.end(); ++E )
207 legendFile << E->first << std::endl;
216 for(
E_iter E=timer.begin(); E!=timer.end(); ++E )
217 file << E->first <<
" " << E->second << std::endl;
227 stepFile << n <<
"\t";
228 for (
E_iter E=timeStep.begin(); E!=timeStep.end(); ++E )
229 stepFile << E->second <<
"\t";
230 stepFile << std::endl;
Monitors the time spent to achieve a certain task.
void printAllTime()
Prints time spent for each event as well as the total time.
bool printNow
boolean to print or not the time in the terminal
Event timeStep
contain the tiem spent times of events for 1 step
void writeLegend()
Writes the events into a file.
void writeTime()
Writes time spent for each event into a file.
Event timer
contain the total time spent of events during the simulation
void printTime(std::string event)
Prints the time spent to achieve a event.
std::ofstream file
file to write the time spent
void resetTimeStep()
Resets the time-step timer.
void startTimer(std::string event)
Starts the timer.
std::map< std::string, double >::iterator E_iter
void eraseTimer(std::string event)
Erases the timer of a given event.
void freeMemory(std::string event, double bytes)
Frees memory allocated for a given event.
void writeTimeStep(int n)
Writes time spent for an iteration into a file.
void resetTimer()
Resets the timer.
std::ofstream legendFile
file to write the name of the events
void printMemory(std::string event)
Prints the memory allocated for a given event.
Event tic
contain the starting time of events
Logger(std::string folder)
Constructor overloading. Opens files given the case directory.
void stopTimer(std::string event, bool print=false)
Stops the timer.
double get_time()
Gets the time of the day.
void allocMemory(std::string event, double bytes)
Allocates memory for an event given a size.
std::map< std::string, double > Event
Event memory
contain info about the memomry allocated for events
std::ofstream stepFile
file to write the time spent for 1 step