xo-imgui: ex2: + average efficiency + plot

This commit is contained in:
Roland Conybeare 2025-08-24 17:03:04 -04:00
commit 4c824edbe4
2 changed files with 45 additions and 12 deletions

View file

@ -163,17 +163,23 @@ namespace xo {
std::size_t garbage0_z,
std::size_t garbage1_z,
std::size_t garbageN_z,
nanos dt) : gc_seq_{gc_seq},
upto_{upto},
new_alloc_z_{new_alloc_z},
survive_z_{survive_z},
promote_z_{promote_z},
persist_z_{persist_z},
effort_z_{effort_z},
garbage0_z_{garbage0_z},
garbage1_z_{garbage1_z},
garbageN_z_{garbageN_z},
dt_{dt} {}
nanos dt,
std::size_t sum_effort_z,
std::size_t sum_garbage_z)
: gc_seq_{gc_seq},
upto_{upto},
new_alloc_z_{new_alloc_z},
survive_z_{survive_z},
promote_z_{promote_z},
persist_z_{persist_z},
effort_z_{effort_z},
garbage0_z_{garbage0_z},
garbage1_z_{garbage1_z},
garbageN_z_{garbageN_z},
dt_{dt},
sum_effort_z_{sum_effort_z},
sum_garbage_z_{sum_garbage_z}
{}
constexpr GcStatisticsHistoryItem(const GcStatisticsHistoryItem &) = default;
std::size_t garbage_z() const { return garbage0_z_ + garbage1_z_ + garbageN_z_; }
@ -184,6 +190,11 @@ namespace xo {
return gz / static_cast<float>(effort_z_ + gz);
}
/** lifetime byte-weighted average collection efficiency. Always in [0.0, 1.0] **/
float average_efficiency() const {
return sum_garbage_z_ / static_cast<float>(sum_effort_z_ + sum_garbage_z_);
}
/** collection rate, in bytes/sec **/
float collection_rate() const;
@ -199,6 +210,10 @@ namespace xo {
garbage1_z_ = x.garbage1_z_;
garbageN_z_ = x.garbageN_z_;
this->dt_.scale_ = x.dt_.scale_;
sum_effort_z_ = x.sum_effort_z_;
sum_garbage_z_ = x.sum_garbage_z_;
return *this;
}
@ -229,6 +244,13 @@ namespace xo {
std::size_t garbageN_z_ = 0;
/** elapsed time for this GC (see @ref GC::execute_gc) **/
nanos dt_;
// ----- cumulative statistics -----
/** sum (in bytes) copied by collections since inception **/
std::size_t sum_effort_z_ = 0;
/** sum (in bytes) of garbage collected since inception **/
std::size_t sum_garbage_z_ = 0;
};
inline std::ostream & operator<< (std::ostream & os, const GcStatisticsHistoryItem & x) {

View file

@ -1119,6 +1119,15 @@ namespace xo {
// still want to update tenured stats for current alloc size
this->gc_statistics_.update_snapshot(generation::tenured, T_after_gc);
}
std::size_t sum_effort_z = effort_z;
std::size_t sum_garbage_z = garbage0_z + garbage1_z + garbageN_z;
if (gc_history_.size() > 0) {
sum_effort_z += gc_history_.back().sum_effort_z_;
sum_garbage_z += gc_history_.back().sum_garbage_z_;
}
GcStatisticsHistoryItem item(gc_statistics_.n_gc(),
upto,
new_alloc_z,
@ -1129,7 +1138,9 @@ namespace xo {
garbage0_z,
garbage1_z,
garbageN_z,
dt);
dt,
sum_effort_z,
sum_garbage_z);
log && log(xtag("gcseq_after_gc", gc_statistics_.n_gc()),
xtag("item", item));