[mlpack-git] master: Add mlpack::backtrace (5e2f445)
gitdub at mlpack.org
gitdub at mlpack.org
Thu Feb 25 10:52:37 EST 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/fd84f3a2e53592d723a8e8a76dadb8aa76820913...1a9c41a86be1fa1dcc5c3b90dd959c2255c3bb8e
>---------------------------------------------------------------
commit 5e2f44528ca89c1963064f4b39ff77817865c8b5
Author: Grzegorz Krajewski <krajekg at gmail.com>
Date: Thu Feb 25 16:52:37 2016 +0100
Add mlpack::backtrace
Prints backtrace for Log::Fatal.
>---------------------------------------------------------------
5e2f44528ca89c1963064f4b39ff77817865c8b5
src/mlpack/core/util/prefixedoutstream_impl.hpp | 30 ++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/src/mlpack/core/util/prefixedoutstream_impl.hpp b/src/mlpack/core/util/prefixedoutstream_impl.hpp
index d86763f..bafc151 100644
--- a/src/mlpack/core/util/prefixedoutstream_impl.hpp
+++ b/src/mlpack/core/util/prefixedoutstream_impl.hpp
@@ -10,6 +10,7 @@
// Just in case it hasn't been included.
#include "prefixedoutstream.hpp"
+#include "backtrace.hpp"
#include <iostream>
namespace mlpack {
@@ -61,11 +62,31 @@ void PrefixedOutStream::BaseLogic(const T& val)
return;
}
- // Now, we need to check for newlines in this line. If we find one, output
- // up until the newline, then output the newline and the prefix and continue
- // looking.
+ // Now, we need to check for newlines in retrieved backtrace.
+ // If we find one, output up until the newline, then output the newline
+ // and the prefix and continue looking.
size_t nl;
size_t pos = 0;
+ if(fatal)
+ {
+ Backtrace bt;
+ std::string btLine = bt.ToString();
+ while ((nl = btLine.find('\n', pos)) != std::string::npos)
+ {
+ PrefixIfNeeded();
+
+ destination << btLine.substr(pos, nl - pos);
+ destination << std::endl;
+ newlined = true;
+
+ carriageReturned = true; // Regardless of whether or not we display it.
+
+ pos = nl + 1;
+ }
+ }
+
+ //The same logic like above, but this time for 'line'.
+ pos = 0;
while ((nl = line.find('\n', pos)) != std::string::npos)
{
PrefixIfNeeded();
@@ -93,7 +114,10 @@ void PrefixedOutStream::BaseLogic(const T& val)
// If we displayed a newline and we need to throw afterwards, do that.
if (fatal && newlined)
+ {
+ std::cout << std::endl;
throw std::runtime_error("fatal error; see Log::Fatal output");
+ }
}
// This is an inline function (that is why it is here and not in .cc).
More information about the mlpack-git
mailing list