use std::time::Instant;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct PhaseStats {
pub rebucket_ns: u64,
pub prepare_ns: u64,
pub rescale_ns: u64,
pub span_plan_ns: u64,
pub permute_ns: u64,
pub coset_loop_ns: u64,
pub unpermute_ns: u64,
pub recount_ns: u64,
pub finalize_ns: u64,
pub collective_ns: u64,
pub export_ns: u64,
pub exchange_ns: u64,
pub swap_ns: u64,
pub size_ns: u64,
pub gather_ns: u64,
pub sort_ns: u64,
pub merge_ns: u64,
pub clear_ns: u64,
pub layers: u64,
pub cosets: u64,
pub runs: u64,
pub rows_gathered: u64,
pub rows_sorted: u64,
pub rows_id: u64,
pub terms_in: u64,
pub terms_out: u64,
pub rows_exported: u64,
pub recv_rows: u64,
pub append_ns: u64,
pub chunk_wait_ns: u64,
pub compact_ns: u64,
pub h2d_ns: u64,
pub d2h_ns: u64,
pub truncate_ns: u64,
pub export_kernel_ns: u64,
}
impl PhaseStats {
pub fn add(&mut self, other: &PhaseStats) {
self.rebucket_ns += other.rebucket_ns;
self.prepare_ns += other.prepare_ns;
self.rescale_ns += other.rescale_ns;
self.span_plan_ns += other.span_plan_ns;
self.permute_ns += other.permute_ns;
self.coset_loop_ns += other.coset_loop_ns;
self.unpermute_ns += other.unpermute_ns;
self.recount_ns += other.recount_ns;
self.finalize_ns += other.finalize_ns;
self.collective_ns += other.collective_ns;
self.export_ns += other.export_ns;
self.exchange_ns += other.exchange_ns;
self.swap_ns += other.swap_ns;
self.size_ns += other.size_ns;
self.gather_ns += other.gather_ns;
self.sort_ns += other.sort_ns;
self.merge_ns += other.merge_ns;
self.clear_ns += other.clear_ns;
self.layers += other.layers;
self.cosets += other.cosets;
self.runs += other.runs;
self.rows_gathered += other.rows_gathered;
self.rows_sorted += other.rows_sorted;
self.rows_id += other.rows_id;
self.terms_in += other.terms_in;
self.terms_out += other.terms_out;
self.rows_exported += other.rows_exported;
self.recv_rows += other.recv_rows;
self.append_ns += other.append_ns;
self.chunk_wait_ns += other.chunk_wait_ns;
self.compact_ns += other.compact_ns;
self.h2d_ns += other.h2d_ns;
self.d2h_ns += other.d2h_ns;
self.truncate_ns += other.truncate_ns;
self.export_kernel_ns += other.export_kernel_ns;
}
pub(crate) fn absorb_coset(&mut self, coset: &CosetStats) {
self.swap_ns += coset.swap_ns;
self.size_ns += coset.size_ns;
self.gather_ns += coset.gather_ns;
self.sort_ns += coset.sort_ns;
self.merge_ns += coset.merge_ns;
self.clear_ns += coset.clear_ns;
self.cosets += coset.cosets;
self.runs += coset.runs;
self.rows_gathered += coset.rows_gathered;
self.rows_sorted += coset.rows_sorted;
self.rows_id += coset.rows_id;
}
pub fn wall_total_ns(&self) -> u64 {
self.rebucket_ns
+ self.prepare_ns
+ self.rescale_ns
+ self.span_plan_ns
+ self.permute_ns
+ self.coset_loop_ns
+ self.unpermute_ns
+ self.recount_ns
+ self.finalize_ns
+ self.collective_ns
+ self.export_ns
+ self.exchange_ns
}
pub fn busy_total_ns(&self) -> u64 {
self.swap_ns
+ self.size_ns
+ self.gather_ns
+ self.sort_ns
+ self.merge_ns
+ self.clear_ns
+ self.compact_ns
}
pub fn timer_reads(&self) -> u64 {
11 * self.layers + 5 * self.cosets + 2 * self.runs
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct PartitionPhaseStats {
pub per_partition: Vec<PhaseStats>,
pub scatter_ns: u64,
pub gather_ns: u64,
pub layers: u64,
}
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct CosetStats {
pub(crate) swap_ns: u64,
pub(crate) size_ns: u64,
pub(crate) gather_ns: u64,
pub(crate) sort_ns: u64,
pub(crate) merge_ns: u64,
pub(crate) clear_ns: u64,
pub(crate) cosets: u64,
pub(crate) runs: u64,
pub(crate) rows_gathered: u64,
pub(crate) rows_sorted: u64,
pub(crate) rows_id: u64,
}
pub(crate) struct Stamp(Instant);
impl Stamp {
pub(crate) fn now() -> Self {
Stamp(Instant::now())
}
pub(crate) fn lap(&mut self, slot: &mut u64) {
let now = Instant::now();
*slot += now.duration_since(self.0).as_nanos() as u64;
self.0 = now;
}
pub(crate) fn rearm(&mut self) {
self.0 = Instant::now();
}
}