let autoRefreshInterval = null; function refreshImage() { const img = document.getElementById('gradientImage'); img.classList.add('loading'); const timestamp = new Date().getTime(); //img.src = 'gradient.jxl?' + timestamp; img.src = './output/gradient.jxl'; img.onload = function() { img.classList.remove('loading'); updateStatus('Image refreshed at ' + new Date().toLocaleTimeString()); }; img.onerror = function() { img.classList.remove('loading'); updateStatus('Error loading image', 'error'); }; } function toggleAutoRefresh() { const button = document.getElementById('autoRefreshBtn'); if (autoRefreshInterval) { clearInterval(autoRefreshInterval); autoRefreshInterval = null; button.textContent = 'Start Auto-Refresh (30s)'; button.classList.remove('danger'); updateStatus('Auto-refresh stopped'); } else { autoRefreshInterval = setInterval(refreshImage, 30000); button.textContent = 'Stop Auto-Refresh'; button.classList.add('danger'); updateStatus('Auto-refresh started (30s interval)'); } } function showStats() { fetch('/api/timing-stats') .then(response => response.json()) .then(data => { displayStats(data); document.getElementById('statsPanel').style.display = 'block'; }) .catch(error => { console.error('Error fetching stats:', error); updateStatus('Error loading stats', 'error'); }); } function hideStats() { document.getElementById('statsPanel').style.display = 'none'; } function clearStats() { fetch('/api/clear-stats', { method: 'POST' }) .then(response => response.json()) .then(data => { updateStatus('Statistics cleared'); hideStats(); }) .catch(error => { console.error('Error clearing stats:', error); updateStatus('Error clearing stats', 'error'); }); } function displayStats(stats) { const statsContent = document.getElementById('statsContent'); if (stats.length === 0) { statsContent.innerHTML = '
No timing data available.
'; return; } let html = '| Function | Calls | Total (s) | Avg (s) | Min (s) | Max (s) | Median (s) | P90 (s) | P95 (s) | P99 (s) |
|---|---|---|---|---|---|---|---|---|---|
| ${stat.function} | ${stat.call_count} | ${parseFloat(stat.total_time).toFixed(6)} | ${parseFloat(stat.avg_time).toFixed(6)} | ${parseFloat(stat.min_time).toFixed(6)} | ${parseFloat(stat.max_time).toFixed(6)} | ${parseFloat(stat.median_time).toFixed(6)} | ${parseFloat(stat.p90_time).toFixed(6)} | ${parseFloat(stat.p95_time).toFixed(6)} | ${parseFloat(stat.p99_time).toFixed(6)} |