Page MenuHomec4science

lm_timer.hh
No OneTemporary

File Metadata

Created
Sun, Nov 3, 14:20

lm_timer.hh

/**
* @file lm_timer.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Mon Sep 08 23:40:22 2014
*
* @brief Timer system for LibMultiScale
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it
* under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale is distributed in the hope that it will be useful, but
* WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#if defined(TIMER) && defined(LIBMULTISCALE_TIMER)
/* -------------------------------------------------------------------------- */
#include <fstream>
#include <map>
#include <time.h>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
extern std::map<std::string, struct timespec> mesT;
extern std::map<std::string, UInt> nmes;
extern std::map<std::string, struct timespec> tstart;
extern std::map<std::string, struct timespec> tstop;
extern UInt header;
/* -------------------------------------------------------------------------- */
#define SEC_IN_NANOSEC 1000000000
/* -------------------------------------------------------------------------- */
inline void STARTTIMER(const std::string &x) {
if (!mesT.count(x)) {
mesT[x].tv_sec = 0;
mesT[x].tv_nsec = 0;
}
clock_gettime(CLOCK_REALTIME, &(tstart[x]));
}
/* -------------------------------------------------------------------------- */
inline void STOPTIMER(const std::string &x) {
clock_gettime(CLOCK_REALTIME, &(tstop[x]));
mesT[x].tv_sec += (tstop[x].tv_sec - tstart[x].tv_sec);
mesT[x].tv_nsec += (tstop[x].tv_nsec - tstart[x].tv_nsec);
if (mesT[x].tv_nsec < 0) {
--mesT[x].tv_sec;
mesT[x].tv_nsec += SEC_IN_NANOSEC;
}
if (mesT[x].tv_nsec >= SEC_IN_NANOSEC) {
++mesT[x].tv_sec;
mesT[x].tv_nsec -= SEC_IN_NANOSEC;
}
++nmes[x];
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#else
#define STARTTIMER(x)
#define STOPTIMER(x)
#endif
__BEGIN_LIBMULTISCALE__
void dumpTimes(UInt proc_number = 0);
void dumpTimesInColumn(UInt proc_number = 0, UInt step = 0);
__END_LIBMULTISCALE__

Event Timeline