CppCommon  1.0.4.1
C++ Common Library
system_stack_trace.cpp

Stack trace snapshot provider example

#include "threads/thread.h"
#include <iostream>
#include <thread>
void function1()
{
std::cout << "Thread Id: " << __THREAD__ << std::endl;
std::cout << "Stack trace: " << std::endl << __STACK__ << std::endl;
}
void function2()
{
function1();
}
void function3()
{
function2();
}
int main(int argc, char** argv)
{
// Initialize stack trace manager of the current process
// Show the stack trace from the main thread
function3();
// Show the stack trace from the child thread
std::thread(function3).join();
// Cleanup stack trace manager of the current process
return 0;
}
static void Initialize()
Initialize stack trace manager.
static void Cleanup()
Cleanup stack trace manager.
Stack trace snapshot provider definition.
#define __STACK__
Current stack trace snapshot macro.
Definition: stack_trace.h:22
Stack trace manager definition.
Thread definition.
#define __THREAD__
Current thread Id macro.
Definition: thread.h:22