Page MenuHomec4science

surface_timer.cpp
No OneTemporary

File Metadata

Created
Sat, Nov 16, 08:04

surface_timer.cpp

/**
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas 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.
*
* Tamaas 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 Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "surface.hh"
__BEGIN_TAMAAS__
/* -------------------------------------------------------------------------- */
#if defined(USING_TIMER)
/* -------------------------------------------------------------------------- */
#include <map>
#include <iomanip>
/* -------------------------------------------------------------------------- */
#include "surface_timer.hh"
/* -------------------------------------------------------------------------- */
std::map<std::string,struct timespec> mesT;
std::map<std::string,UInt> nmes;
std::map<std::string,struct timespec> tstart;
std::map<std::string,struct timespec> tstop;
/* -------------------------------------------------------------------------- */
void dumpTimes(UInt proc_number) {
std::stringstream fname;
fname << "perf-" << proc_number;
std::ofstream out(fname.str().c_str());
out << std::setw(30) << "Operation" << std::setw(5) << " "
<< std::setw(20) << "Mean time(s)" << std::setw(5) << " "
<< std::setw(20) << "Total time(s)" << std::setw(5) << " "
<< std::setw(20) << "Call number" << std::endl;
std::multimap<Real,std::string> inv;
{
std::map<std::string,struct timespec>::iterator it = mesT.begin();
std::map<std::string,struct timespec>::iterator end = mesT.end();
for( ; it != end ; ++it){
Real t = (*it).second.tv_sec + (*it).second.tv_nsec*1e-9;
inv.insert(std::pair<Real,std::string>(t,(*it).first));
}
}
std::multimap<Real,std::string>::reverse_iterator it = inv.rbegin();
std::multimap<Real,std::string>::reverse_iterator end = inv.rend();
for( ; it != end ; ++it){
std::string & key = (*it).second;
Real t = (*it).first;
UInt n = nmes[key];
Real t_moy = t/n;
out << std::scientific << std::setprecision(10)
<< std::setw(30) << key << std::setw(5) << " "
<< std::setw(20) << t_moy << std::setw(5) << " "
<< std::setw(20) << t << std::setw(5) << " "
<< std::setw(20) << n << std::endl;
}
}
#else
void dumpTimes(UInt proc_number) {}
#endif
/* -------------------------------------------------------------------------- */
__END_TAMAAS__

Event Timeline