mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:22:39 +00:00
Gate the counters on the testing feature
This commit is contained in:
@@ -27,6 +27,7 @@ pub(crate) fn measure_content<C: Component>(
|
||||
value: Option<&ValueOf<C>>,
|
||||
) -> (Vec2, Inputs) {
|
||||
let cx = measure_cx::<C>(input, style, resolved, value);
|
||||
#[cfg(feature = "testing")]
|
||||
crate::runtime::measure::count_measure_ask(input.ui.ctx(), std::any::type_name::<C>());
|
||||
layout_memory::measure_call(input.ui.ctx(), || comp.measure(&cx))
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ pub(crate) fn show(ui: &mut Ui, edit: Edit<'_>) -> Shown {
|
||||
}
|
||||
None => job.append(text, 0.0, plain),
|
||||
}
|
||||
#[cfg(feature = "testing")]
|
||||
crate::runtime::measure::count_text_layout(ui.ctx());
|
||||
ui.fonts_mut(|fonts| crate::runtime::egui::text_layout::layout_with(fonts, job))
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ use std::sync::Arc;
|
||||
/// different logical heights at different interface scales (14.5 at scale 2, 15 at scale 1), and a wrapped text would
|
||||
/// change height with the scale.
|
||||
pub(crate) fn layout(ctx: &Context, job: LayoutJob) -> Arc<Galley> {
|
||||
#[cfg(feature = "testing")]
|
||||
crate::runtime::measure::count_text_layout(ctx);
|
||||
ctx.fonts_mut(|fonts| layout_with(fonts, job))
|
||||
}
|
||||
|
||||
@@ -256,6 +256,7 @@ pub(crate) fn decide(ctx: &Context, id: Id, view: &View, at: impl FnOnce(Vec2) -
|
||||
};
|
||||
if skip { Decision::Skip(size) } else { Decision::Run }
|
||||
});
|
||||
#[cfg(feature = "testing")]
|
||||
if matches!(decision, Decision::Skip(_)) {
|
||||
crate::runtime::measure::count_settle(ctx, id, crate::runtime::measure::Settle::OutOfView);
|
||||
}
|
||||
@@ -302,17 +303,11 @@ pub(crate) fn replay(ctx: &Context, id: Id) {
|
||||
/// - for a child with no content version: no input other than pointer motion this frame or the one before;
|
||||
/// - the run did nothing a replay cannot repeat (`runtime::replay`).
|
||||
pub(crate) fn settled(ctx: &Context, owner: Option<Id>, id: Id, sizing: bool, place: Option<Place>, content: Option<u64>) -> Option<Vec2> {
|
||||
use crate::runtime::measure::{Settle, count_memo_key_bytes, count_settle};
|
||||
// The 8 bytes of a keyed call's content version are the key fed in.
|
||||
// Keyed calls feed their 8-byte content version into the key.
|
||||
#[cfg(feature = "testing")]
|
||||
if content.is_some() {
|
||||
count_memo_key_bytes(ctx, 8);
|
||||
crate::runtime::measure::count_memo_key_bytes(ctx, 8);
|
||||
}
|
||||
let size = decide_settled(ctx, owner, id, sizing, place, content);
|
||||
count_settle(ctx, id, if size.is_some() { Settle::Replayed } else { Settle::Ran });
|
||||
size
|
||||
}
|
||||
|
||||
fn decide_settled(ctx: &Context, owner: Option<Id>, id: Id, sizing: bool, place: Option<Place>, content: Option<u64>) -> Option<Vec2> {
|
||||
let input = ctx.input(|input| {
|
||||
input.events.iter().any(|event| !matches!(event, egui::Event::PointerMoved(_) | egui::Event::MouseMoved(_) | egui::Event::PointerGone))
|
||||
});
|
||||
@@ -355,15 +350,23 @@ fn decide_settled(ctx: &Context, owner: Option<Id>, id: Id, sizing: bool, place:
|
||||
settled.map(|settled| (entry.sizes[kind].or(entry.sizes[1 - kind]).unwrap_or(settled.rect.size()), settled))
|
||||
});
|
||||
// The pointer over it, or a press that started on it, is read outside the store.
|
||||
let (size, settled) = settled?;
|
||||
let Some((size, settled)) = settled else {
|
||||
#[cfg(feature = "testing")]
|
||||
crate::runtime::measure::count_settle(ctx, id, crate::runtime::measure::Settle::Ran);
|
||||
return None;
|
||||
};
|
||||
if engaged(ctx, &settled) {
|
||||
with(ctx, |store, pass_nr, _| {
|
||||
if let Some(entry) = store.entries.get_mut(&id) {
|
||||
entry.replays = Some((pass_nr, false));
|
||||
}
|
||||
});
|
||||
#[cfg(feature = "testing")]
|
||||
crate::runtime::measure::count_settle(ctx, id, crate::runtime::measure::Settle::Ran);
|
||||
return None;
|
||||
}
|
||||
#[cfg(feature = "testing")]
|
||||
crate::runtime::measure::count_settle(ctx, id, crate::runtime::measure::Settle::Replayed);
|
||||
Some(size)
|
||||
}
|
||||
|
||||
|
||||
@@ -328,19 +328,15 @@ struct SettleLog {
|
||||
|
||||
/// Counts the decision about the settling child `id` in this pass. Fed by `lazy::settled` (ran, replayed) and
|
||||
/// `lazy::decide` (out of view); a rename of that decision point moves both calls.
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn count_settle(ctx: &Context, id: Id, what: Settle) {
|
||||
#[cfg(feature = "testing")]
|
||||
{
|
||||
let pass = ctx.cumulative_pass_nr();
|
||||
store::with::<SettleLog, _>(ctx, |log| {
|
||||
if log.pass != pass {
|
||||
*log = SettleLog { pass, decisions: Vec::new() };
|
||||
}
|
||||
log.decisions.push((id, what));
|
||||
});
|
||||
}
|
||||
#[cfg(not(feature = "testing"))]
|
||||
let _ = (ctx, id, what);
|
||||
let pass = ctx.cumulative_pass_nr();
|
||||
store::with::<SettleLog, _>(ctx, |log| {
|
||||
if log.pass != pass {
|
||||
*log = SettleLog { pass, decisions: Vec::new() };
|
||||
}
|
||||
log.decisions.push((id, what));
|
||||
});
|
||||
}
|
||||
|
||||
/// The settled-test decisions of the last pass, by child id, in the order they were made; empty when that pass made none.
|
||||
@@ -377,12 +373,11 @@ fn last_totals<R>(ctx: &Context, f: impl FnOnce(&PassTotals) -> R, none: R) -> R
|
||||
store::with::<PassTotals, _>(ctx, |log| if log.pass == last { f(log) } else { none })
|
||||
}
|
||||
|
||||
/// Counts `bytes` fed into a memo key in this pass. Fed by `MemoKey`.
|
||||
/// Counts `bytes` fed into a memo key in this pass. Fed by `MemoKey`; until it exists, by `lazy::settled` (8 bytes
|
||||
/// per call with a content version).
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn count_memo_key_bytes(ctx: &Context, bytes: usize) {
|
||||
#[cfg(feature = "testing")]
|
||||
totals(ctx, |log| log.key_bytes += bytes);
|
||||
#[cfg(not(feature = "testing"))]
|
||||
let _ = (ctx, bytes);
|
||||
}
|
||||
|
||||
/// The bytes fed into memo keys in the last pass.
|
||||
@@ -392,11 +387,9 @@ pub fn last_pass_memo_key_bytes(ctx: &Context) -> usize {
|
||||
}
|
||||
|
||||
/// Counts a text layout handed to egui (`text_layout::layout`, `layout_with`) in this pass.
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn count_text_layout(ctx: &Context) {
|
||||
#[cfg(feature = "testing")]
|
||||
totals(ctx, |log| log.text_layouts += 1);
|
||||
#[cfg(not(feature = "testing"))]
|
||||
let _ = ctx;
|
||||
}
|
||||
|
||||
/// The text layouts handed to egui in the last pass.
|
||||
@@ -406,14 +399,12 @@ pub fn last_pass_text_layouts(ctx: &Context) -> u32 {
|
||||
}
|
||||
|
||||
/// Counts a measure call of a leaf component of the type `name` in this pass.
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn count_measure_ask(ctx: &Context, name: &'static str) {
|
||||
#[cfg(feature = "testing")]
|
||||
totals(ctx, |log| match log.asks.iter_mut().find(|(ty, _)| *ty == name) {
|
||||
Some((_, count)) => *count += 1,
|
||||
None => log.asks.push((name, 1)),
|
||||
});
|
||||
#[cfg(not(feature = "testing"))]
|
||||
let _ = (ctx, name);
|
||||
}
|
||||
|
||||
/// The leaf types that were asked to measure in the last pass, and how many times each.
|
||||
|
||||
Reference in New Issue
Block a user