10#include <unordered_set>
30 {
"2D",
"faces"}, {
"2D",
"cells"}, {
"2D",
"rebuild"}, {
"2D",
"boundary"},
31 {
"2D",
"exchange"}, {
"2D",
"publish"}, {
"2D",
"species_faces"},
32 {
"2D",
"species_cells"}, {
"2D",
"reactions"},
33 {
"GW2D",
"faces"}, {
"GW2D",
"cells"}, {
"GW2D",
"node_exchange"},
34 {
"GW2D",
"refresh_dt"}, {
"GW2D",
"infiltration"}, {
"GW2D",
"species"},
35 {
"GW2D",
"reactions"}, {
"GW2D",
"sigma_map"}, {
"GW2D",
"heat_columns"},
36 {
"2D",
"quality"}, {
"HYD",
"runoff"}, {
"HYD",
"groundwater"}, {
"HYD",
"lid"},
37 {
"HYD",
"lid_nodes"}, {
"HYD",
"richards"}, {
"HYD",
"mesh_snow"},
38 {
"HYD",
"subcatch_snow"}, {
"HYD",
"common_source"}, {
"HYD",
"source_trial"},
39 {
"HYD",
"outfall"}, {
"HYD",
"source_results"}, {
"HYD",
"engine_source_results"}
59 dlsym(RTLD_DEFAULT,
"openswmm_perf_malloc_snapshot"));
72 "sigma.evaluate",
"sigma.firings",
"sigma.hist.le1",
"sigma.hist.2_8",
73 "sigma.hist.9_32",
"sigma.hist.33_64",
"sigma.hist.gt64",
"sigma_map.refresh",
74 "copy.water_trial",
"copy.source_stage",
"copy.rk2_snapshot",
"copy.mesh_snow"
80 process_counts[std::size_t(counter)].fetch_add(n, std::memory_order_relaxed);
83 return process_counts[std::size_t(counter)].load(std::memory_order_relaxed);
92 std::optional<GatedTimer> timer_;
94 std::uint64_t allocations_begin_ = 0, bytes_begin_ = 0;
99 if (allocations_) allocations_(&allocations_begin_, &bytes_begin_);
100 timer_.emplace(seconds_);
110 std::uint64_t calls = 0, bytes = 0;
111 allocations_(&calls, &bytes);
112 process_allocations[std::size_t(phase_)].fetch_add(calls - allocations_begin_, std::memory_order_relaxed);
116 double old = total.load(std::memory_order_relaxed);
117 while (!total.compare_exchange_weak(old, old + seconds_, std::memory_order_relaxed)) {}
118 process_calls[std::size_t(phase_)].fetch_add(1, std::memory_order_relaxed);
143 for (
auto& seconds :
process_seconds) seconds.store(0, std::memory_order_relaxed);
144 for (
auto& calls :
process_calls) calls.store(0, std::memory_order_relaxed);
176 std::fprintf(stderr,
"[PERF-PROCESS-INVALID] reason=tracking_failed\n");
181 std::fprintf(stderr,
"[PERF-PROCESS-INVALID] reason=overlapping_engine_lifetimes\n");
184 for (
const char* group : {
"2D",
"GW2D",
"HYD"}) {
189 std::fprintf(stderr,
"[PERF-%s]", group);
191 if (std::string_view(
process_names[i].group) != group)
continue;
192 std::fprintf(stderr,
" %s=%.9f n.%s=%llu",
process_names[i].key,
195 std::fprintf(stderr,
"\n");
200 std::fprintf(stderr,
"[PERF-PROCESS-COUNTS]");
203 std::fprintf(stderr,
"\n");
206 std::fprintf(stderr,
"[PERF-ALLOC] inclusive=1 calling_thread=1");
209 std::fprintf(stderr,
" %s.%s.calls=%llu %s.%s.bytes=%llu",
212 std::fprintf(stderr,
"\n");
Performance timing and phase accumulators for engine execution.
void stop() noexcept
Definition ProcessPerf.hpp:103
ProcessTimer(ProcessPhase phase) noexcept
Definition ProcessPerf.hpp:96
~ProcessTimer() noexcept
Definition ProcessPerf.hpp:120
ProcessTimer & operator=(const ProcessTimer &)=delete
ProcessTimer(const ProcessTimer &)=delete
Definition PerfTimers.hpp:26
ProcessCounter
Definition ProcessPerf.hpp:66
@ water_trial_copies
Definition ProcessPerf.hpp:68
@ rk2_snapshots
Definition ProcessPerf.hpp:69
@ sigma_le_8
Definition ProcessPerf.hpp:67
@ sigma_gt_64
Definition ProcessPerf.hpp:68
@ mesh_snow_copies
Definition ProcessPerf.hpp:69
@ sigma_evaluations
Definition ProcessPerf.hpp:67
@ sigma_le_32
Definition ProcessPerf.hpp:67
@ sigma_firings
Definition ProcessPerf.hpp:67
@ source_stage_copies
Definition ProcessPerf.hpp:69
@ sigma_le_1
Definition ProcessPerf.hpp:67
@ count
Definition ProcessPerf.hpp:69
@ sigma_map_refreshes
Definition ProcessPerf.hpp:68
@ sigma_le_64
Definition ProcessPerf.hpp:68
long value(FvCounter counter) noexcept
Read one process-global completed FV counter total.
Definition PerfTimers.hpp:136
std::array< std::atomic< unsigned long long >, std::size_t(ProcessCounter::count)> process_counts
Definition ProcessPerf.hpp:76
std::array< std::atomic< double >, std::size_t(ProcessPhase::count)> process_seconds
Definition ProcessPerf.hpp:41
void reset_process() noexcept
Definition ProcessPerf.hpp:150
constexpr std::array< ProcessPhaseName, std::size_t(ProcessPhase::count)> process_names
Definition ProcessPerf.hpp:29
std::array< std::atomic< unsigned long long >, std::size_t(ProcessPhase::count)> process_allocations
Definition ProcessPerf.hpp:43
void end_process_model(const void *model, bool report=true) noexcept
Definition ProcessPerf.hpp:215
bool process_tracking_failed
Definition ProcessPerf.hpp:50
bool enabled() noexcept
Read the process-cached profiling environment gate.
Definition PerfTimers.hpp:238
void clear_process_totals() noexcept
Definition ProcessPerf.hpp:142
std::atomic< bool > process_attribution_valid
Definition ProcessPerf.hpp:47
std::array< std::atomic< unsigned long long >, std::size_t(ProcessPhase::count)> process_calls
Definition ProcessPerf.hpp:42
void begin_process_model(const void *model) noexcept
Definition ProcessPerf.hpp:159
constexpr std::array< const char *, std::size_t(ProcessCounter::count)> process_counter_names
Definition ProcessPerf.hpp:71
void(*)(std::uint64_t *, std::uint64_t *) AllocationSnapshot
Definition ProcessPerf.hpp:55
void dump_process() noexcept
Definition ProcessPerf.hpp:179
ProcessPhase
Definition ProcessPerf.hpp:19
@ surface_cells
Definition ProcessPerf.hpp:20
@ gw_reactions
Definition ProcessPerf.hpp:23
@ gw_infiltration
Definition ProcessPerf.hpp:22
@ surface_boundary
Definition ProcessPerf.hpp:20
@ lid_nodes
Definition ProcessPerf.hpp:24
@ gw_faces
Definition ProcessPerf.hpp:22
@ common_source
Definition ProcessPerf.hpp:25
@ gw_dt
Definition ProcessPerf.hpp:22
@ surface_faces
Definition ProcessPerf.hpp:20
@ gw_cells
Definition ProcessPerf.hpp:22
@ groundwater
Definition ProcessPerf.hpp:24
@ gw_sigma_map
Definition ProcessPerf.hpp:23
@ source_results
Definition ProcessPerf.hpp:25
@ gw_node_exchange
Definition ProcessPerf.hpp:22
@ gw_species
Definition ProcessPerf.hpp:23
@ surface_rebuild
Definition ProcessPerf.hpp:20
@ heat_columns
Definition ProcessPerf.hpp:23
@ surface_quality
Definition ProcessPerf.hpp:23
@ surface_species_cells
Definition ProcessPerf.hpp:21
@ lid
Definition ProcessPerf.hpp:24
@ mesh_snow
Definition ProcessPerf.hpp:24
@ richards
Definition ProcessPerf.hpp:24
@ surface_species
Definition ProcessPerf.hpp:21
@ surface_reactions
Definition ProcessPerf.hpp:21
@ engine_source_results
Definition ProcessPerf.hpp:25
@ source_trial
Definition ProcessPerf.hpp:25
@ count
Definition ProcessPerf.hpp:26
@ outfall
Definition ProcessPerf.hpp:25
@ surface_publish
Definition ProcessPerf.hpp:21
@ surface_exchange
Definition ProcessPerf.hpp:21
@ runoff
Definition ProcessPerf.hpp:24
@ subcatch_snow
Definition ProcessPerf.hpp:24
void count(FvCounter counter, long n=1) noexcept
Accumulate a batch of events into worker-private or serial global counters.
Definition PerfTimers.hpp:480
AllocationSnapshot allocation_snapshot() noexcept
Definition ProcessPerf.hpp:56
std::array< std::atomic< unsigned long long >, std::size_t(ProcessPhase::count)> process_allocated_bytes
Definition ProcessPerf.hpp:44
std::unordered_set< const void * > process_models
Definition ProcessPerf.hpp:49
std::mutex process_models_mutex
Definition ProcessPerf.hpp:48
Definition ProcessPerf.hpp:28
const char * key
Definition ProcessPerf.hpp:28
const char * group
Definition ProcessPerf.hpp:28
Definition ProcessPerf.hpp:127
unsigned long long evaluations
Definition ProcessPerf.hpp:128
void evaluate() noexcept
Definition ProcessPerf.hpp:129
~SigmaEvaluations() noexcept
Definition ProcessPerf.hpp:130