Updating StackTrace and improving performance converting uCT data
This commit is contained in:
@@ -8,8 +8,10 @@
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
|
||||
#ifdef USE_MPI
|
||||
#include "mpi.h"
|
||||
@@ -19,6 +21,10 @@
|
||||
#include "MemoryApp.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_GCOV
|
||||
extern "C" void __gcov_flush( void );
|
||||
#endif
|
||||
|
||||
|
||||
#define perr std::cerr
|
||||
|
||||
@@ -65,6 +71,12 @@
|
||||
// clang-format on
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define USE_ABI
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace StackTrace {
|
||||
|
||||
|
||||
@@ -96,13 +108,12 @@ inline size_t findfirst( const std::vector<TYPE> &X, TYPE Y )
|
||||
/****************************************************************************
|
||||
* Function to terminate the program *
|
||||
****************************************************************************/
|
||||
static bool abort_throwException = false;
|
||||
static printStackType abort_stackType = printStackType::global;
|
||||
static int force_exit = 0;
|
||||
static bool abort_throwException = false;
|
||||
static int force_exit = 0;
|
||||
void Utilities::setAbortBehavior( bool throwException, int stackType )
|
||||
{
|
||||
abort_throwException = throwException;
|
||||
abort_stackType = static_cast<printStackType>( stackType );
|
||||
StackTrace::setDefaultStackType( static_cast<printStackType>( stackType ) );
|
||||
}
|
||||
void Utilities::abort( const std::string &message, const std::string &filename, const int line )
|
||||
{
|
||||
@@ -112,16 +123,28 @@ void Utilities::abort( const std::string &message, const std::string &filename,
|
||||
err.type = terminateType::abort;
|
||||
err.line = line;
|
||||
err.bytes = Utilities::getMemoryUsage();
|
||||
err.stackType = abort_stackType;
|
||||
err.stackType = StackTrace::getDefaultStackType();
|
||||
err.stack = StackTrace::backtrace();
|
||||
throw err;
|
||||
}
|
||||
static void terminate( const StackTrace::abort_error &err )
|
||||
static std::mutex terminate_mutex;
|
||||
static inline void callAbort()
|
||||
{
|
||||
#ifdef USE_GCOV
|
||||
__gcov_flush();
|
||||
#endif
|
||||
terminate_mutex.unlock();
|
||||
std::abort();
|
||||
}
|
||||
void Utilities::terminate( const StackTrace::abort_error &err )
|
||||
{
|
||||
// Lock mutex to ensure multiple threads do not try to abort simultaneously
|
||||
terminate_mutex.lock();
|
||||
// Clear the error handlers
|
||||
clearErrorHandler();
|
||||
// Print the message and abort
|
||||
if ( force_exit > 1 ) {
|
||||
std::abort();
|
||||
callAbort();
|
||||
} else if ( !abort_throwException ) {
|
||||
// Use MPI_abort (will terminate all processes)
|
||||
force_exit = 2;
|
||||
@@ -135,10 +158,11 @@ static void terminate( const StackTrace::abort_error &err )
|
||||
MPI_Abort( MPI_COMM_WORLD, -1 );
|
||||
}
|
||||
#endif
|
||||
std::abort();
|
||||
callAbort();
|
||||
} else {
|
||||
perr << err.what();
|
||||
std::abort();
|
||||
perr.flush();
|
||||
callAbort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +173,7 @@ static void terminate( const StackTrace::abort_error &err )
|
||||
static void setTerminateErrorHandler()
|
||||
{
|
||||
// Set the terminate routine for runtime errors
|
||||
StackTrace::setErrorHandler( terminate );
|
||||
StackTrace::setErrorHandler( Utilities::terminate );
|
||||
}
|
||||
void Utilities::setErrorHandlers()
|
||||
{
|
||||
@@ -293,4 +317,18 @@ std::string Utilities::exec( const string_view &cmd, int &exit_code )
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Get the type name *
|
||||
****************************************************************************/
|
||||
std::string Utilities::getTypeName( const std::type_info &id )
|
||||
{
|
||||
std::string name = id.name();
|
||||
#if defined( USE_ABI )
|
||||
int status;
|
||||
name = abi::__cxa_demangle( name.c_str(), 0, 0, &status );
|
||||
#endif
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
} // namespace StackTrace
|
||||
|
||||
Reference in New Issue
Block a user