From 864b031b6a260bc3eaa9a83800d21d3b4c0ce0a6 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sat, 6 Jan 2018 15:13:20 +0100 Subject: [PATCH] Disable backtrace generation in Hurricane::Error constructor. * Change: In Hurricane::Backtrace constructor, add a boolean parameter to enable/disable the actual backtrace generation. * Change: In Hurricane::Error constructor, disable by default the backtrace generation. The backtrace is useful when the Error is thrown, and the program therefore stopped. But in many case we just issue the error message on the console and try to continue. But if the backtrace is enabled, it terribly slow down the program. Have to think about an clean way to re-enable the trace only when the exception is thrown. --- hurricane/src/hurricane/Backtrace.cpp | 4 +++- hurricane/src/hurricane/Error.cpp | 8 ++++---- hurricane/src/hurricane/hurricane/Backtrace.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hurricane/src/hurricane/Backtrace.cpp b/hurricane/src/hurricane/Backtrace.cpp index aad56166..02cb5b47 100644 --- a/hurricane/src/hurricane/Backtrace.cpp +++ b/hurricane/src/hurricane/Backtrace.cpp @@ -427,9 +427,11 @@ namespace Hurricane { // 3 libstdc++.6.dylib 0x9142514b _ZSt9terminatev + 29 - Backtrace::Backtrace () + Backtrace::Backtrace ( bool enabled ) : _stack() { + if (not enabled) return; + if (_inConstructor) { _stack.push_back( "[BUG] Backtrace::Backtrace(): An error occurred in the backtace *istself*." ); _stack.push_back( "" ); diff --git a/hurricane/src/hurricane/Error.cpp b/hurricane/src/hurricane/Error.cpp index 76a83b9c..ecbea250 100644 --- a/hurricane/src/hurricane/Error.cpp +++ b/hurricane/src/hurricane/Error.cpp @@ -47,7 +47,7 @@ namespace Hurricane { : Exception () , _reason (reason) , _code (0) - , _backtrace() + , _backtrace(false) { } @@ -55,7 +55,7 @@ namespace Hurricane { : Exception () , _reason (reason) , _code (code) - , _backtrace() + , _backtrace(false) { } @@ -63,7 +63,7 @@ namespace Hurricane { : Exception () , _reason () , _code (0) - , _backtrace() + , _backtrace(false) { static char formatted [ 8192 ]; va_list args; @@ -80,7 +80,7 @@ namespace Hurricane { : Exception () , _reason () , _code (code) - , _backtrace() + , _backtrace(false) { static char formatted [ 8192 ]; va_list args; diff --git a/hurricane/src/hurricane/hurricane/Backtrace.h b/hurricane/src/hurricane/hurricane/Backtrace.h index eefcfeaa..d2cddbc2 100644 --- a/hurricane/src/hurricane/hurricane/Backtrace.h +++ b/hurricane/src/hurricane/hurricane/Backtrace.h @@ -42,7 +42,7 @@ namespace Hurricane { class Backtrace { public: - Backtrace (); + Backtrace ( bool enabled ); ~Backtrace (); inline std::string where () const; inline std::string textWhere () const;