25#ifdef SHAMROCK_USE_NVTX
26 #include <nvtx3/nvtx3.hpp>
38auto get_profiling = []() {
39 const char *val = std::getenv(
"SHAM_PROFILING");
41 if (std::string(val) ==
"1") {
43 }
else if (std::string(val) ==
"0") {
51 const char *val = std::getenv(
"SHAM_PROF_USE_NVTX");
53 if (std::string(val) ==
"1") {
55 if (!get_profiling()) {
57 "-- SHAM_PROF_USE_NVTX is set to 1 but SHAM_PROFILING is not set to 1.\n"
58 " please set SHAM_PROFILING=1 before SHAM_PROF_USE_NVTX=1");
62 }
else if (std::string(val) ==
"0") {
69auto get_complete_event = []() {
70 const char *val = std::getenv(
"SHAM_PROF_USE_COMPLETE_EVENT");
72 if (std::string(val) ==
"1") {
74 }
else if (std::string(val) ==
"0") {
81auto get_threshold = []() {
82 const char *val = std::getenv(
"SHAM_PROF_EVENT_RECORD_THRES");
84 return std::stod(val);
89bool enable_profiling = get_profiling();
90bool use_complete_event = get_complete_event();
91f64 threshold = get_threshold();
92bool enable_nvtx = get_nvtx();
104 const std::optional<std::string> &name,
105 const std::optional<std::string> &category_name) {
107 if (enable_profiling) {
109 if (!use_complete_event) {
110 chrome::register_event_start(
111 src_loc_to_name(fileloc), fileloc.loc.
function_name(), t_start, 0, 0);
121 const std::optional<std::string> &name,
122 const std::optional<std::string> &category_name) {
124 if (enable_profiling) {
125 if (use_complete_event) {
126 if (tend - t_start > threshold) {
127 chrome::register_event_complete(
128 src_loc_to_name(fileloc), fileloc.loc.
function_name(), t_start, tend, 0, 0);
131 chrome::register_event_end(
132 src_loc_to_name(fileloc), fileloc.loc.
function_name(), tend, 0, 0);
140 const std::optional<std::string> &name,
141 const std::optional<std::string> &category_name) {
143 if (enable_profiling && enable_nvtx) {
144#ifdef SHAMROCK_USE_NVTX
153 const std::optional<std::string> &name,
154 const std::optional<std::string> &category_name) {
156 if (enable_profiling && enable_nvtx) {
157#ifdef SHAMROCK_USE_NVTX
166 if (enable_profiling) {
167 chrome::register_counter_val(0, time, name, val);
double f64
Alias for double.
void set_use_complete_event(bool use_complete_event)
Use complete event, or start and begin event in chrome tracing.
void set_event_record_threshold(f64 threshold)
Set the event record threshold.
bool is_profiling_enabled()
Check if profiling is enabled.
void stack_entry_start_no_time(const SourceLocation &fileloc, const std::optional< std::string > &name=std::nullopt, const std::optional< std::string > &category_name=std::nullopt)
Start a profiling event without a time info.
void set_enable_profiling(bool enable_profiling)
Set wether to enable profiling.
void register_counter_val(const std::string &name, f64 time, f64 val)
Register a counter value.
void set_enable_nvtx(bool enable_nvtx)
Set wether to enable NVTX profiling.
void stack_entry_end_no_time(const SourceLocation &fileloc, const std::optional< std::string > &name=std::nullopt, const std::optional< std::string > &category_name=std::nullopt)
End a profiling event without a time info.
void stack_entry_start(const SourceLocation &fileloc, f64 t_start, const std::optional< std::string > &name=std::nullopt, const std::optional< std::string > &category_name=std::nullopt)
Register the start of a profiling event.
void stack_entry_end(const SourceLocation &fileloc, f64 t_start, f64 tend, const std::optional< std::string > &name=std::nullopt, const std::optional< std::string > &category_name=std::nullopt)
Register the end of a profiling event.
provide information about the source location
constexpr const char * file_name() const noexcept
Returns the file name of the source location.
constexpr unsigned column() const noexcept
Returns the column offset of the source location.
constexpr unsigned line() const noexcept
Returns the line number of the source location.
constexpr const char * function_name() const noexcept
Returns the function name of the source location.