23namespace shambase::details {
41 return shambase::format_printf(
59 return shambase::format_printf(
79 std::vector<ChromeProfileEntry> profile_data_chrome;
90 auto to_prof_time = [](
f64 in) {
91 return static_cast<u64>(in * 1e6);
96 .name = loc.function_name(), .time_val = to_prof_time(time), .is_start = is_start});
102 inline void clear_chrome_entry() { profile_data_chrome.clear(); }
104 void dump_profilings_chrome(
const std::string &process_prefix,
u32 world_rank) {
107 std::ofstream outfile(process_prefix + std::to_string(world_rank));
112 u32 len = profile_data_chrome.size();
114 for (
u32 i = 0; i < len; i++) {
116 outfile << profile_data_chrome[i].format(world_rank);
131namespace shambase::details {
165 return shambase::format_printf(
192 {.time_start = start_time, .time_end = end_time, .entry_name = loc.function_name()});
203 std::ofstream outfile(process_prefix + std::to_string(world_rank));
208 for (
u32 i = 0; i < len; i++) {
223 std::string _callstack_process_identifier;
225 void set_callstack_process_identifier(std::string identifier) {
226 _callstack_process_identifier = std::move(identifier);
229 std::vector<std::function<std::string()>> _callstack_gen_info_generators;
231 void add_callstack_gen_info_generator(std::string (*generator)()) {
232 _callstack_gen_info_generators.push_back(std::move(generator));
243 std::vector<std::string> lines;
245 while (!cpy.empty()) {
251 std::reverse(lines.begin(), lines.end());
253 std::stringstream ss;
255 if (!_callstack_process_identifier.empty()) {
256 ss <<
" -> process identifier: " << _callstack_process_identifier <<
"\n";
259 for (
u32 i = 0; i < lines.size(); i++) {
260 ss << shambase::format(
" {:2} : {}\n", i, lines[i]);
263 for (
auto &generator : _callstack_gen_info_generators) {
264 ss << generator() <<
"\n";
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Class Timer measures the time elapsed since the timer was started.
void start()
Starts the timer.
namespace for basic c++ utilities
std::string fmt_callstack()
Get the formatted callstack.
void add_entry_chrome(std::source_location loc, f64 time, bool is_start)
Add a Chrome tracing entry to the storage.
auto make_timer
Utility to create a timer and start it.
Timer global_timer
Wall time global timer.
void clear_chrome_entry()
Clear the Chrome tracing entries storage.
std::vector< ChromeProfileEntry > profile_data_chrome
Chrome tracing entries storage.
std::vector< ProfileEntry > profile_data
Vector to hold profiling entries.
This file contains the definition for the stacktrace related functionality.
std::stack< SourceLocation > call_stack
The call stack used to keep track of the stack trace. It is used to print the stack trace when an exc...
void 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 ...
void dump_profilings(const std::string &process_prefix, u32 world_rank)
Dump the profiling data in a JSON format to a file.
void 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 e...
f64 get_wtime()
Returns the current wall clock time in seconds.
void clear_profiling_data()
Clear the profiling data. (should be done in large run to avoid out-of-memory).
provide information about the source location
std::string format_one_line_func() const
format the location in a one liner with the function name displayed
Chrome tracing profile entry.
u64 time_val
Time value for the profile entry.
std::string name
Name of the profile entry.
bool is_start
Flag indicating if it is the start of the profile entry.
std::string format(u32 world_rank)
Format the Chrome profile entry.
Structure to hold data for a profiling entry.
f64 time_start
Start time of the profiling entry (in sec since program start).
std::string entry_name
Name of the profiling entry.
std::string format()
Format the profile entry as a JSON string.
f64 time_end
End time of the profiling entry (in sec since program start).