Page MenuHomec4science

lm_log.cc
No OneTemporary

File Metadata

Created
Sat, Oct 19, 07:28

lm_log.cc

/**
* @file lm_log.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Mon Sep 08 23:40:22 2014
*
* @brief Log/Debug system of 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/>.
*
*/
#include "lm_common.hh"
#include <mpi.h>
#include <fstream>
#include "action_manager.hh"
#include "lm_globals.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
#define CREATE_SEGFAULT if (create_seg_fault) {UInt * a = NULL; *a = 1;}
/* -------------------------------------------------------------------------- */
void doWait(bool condition) {
if(!condition) return;
UInt pid = lm_getpid();
std::cerr << "Proc " << lm_my_proc_id
<< " Waiting for gdb to attach: pid is " << pid
<< std::endl;
UInt a = 1;
while(a) {};
}
/* -------------------------------------------------------------------------- */
void doWaitOnFatal(){
doWait(wait_on_fatal);
}
/* -------------------------------------------------------------------------- */
void doWaitAtStartup(){
doWait((wait_at_startup != UINT_MAX)
&&
(lm_my_proc_id == wait_at_startup));
}
/* -------------------------------------------------------------------------- */
void lmFatal(std::stringstream & x,
UInt line,
const std::string & file,
const std::string & function,
const std::string & pretty_function) {
if (!fatal_loop) {
fatal_loop = true;
try {
ActionManager & actions = ActionManager::getManager();
current_stage = PRE_FATAL;
actions.action();
}
catch (...){
}
}
(*global_out) << "(" << current_step << ")"
<< "[" << lm_my_proc_id << "]<" << file
<< ":" << line << "> FATAL : "
<< x.str() << std::endl;
(*global_out).flush();
DOWAIT_ON_FATAL;
CREATE_SEGFAULT;
::libmultiscale::lm_exit(LM_EXIT_FAILURE);
}
/* -------------------------------------------------------------------------- */
void openGlobal(){
if (print_crap_to_file){
std::stringstream sstr;
sstr << my_hostname << "-" << lm_my_proc_id << ".log";
file_out.open(sstr.str().c_str(),std::ios_base::out);
global_out = &file_out;
}
else{
global_out = &std::cerr;
}
}
/* -------------------------------------------------------------------------- */
inline std::ostream & operator <<(std::ostream & stream, const dbgLevel & _this)
{
switch (_this){
case dbg_message : ; break;
case dbg_warning : stream << "WARNING:" ; break;
case dbg_info_startup : stream << "INFO_STARTUP:"; break;
case dbg_info : stream << "INFO:" ; break;
case dbg_detail : stream << "DETAIL:" ; break;
case dbg_all : stream << "ALL:" ; break;
}
return stream;
}
/* -------------------------------------------------------------------------- */
#define INFO_PROCESS \
"(" << current_step << ":" << current_stage \
<< ")[" << lm_my_proc_id << ","
#define INFO_PROCESS_FULL \
"(" << current_step << ")[" \
<< lm_my_proc_id << "," \
<< my_hostname << "," << getpid()
#define INFO_SOURCE \
function << ":" << line << "] "
#define INFO_SOURCE_FULL \
pretty_function << ":" << line << "] "
/* ----------------- */
//no info
//#define APPEND_FILE ""
/* ------------------*/
//small info
#define APPEND_FILE INFO_PROCESS << INFO_SOURCE
/* ------------------*/
//full info
//#define APPEND_FILE INFO_PROCESS_FULL << INFO_SOURCE_FULL
/* -------------------------------------------------------------------------- */
void lmPrintOut(std::stringstream & x,
dbgLevel level,
UInt line,
const std::string & file,
const std::string & function,
const std::string & pretty_function){
if(global_level >= level)
if((global_proc == lm_uint_max
|| global_proc == lm_my_proc_id
|| global_proc1 == lm_my_proc_id
|| global_proc2 == lm_my_proc_id)
&& (current_step >= start_dump &&
(end_dump == lm_uint_max
|| current_step <= end_dump))){
(*global_out) << APPEND_FILE <<
x.str() << std::endl << std::flush;
}
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__

Event Timeline