Commit 818bc6ad authored by Davis King's avatar Davis King

Changed the stack trace stuff so that it doesn't perform memory

allocations or copy strings.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402242
parent 2c32d2d2
...@@ -10,17 +10,28 @@ ...@@ -10,17 +10,28 @@
#include "stack_trace.h" #include "stack_trace.h"
#include "threads.h" #include "threads.h"
#include "stack.h" #include "stack.h"
#include "memory_manager.h"
namespace dlib namespace dlib
{ {
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
thread_specific_data<stack<std::string>::kernel_1a>& get_dlib_stack_trace_stack() namespace
{ {
static thread_specific_data<stack<std::string>::kernel_1a> a; struct stack_tracer_data
{
const char* funct_name;
const char* file_name;
int line_number;
};
thread_specific_data<stack<stack_tracer_data,memory_manager<char>::kernel_2a>::kernel_1a>& get_dlib_stack_trace_stack()
{
static thread_specific_data<stack<stack_tracer_data,memory_manager<char>::kernel_2a>::kernel_1a> a;
return a; return a;
} }
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -31,16 +42,13 @@ namespace dlib ...@@ -31,16 +42,13 @@ namespace dlib
const int line_number const int line_number
) )
{ {
std::ostringstream sout; stack_tracer_data data;
// if the function name isn't really long then put this all on a single line data.funct_name = funct_name;
if (std::strlen(funct_name) < 40) data.file_name = file_name;
sout << file_name << ":" << line_number << ": " << funct_name; data.line_number = line_number;
else
sout << file_name << ":" << line_number << "\n" << funct_name; // pop the info onto the function stack trace
get_dlib_stack_trace_stack().data().push(data);
// pop the string onto the function stack trace
std::string temp(sout.str());
get_dlib_stack_trace_stack().data().push(temp);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -48,7 +56,7 @@ namespace dlib ...@@ -48,7 +56,7 @@ namespace dlib
stack_tracer:: stack_tracer::
~stack_tracer() ~stack_tracer()
{ {
std::string temp; stack_tracer_data temp;
get_dlib_stack_trace_stack().data().pop(temp); get_dlib_stack_trace_stack().data().pop(temp);
} }
...@@ -60,7 +68,8 @@ namespace dlib ...@@ -60,7 +68,8 @@ namespace dlib
get_dlib_stack_trace_stack().data().reset(); get_dlib_stack_trace_stack().data().reset();
while (get_dlib_stack_trace_stack().data().move_next()) while (get_dlib_stack_trace_stack().data().move_next())
{ {
sout << get_dlib_stack_trace_stack().data().element() << "\n"; stack_tracer_data data = get_dlib_stack_trace_stack().data().element();
sout << data.file_name << ":" << data.line_number << "\n " << data.funct_name;
} }
return sout.str(); return sout.str();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment