Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Functions | Variables
stacktrace.hpp File Reference

This file contains the definition for the stacktrace related functionality. More...

#include "shambase/SourceLocation.hpp"
#include "shambase/aliases_float.hpp"
#include "shambase/aliases_int.hpp"
#include "shambase/profiling/profiling.hpp"
#include "shambase/string.hpp"
#include "shambase/unique_name_macro.hpp"
#include <stack>
+ Include dependency graph for stacktrace.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  shambase::details::CallStackEntry
 Helper class to manage the call stack entry. More...
 
struct  shambase::details::BasicStackEntry
 
struct  shambase::details::NamedBasicStackEntry
 

Namespaces

namespace  shambase
 namespace for basic c++ utilities
 

Macros

#define __shamrock_stack_entry()    [[maybe_unused]] StackEntry __shamrock_unique_name(stack_loc_) {}
 Macro to create a stack entry.
 
#define __shamrock_log_callsite(callsite)
 Macro to create a stack entry from a given location. Can be used only on SourceLocation &&.
 
#define __shamrock_stack_entry_with_callsite(callsite)    [[maybe_unused]] StackEntry __shamrock_unique_name(stack_loc_) { callsite }
 Macro to create a stack entry.
 

Typedefs

using StackEntry = shambase::details::BasicStackEntry
 Alias for shambase::details::BasicStackEntry.
 
using NamedStackEntry = shambase::details::NamedBasicStackEntry
 Alias for shambase::details::NamedBasicStackEntry.
 

Functions

f64 shambase::details::get_wtime ()
 Returns the current wall clock time in seconds.
 
void shambase::details::register_profile_entry_start (std::source_location loc, f64 start_time)
 Register the start of a profile entry. This is required for chrome profiling as there is a separate entry for start and end.
 
void shambase::details::register_profile_entry (std::source_location loc, f64 start_time, f64 end_time)
 Register a profile entry. This register the end of a profile entry for chrome tracing and a complete entry in the builtin profiling data.
 
void shambase::details::dump_profilings (const std::string &process_prefix, u32 world_rank)
 Dump the profiling data in a JSON format to a file.
 
void shambase::details::dump_profilings_chrome (const std::string &process_prefix, u32 world_rank)
 Dump the profiling data in a Chrome Tracing format.
 
void shambase::details::clear_profiling_data ()
 Clear the profiling data. (should be done in large run to avoid out-of-memory)
 
std::string shambase::fmt_callstack ()
 Get the formatted callstack.
 
void shambase::set_callstack_process_identifier (std::string identifier)
 
void shambase::add_callstack_gen_info_generator (std::string(*generator)())
 

Variables

std::stack< SourceLocationshambase::details::call_stack
 The call stack used to keep track of the stack trace. It is used to print the stack trace when an exception is thrown.
 

Detailed Description

This file contains the definition for the stacktrace related functionality.

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

Definition in file stacktrace.hpp.

Macro Definition Documentation

◆ __shamrock_log_callsite

#define __shamrock_log_callsite (   callsite)
Value:
[[maybe_unused]] shambase::details::CallStackEntry __shamrock_unique_name(call_site_loc) { \
callsite \
}
Helper class to manage the call stack entry.

Macro to create a stack entry from a given location. Can be used only on SourceLocation &&.

This macro defines a StackEntry variable with a unique name by leveraging the __shamrock_unique_name macro.

Definition at line 266 of file stacktrace.hpp.

◆ __shamrock_stack_entry

#define __shamrock_stack_entry ( )     [[maybe_unused]] StackEntry __shamrock_unique_name(stack_loc_) {}

Macro to create a stack entry.

This macro defines a StackEntry variable with a unique name by leveraging the __shamrock_unique_name macro.

Definition at line 257 of file stacktrace.hpp.

◆ __shamrock_stack_entry_with_callsite

#define __shamrock_stack_entry_with_callsite (   callsite)     [[maybe_unused]] StackEntry __shamrock_unique_name(stack_loc_) { callsite }

Macro to create a stack entry.

This macro defines a StackEntry variable with a unique name by leveraging the __shamrock_unique_name macro.

Definition at line 277 of file stacktrace.hpp.

Typedef Documentation

◆ NamedStackEntry

Alias for shambase::details::NamedBasicStackEntry.

This alias is used to simplify the use of the NamedBasicStackEntry class.

Definition at line 249 of file stacktrace.hpp.

◆ StackEntry

Alias for shambase::details::BasicStackEntry.

This alias is used to simplify the use of the BasicStackEntry class.

Definition at line 242 of file stacktrace.hpp.

Function Documentation

◆ clear_profiling_data()

void shambase::details::clear_profiling_data ( )

Clear the profiling data. (should be done in large run to avoid out-of-memory)

Definition at line 195 of file stacktrace.cpp.

+ Here is the call graph for this function:

◆ dump_profilings()

void shambase::details::dump_profilings ( const std::string &  process_prefix,
u32  world_rank 
)

Dump the profiling data in a JSON format to a file.

Parameters
process_prefixThe prefix of the process name.
world_rankThe rank of the process.

Definition at line 200 of file stacktrace.cpp.

+ Here is the call graph for this function:

◆ dump_profilings_chrome()

void shambase::details::dump_profilings_chrome ( const std::string &  process_prefix,
u32  world_rank 
)

Dump the profiling data in a Chrome Tracing format.

Parameters
process_prefixThe prefix of the process name.
world_rankThe rank of the process.

Definition at line 85 of file stacktrace.cpp.

◆ get_wtime()

f64 shambase::details::get_wtime ( )

Returns the current wall clock time in seconds.

Get the current wall time.

Returns
f64 The current wall clock time in seconds.
f64 Wall time in seconds since program start

Definition at line 179 of file stacktrace.cpp.

+ Here is the call graph for this function:

◆ register_profile_entry()

void shambase::details::register_profile_entry ( std::source_location  loc,
f64  start_time,
f64  end_time 
)

Register a profile entry. This register the end of a profile entry for chrome tracing and a complete entry in the builtin profiling data.

Parameters
locThe source location of the profile entry.
start_timeThe start time of the profile entry.
end_timeThe end time of the profile entry.

Definition at line 188 of file stacktrace.cpp.

+ Here is the call graph for this function:

◆ register_profile_entry_start()

void shambase::details::register_profile_entry_start ( std::source_location  loc,
f64  start_time 
)

Register the start of a profile entry. This is required for chrome profiling as there is a separate entry for start and end.

Parameters
locThe source location of the profile entry.
start_timeThe start time of the profile entry.

Definition at line 184 of file stacktrace.cpp.

+ Here is the call graph for this function:

Variable Documentation

◆ call_stack

std::stack<SourceLocation> shambase::details::call_stack
inline

The call stack used to keep track of the stack trace. It is used to print the stack trace when an exception is thrown.

Definition at line 84 of file stacktrace.hpp.