14 #if __has_include(<mlog/mlog.h>)
15 #include <mlog/mlog.h>
17 #define MLOG_BEGIN(...) ((void*)0)
19 #define MLOG_READ_ARG(buf, type) ((type){})
23 die(
"Trace profiler cannot be used because MassiveLogger is not loaded.");
82 return e->trace_decoder(stream, buf0, buf1);
92 fprintf(stream,
"%d,%lu,%d,%lu,%s\n", rank, t0, rank, t1,
str().c_str());
96 virtual std::string
str()
const {
return "UNKNOWN"; }
107 using msg_t = std::tuple<wallclock::wallclock_t, wallclock::wallclock_t, wallclock::wallclock_t, counter_t>;
152 printf(
" %-22s (rank %3d) : %10.6f %% ( %15ld ns / %15ld ns ) count: %10ld ave: %8ld ns max: %8ld ns\n",
154 (
double)sum_time / t_total * 100, sum_time, t_total,
155 count, count == 0 ? 0 : (sum_time / count), max_time);
162 printf(
" %-22s : %10.6f %% ( %15ld ns / %15ld ns ) count: %10ld ave: %8ld ns max: %8ld ns\n",
164 (
double)sum_time / t_total * 100, sum_time, t_total,
165 count, count == 0 ? 0 : (sum_time / count), max_time);
174 template <
typename Mode>
179 if constexpr (std::is_same_v<Mode, mode_trace>) {
181 trace_out_file_ = {std::fopen(trace_out_filename().c_str(),
"w"), &std::fclose};
186 events_.push_back(e);
197 if (last_phase_ !=
nullptr) {
199 last_phase_ =
nullptr;
204 if constexpr (std::is_same_v<Mode, mode_trace>) {
207 for (
auto&& e : events_) {
214 for (
auto&& e : events_) {
217 if constexpr (std::is_same_v<Mode, mode_trace>) {
224 template <
typename PhaseFrom,
typename PhaseTo>
231 if (last_phase_ ==
nullptr) {
232 phase_ibd_ = phase_from.interval_begin(Mode{}, state_.
t_begin);
237 phase_from.interval_end(Mode{}, t, phase_ibd_);
238 phase_ibd_ = phase_to.interval_begin(Mode{}, t);
239 last_phase_ = &phase_to;
244 static std::string trace_out_filename() {
245 std::stringstream ss;
250 std::vector<event*> events_;
251 profiler_state state_;
252 event* last_phase_ =
nullptr;
254 std::unique_ptr<FILE, int (*)(FILE*)> trace_out_file_ = {
nullptr,
nullptr};
263 template <
typename Event>
266 template <
typename... Args>
269 if (init_.should_finalize()) {
277 template <
typename Event,
typename... Args>
279 if constexpr (!std::is_same_v<mode, mode_disabled>) {
287 template <
typename Event,
typename... Args>
289 if constexpr (!std::is_same_v<mode, mode_disabled>) {
298 template <
typename Event>
301 template <
typename... Args>
303 ibd_ = interval_begin<Event>(std::forward<Args>(
args)...);
306 interval_end<Event>(ibd_);
319 #define ITYR_PROFILER_RECORD(event, ...) \
320 ityr::common::profiler::interval_scope<event> ITYR_ANON_VAR {__VA_ARGS__};
322 template <
typename PhaseFrom,
typename PhaseTo>
324 if constexpr (!std::is_same_v<mode, mode_disabled>) {
339 if constexpr (!std::is_same_v<mode, mode_disabled>) {
static value_type value()
Definition: options.hpp:62
Definition: profiler.hpp:264
event_initializer(Args &&... args)
Definition: profiler.hpp:267
Definition: profiler.hpp:53
mode_stats::interval_begin_data interval_begin(mode_stats, wallclock::wallclock_t t)
Definition: profiler.hpp:63
event(profiler_state &state)
Definition: profiler.hpp:55
virtual void print_stats_sum(wallclock::wallclock_t sum_time, wallclock::wallclock_t max_time, wallclock::wallclock_t t_total, counter_t count) const
Definition: profiler.hpp:158
virtual std::string str() const
Definition: profiler.hpp:96
void interval_end(mode_disabled, wallclock::wallclock_t, mode_disabled::interval_begin_data)
Definition: profiler.hpp:61
virtual void clear()
Definition: profiler.hpp:98
profiler_state & state_
Definition: profiler.hpp:168
mode_trace::interval_begin_data interval_begin(mode_trace, wallclock::wallclock_t t)
Definition: profiler.hpp:71
virtual void print_stats()
Definition: profiler.hpp:104
void interval_end(mode_trace, wallclock::wallclock_t t, mode_trace::interval_begin_data ibd)
Definition: profiler.hpp:76
void interval_end(mode_stats, wallclock::wallclock_t t, mode_stats::interval_begin_data ibd)
Definition: profiler.hpp:67
uint64_t counter_t
Definition: profiler.hpp:145
mode_stats::interval_begin_data interval_begin(mode_disabled, wallclock::wallclock_t)
Definition: profiler.hpp:60
static void * trace_decoder_base(FILE *stream, int, int, void *buf0, void *buf1)
Definition: profiler.hpp:80
virtual void print_stats_per_rank(topology::rank_t rank, wallclock::wallclock_t sum_time, wallclock::wallclock_t max_time, wallclock::wallclock_t t_total, counter_t count) const
Definition: profiler.hpp:147
wallclock::wallclock_t sum_time_
Definition: profiler.hpp:169
counter_t count_
Definition: profiler.hpp:171
void do_acc(wallclock::wallclock_t t)
Definition: profiler.hpp:139
wallclock::wallclock_t max_time_
Definition: profiler.hpp:170
virtual void * trace_decoder(FILE *stream, void *buf0, void *buf1)
Definition: profiler.hpp:85
Definition: profiler.hpp:299
interval_scope & operator=(interval_scope &&)=delete
interval_scope & operator=(const interval_scope &)=delete
interval_scope(interval_scope &&)=delete
~interval_scope()
Definition: profiler.hpp:305
interval_scope(const interval_scope &)=delete
interval_scope(Args &&... args)
Definition: profiler.hpp:302
Definition: profiler.hpp:175
void begin()
Definition: profiler.hpp:189
profiler()
Definition: profiler.hpp:177
profiler_state & get_state()
Definition: profiler.hpp:222
void add(event *e)
Definition: profiler.hpp:185
void flush()
Definition: profiler.hpp:203
void end()
Definition: profiler.hpp:194
void switch_phase()
Definition: profiler.hpp:225
static auto & get()
Definition: util.hpp:180
#define ITYR_PROFILER_MODE
#define ITYR_CONCAT(x, y)
Definition: util.hpp:20
#define ITYR_CHECK(cond)
Definition: util.hpp:48
Definition: profiler.hpp:20
void switch_phase()
Definition: profiler.hpp:323
mode::interval_begin_data interval_begin_data
Definition: profiler.hpp:261
void end()
Definition: profiler.hpp:334
ITYR_CONCAT(mode_, ITYR_PROFILER_MODE) mode
Definition: profiler.hpp:257
void * mlog_data_t
Definition: profiler.hpp:21
void mlog_die()
Definition: profiler.hpp:22
void interval_end(interval_begin_data ibd, Args &&... args)
Definition: profiler.hpp:288
void begin()
Definition: profiler.hpp:329
void mlog_init(void **, int, size_t)
Definition: profiler.hpp:25
interval_begin_data interval_begin(Args &&... args)
Definition: profiler.hpp:278
void flush()
Definition: profiler.hpp:338
void mlog_flush_all(void **, FILE *)
Definition: profiler.hpp:26
void mlog_clear_all(void **)
Definition: profiler.hpp:27
rank_t n_ranks()
Definition: topology.hpp:208
int rank_t
Definition: topology.hpp:12
MPI_Comm mpicomm()
Definition: topology.hpp:206
rank_t my_rank()
Definition: topology.hpp:207
uint64_t wallclock_t
Definition: wallclock.hpp:13
wallclock_t gettime_ns()
Definition: wallclock.hpp:88
va_list args
Definition: util.hpp:76
fprintf(stderr, "\x1b[31m%s\x1b[39m\n", msg)
T mpi_reduce_value(const T &value, int root_rank, MPI_Comm comm, MPI_Op op=MPI_SUM)
Definition: mpi_util.hpp:170
void mpi_barrier(MPI_Comm comm)
Definition: mpi_util.hpp:42
void mpi_send_value(const T &value, int target_rank, int tag, MPI_Comm comm)
Definition: mpi_util.hpp:84
void get(global_ptr< ConstT > from_ptr, T *to_ptr, std::size_t count)
Definition: ori.hpp:80
monoid< T, max_functor<>, lowest< T > > max
Definition: reducer.hpp:104
#define MLOG_BEGIN(...)
Definition: profiler.hpp:17
#define MLOG_READ_ARG(buf, type)
Definition: profiler.hpp:19
#define MLOG_END(...)
Definition: profiler.hpp:18
Definition: profiler.hpp:33
void * interval_begin_data
Definition: profiler.hpp:34
Definition: profiler.hpp:37
wallclock::wallclock_t interval_begin_data
Definition: profiler.hpp:38
Definition: profiler.hpp:41
void * interval_begin_data
Definition: profiler.hpp:42
Definition: profiler.hpp:45
bool output_per_rank
Definition: profiler.hpp:49
bool enabled
Definition: profiler.hpp:46
wallclock::wallclock_t t_end
Definition: profiler.hpp:48
wallclock::wallclock_t t_begin
Definition: profiler.hpp:47
mlog_data_t trace_md
Definition: profiler.hpp:50