I criteri della specifica §9.11 (frame, blocchi del thread, riga aggiornata entro 100 ms, riconnessione sotto i 2 s, nessun ridisegno della griglia con maniglie e finestra) non li misurava nessuno. Ora il simulatore prende --simulatore-aste N (solo con --simulatore): N aste in elenco, tre su quattro in Attiva, ciclo di 5 s e due autopuntate senza fine per asta, così almeno dieci aste stanno sempre sotto i 4 s; senza l'argomento il simulatore resta quello di sempre. tools/Mimante.Schermate ha la modalità --misura <secondi>, tutta via CDP: uno script nella pagina cronometra frame, compiti dell'interfaccia (timer, frame, eventi del puntatore, ResizeObserver) e messaggi del bot, chiude il canale per la riconnessione, trascina la maniglia e ridimensiona la finestra controllando che i <tr data-id> restino gli stessi nodi, che la griglia non scorra né si virtualizzi e che anche lì nessun compito blocchi il thread; scrive misura.json e misura.txt ed esce con 1 se un criterio vincolante fallisce (anche un solo compito lungo del browser) o la misura non vale (basta un campione con meno di dieci aste in finestra critica; la CPU si riporta soltanto). La password può venire da UI_PASSWORD. prove-a-mano.yml ha il lavoro «prestazioni», dopo carico e schermate per non dividere la CPU, e il commento sul mondo del simulatore è corretto. Le prove dei conti della misura stanno in tests/Mimante.Tests con un riferimento a tools/Mimante.Schermate che esiste solo se la cartella c'è: il contesto dell'immagine non ha tools/ e lì quelle prove restano fuori, così la costruzione dell'immagine non si rompe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
189 lines
8.6 KiB
C#
189 lines
8.6 KiB
C#
namespace Mimante.Schermate.Misura;
|
|
|
|
/// <summary>
|
|
/// Lo strumento di misura dentro la pagina, messo con <c>Page.addScriptToEvaluateOnNewDocument</c> prima di ogni
|
|
/// altro script: <c>window.__mimantePerf</c>.
|
|
///
|
|
/// <list type="bullet">
|
|
/// <item>un ciclo di <c>requestAnimationFrame</c> che registra l'intervallo fra due frame (frame persi);</item>
|
|
/// <item>i compiti dell'interfaccia cronometrati uno per uno (i blocchi del thread): le funzioni passate a
|
|
/// <c>setTimeout</c>, <c>setInterval</c> e <c>requestAnimationFrame</c>, gli ascoltatori degli eventi del puntatore,
|
|
/// della rotella, dello scorrimento e della finestra (la maniglia di <c>split.js</c>), le funzioni dei
|
|
/// <c>ResizeObserver</c> e la gestione di ogni messaggio del bot;</item>
|
|
/// <item>un involucro di <c>window.WebSocket</c>: ogni <c>auction.delta</c> si cronometra dall'evento del messaggio
|
|
/// al primo frame dopo la sua gestione (ws.js → state.js → aste.js → grid.js aggiornano la riga in modo sincrono, e
|
|
/// quel frame è il primo che la mostra); <c>reconnect()</c> chiude il canale e misura fino al nuovo elenco
|
|
/// (<c>snapshot</c>) a schermo;</item>
|
|
/// <item>un <c>PerformanceObserver</c> dei compiti lunghi del browser (scatta solo sopra 50 ms, quindi prende anche
|
|
/// layout e stile che i cronometri non vedono): uno solo, in qualunque fase, fa fallire il criterio dei blocchi;</item>
|
|
/// <item><c>sample()</c> conta le aste in elenco e quelle in Attiva in finestra critica dallo stato della pagina
|
|
/// (<c>/js/state.js</c>, lo stesso modulo dell'interfaccia); <c>rows()</c> dà a ogni <c><tr data-id></c> un
|
|
/// segno, per riconoscere un nodo ridisegnato; <c>grid()</c> dice lo scorrimento, le righe disegnate e se la griglia
|
|
/// è virtualizzata.</item>
|
|
/// </list>
|
|
/// </summary>
|
|
public static class PerfScript
|
|
{
|
|
private const string Source = """
|
|
(() => {
|
|
if (window.__mimantePerf) return;
|
|
const now = () => performance.now();
|
|
const round = v => Math.round(v * 100) / 100;
|
|
const P = {
|
|
recording: false, frames: [], rowUpdates: [], handlers: [], tasks: [], longTasks: [],
|
|
pending: [], sockets: 0, socket: null, lastOpen: 0, reconnecting: null
|
|
};
|
|
|
|
// I compiti dell'interfaccia: ogni funzione data a un timer o a requestAnimationFrame, cronometrata. Gli id restano
|
|
// quelli del browser, quindi clearTimeout, clearInterval e cancelAnimationFrame non cambiano.
|
|
const nativeRaf = window.requestAnimationFrame.bind(window);
|
|
const timed = fn => function (...a) {
|
|
const s = now();
|
|
try { return fn.apply(this, a); }
|
|
finally { if (P.recording) P.tasks.push(round(now() - s)); }
|
|
};
|
|
for (const name of ['setTimeout', 'setInterval']) {
|
|
const native = window[name].bind(window);
|
|
window[name] = (fn, ...rest) => native(typeof fn === 'function' ? timed(fn) : fn, ...rest);
|
|
}
|
|
window.requestAnimationFrame = fn => nativeRaf(typeof fn === 'function' ? timed(fn) : fn);
|
|
|
|
// Gli ascoltatori del puntatore, della rotella, dello scorrimento e della finestra e le funzioni dei ResizeObserver:
|
|
// i compiti di maniglia e ridimensionamento. La stessa funzione ha sempre lo stesso involucro, così
|
|
// removeEventListener la ritrova (split.js toglie pointermove e pointerup a fine trascinamento).
|
|
const watched = /^(?:pointer|mouse)|^(?:wheel|scroll|resize)$/;
|
|
const wrappers = new WeakMap();
|
|
const wrapped = fn => { let w = wrappers.get(fn); if (!w) { w = timed(fn); wrappers.set(fn, w); } return w; };
|
|
const nativeAdd = EventTarget.prototype.addEventListener;
|
|
const nativeRemove = EventTarget.prototype.removeEventListener;
|
|
EventTarget.prototype.addEventListener = function (type, fn, ...rest) {
|
|
return nativeAdd.call(this, type, typeof fn === 'function' && watched.test(type) ? wrapped(fn) : fn, ...rest);
|
|
};
|
|
EventTarget.prototype.removeEventListener = function (type, fn, ...rest) {
|
|
return nativeRemove.call(this, type, typeof fn === 'function' && watched.test(type) ? (wrappers.get(fn) || fn) : fn, ...rest);
|
|
};
|
|
const NativeResizeObserver = window.ResizeObserver;
|
|
if (NativeResizeObserver) {
|
|
window.ResizeObserver = class extends NativeResizeObserver {
|
|
constructor(fn) { super(typeof fn === 'function' ? timed(fn) : fn); }
|
|
};
|
|
}
|
|
|
|
let last = 0;
|
|
const loop = t => {
|
|
if (P.recording && last > 0) P.frames.push(round(t - last));
|
|
last = t;
|
|
if (P.pending.length) {
|
|
const n = now();
|
|
for (const r of P.pending) { if (P.recording) P.rowUpdates.push(round(n - r.t0)); }
|
|
P.pending.length = 0;
|
|
}
|
|
const rc = P.reconnecting;
|
|
if (rc && rc.snapshotAt > 0) rc.done(now());
|
|
nativeRaf(loop);
|
|
};
|
|
nativeRaf(loop);
|
|
|
|
try {
|
|
new PerformanceObserver(list => {
|
|
if (!P.recording) return;
|
|
for (const e of list.getEntries()) P.longTasks.push(round(e.duration));
|
|
}).observe({ type: 'longtask' });
|
|
} catch { /* browser senza longtask */ }
|
|
|
|
const Native = window.WebSocket;
|
|
class PerfSocket extends Native {
|
|
constructor(...args) {
|
|
super(...args);
|
|
P.sockets++;
|
|
P.socket = this;
|
|
this.__perfIndex = P.sockets;
|
|
this.addEventListener('open', () => { P.lastOpen = now(); });
|
|
}
|
|
get onmessage() { return this.__perfHandler || null; }
|
|
set onmessage(fn) {
|
|
this.__perfHandler = fn;
|
|
super.onmessage = typeof fn !== 'function' ? fn : ev => {
|
|
const start = now();
|
|
const t0 = ev.timeStamp > 0 && ev.timeStamp <= start ? ev.timeStamp : start;
|
|
const m = typeof ev.data === 'string' ? /^\{"t":"([^"]+)"/.exec(ev.data) : null;
|
|
try { return fn.call(this, ev); }
|
|
finally {
|
|
const end = now();
|
|
const type = m ? m[1] : '';
|
|
if (P.recording) P.handlers.push(round(end - start));
|
|
if (type === 'auction.delta' && P.recording) P.pending.push({ t0 });
|
|
const rc = P.reconnecting;
|
|
if (type === 'snapshot' && rc && this.__perfIndex > rc.socketIndex && !rc.snapshotAt) rc.snapshotAt = end;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
window.WebSocket = PerfSocket;
|
|
|
|
let token = 0;
|
|
window.__mimantePerf = {
|
|
start() {
|
|
P.frames = []; P.rowUpdates = []; P.handlers = []; P.tasks = []; P.longTasks = []; P.pending = [];
|
|
last = 0;
|
|
P.recording = true;
|
|
return true;
|
|
},
|
|
take() {
|
|
P.recording = false;
|
|
const out = { frames: P.frames, rowUpdates: P.rowUpdates, handlers: P.handlers, tasks: P.tasks, longTasks: P.longTasks };
|
|
P.frames = []; P.rowUpdates = []; P.handlers = []; P.tasks = []; P.longTasks = [];
|
|
return out;
|
|
},
|
|
async sample() {
|
|
const { state, remainingMs } = await import('/js/state.js');
|
|
let listed = 0, active = 0, critical = 0;
|
|
for (const r of state.auctions.values()) {
|
|
listed++;
|
|
if (r.outcome || r.mode !== 'attiva') continue;
|
|
active++;
|
|
const ms = remainingMs(r);
|
|
if (ms != null && ms > 0 && ms < __CRITICAL_MS__) critical++;
|
|
}
|
|
const drawn = document.querySelectorAll('.aste-list tbody tr[data-id]').length;
|
|
return { listed, active, critical, drawn, connected: !!state.connected };
|
|
},
|
|
rows() {
|
|
return [...document.querySelectorAll('.aste-list tbody tr[data-id]')]
|
|
.map(tr => [tr.dataset.id, tr.__perfToken || (tr.__perfToken = ++token)]);
|
|
},
|
|
handle() {
|
|
const h = document.querySelector('.split .vsplit');
|
|
if (!h) return null;
|
|
const r = h.getBoundingClientRect();
|
|
const panel = document.querySelector('.split .panel');
|
|
return { x: r.left + r.width / 2, y: r.top + r.height / 2, panel: panel ? panel.getBoundingClientRect().width : 0 };
|
|
},
|
|
grid() {
|
|
const list = document.querySelector('.aste-list');
|
|
return {
|
|
scroll: list ? list.scrollTop : 0,
|
|
drawn: document.querySelectorAll('.aste-list tbody tr[data-id]').length,
|
|
virtual: !!document.querySelector('.aste-list tbody tr.spacer-row')
|
|
};
|
|
},
|
|
reconnect() {
|
|
return new Promise(resolve => {
|
|
const s = P.socket;
|
|
if (!s || s.readyState !== 1) { resolve({ ok: false, reason: 'canale non aperto' }); return; }
|
|
const rc = { start: now(), socketIndex: s.__perfIndex, snapshotAt: 0 };
|
|
const timer = setTimeout(() => { P.reconnecting = null; resolve({ ok: false, reason: 'nessun elenco nuovo entro 10 s' }); }, 10000);
|
|
rc.done = at => { clearTimeout(timer); P.reconnecting = null; resolve({ ok: true, ms: round(at - rc.start), openMs: round(P.lastOpen - rc.start) }); };
|
|
P.reconnecting = rc;
|
|
s.close();
|
|
});
|
|
}
|
|
};
|
|
})();
|
|
""";
|
|
|
|
/// <summary>Lo script con le soglie della misura.</summary>
|
|
public static string Build() =>
|
|
Source.Replace("__CRITICAL_MS__", PerfCriteria.CriticalMs.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
|
}
|