MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add better view for test262

+71 -12
+71 -12
examples/test262/index.js
··· 54 54 index: 0, 55 55 filter: '', 56 56 filtered: entries, 57 + memoryCache: null, 57 58 memoryOffset: 0, 58 59 memoryStatus: '', 59 60 memoryStatusAt: 0, ··· 151 152 return out; 152 153 } 153 154 154 - function buildMemoryLines(styled = true) { 155 + function collectMemorySnapshot() { 155 156 const mem = Ant.stats(); 157 + const gcProfile = Ant.raw && typeof Ant.raw.gcMarkProfile === 'function' 158 + ? Ant.raw.gcMarkProfile() 159 + : null; 160 + 161 + return { mem, gcProfile }; 162 + } 163 + 164 + function buildMemoryLinesFromSnapshot(snapshot, styled = true) { 165 + const { mem, gcProfile } = snapshot; 156 166 const lines = styled 157 167 ? [`${c.cyan}Ant.stats()${c.reset}`, `${c.dim}Raw runtime stats dump${c.reset}`, ''] 158 168 : ['Ant.stats()', 'Raw runtime stats dump', '']; 159 169 lines.push(...flattenStats(mem, '', [], styled)); 160 170 161 - if (Ant.raw && typeof Ant.raw.gcMarkProfile === 'function') { 171 + if (gcProfile) { 162 172 lines.push(''); 163 173 lines.push(styled ? `${c.cyan}Ant.raw.gcMarkProfile()${c.reset}` : 'Ant.raw.gcMarkProfile()'); 164 174 lines.push(styled ? `${c.dim}Extra GC mark profiler stats${c.reset}` : 'Extra GC mark profiler stats'); 165 175 lines.push(''); 166 - lines.push(...flattenStats(Ant.raw.gcMarkProfile(), 'gcMarkProfile', [], styled)); 176 + lines.push(...flattenStats(gcProfile, 'gcMarkProfile', [], styled)); 167 177 } 168 178 169 179 return lines; 170 180 } 171 181 182 + function rebuildMemoryDisplayCache() { 183 + if (!state.memoryCache) return; 184 + 185 + const cols = getCols(); 186 + state.memoryCache.cols = cols; 187 + state.memoryCache.displayLines = state.memoryCache.styledLines.map(line => pad(line, cols)); 188 + } 189 + 190 + function refreshMemoryCache() { 191 + const snapshot = collectMemorySnapshot(); 192 + state.memoryCache = { 193 + snapshot, 194 + styledLines: buildMemoryLinesFromSnapshot(snapshot, true), 195 + plainLines: buildMemoryLinesFromSnapshot(snapshot, false), 196 + displayLines: [], 197 + cols: 0, 198 + updatedAt: Date.now(), 199 + }; 200 + rebuildMemoryDisplayCache(); 201 + } 202 + 203 + function ensureMemoryCache() { 204 + if (!state.memoryCache) { 205 + refreshMemoryCache(); 206 + } else if (state.memoryCache.cols !== getCols()) { 207 + rebuildMemoryDisplayCache(); 208 + } 209 + 210 + return state.memoryCache; 211 + } 212 + 172 213 function memoryStatusText() { 173 214 if (!state.memoryStatus) return ''; 174 215 if (Date.now() - state.memoryStatusAt > 4000) { ··· 184 225 } 185 226 186 227 function copyMemoryStats() { 187 - const text = buildMemoryLines(false).join('\n') + '\n'; 228 + const text = ensureMemoryCache().plainLines.join('\n') + '\n'; 188 229 const commands = process.platform === 'win32' 189 230 ? [{ command: 'clip', args: [] }] 190 231 : [ ··· 212 253 const rows = getRows(); 213 254 const cols = getCols(); 214 255 const lines = []; 256 + let linesArePadded = false; 215 257 216 258 if (state.mode === 'browse') { 217 259 const rateColor = stats.rate >= 80 ? c.green : stats.rate >= 50 ? c.yellow : c.red; ··· 300 342 lines.push(`${c.dim}s browse 路 q quit${c.reset}`); 301 343 } else if (state.mode === 'memory') { 302 344 const footerLines = 2; 303 - const memoryLines = buildMemoryLines(); 345 + const memoryCache = ensureMemoryCache(); 346 + const memoryLines = memoryCache.displayLines; 304 347 const viewHeight = Math.max(1, rows - footerLines); 305 348 const maxOffset = Math.max(0, memoryLines.length - viewHeight); 306 349 ··· 312 355 lines.push(...memoryLines.slice(state.memoryOffset, end)); 313 356 314 357 while (lines.length < rows - footerLines) { 315 - lines.push(''); 358 + lines.push(' '.repeat(cols)); 316 359 } 317 360 318 - lines.push(''); 361 + lines.push(' '.repeat(cols)); 319 362 const status = memoryStatusText(); 320 - lines.push( 321 - `${c.dim}鈫戔啌 scroll 路 PgUp/PgDn 路 g/G top/bottom 路 c copy 路 m browse 路 q quit${c.reset} ${c.dim}[${state.memoryOffset + 1}-${end}/${memoryLines.length}]${c.reset} ${status}${status ? ' ' : ''}${c.cyan}${fps.current} fps${c.reset}` 322 - ); 363 + lines.push(pad( 364 + `${c.dim}鈫戔啌 scroll 路 PgUp/PgDn 路 g/G top/bottom 路 r refresh 路 c copy 路 m browse 路 q quit${c.reset} ${c.dim}[${state.memoryOffset + 1}-${end}/${memoryLines.length}]${c.reset} ${status}${status ? ' ' : ''}${c.cyan}${fps.current} fps${c.reset}`, 365 + cols 366 + )); 367 + linesArePadded = true; 323 368 } 324 369 325 - return lines.map(l => pad(l, cols)).join('\n'); 370 + return linesArePadded ? lines.join('\n') : lines.map(l => pad(l, cols)).join('\n'); 326 371 } 327 372 328 373 function render() { ··· 454 499 needsRender = true; 455 500 break; 456 501 case 'm': 457 - state.mode = state.mode === 'memory' ? 'browse' : 'memory'; 502 + if (state.mode === 'memory') { 503 + state.mode = 'browse'; 504 + } else { 505 + state.mode = 'memory'; 506 + state.memoryOffset = 0; 507 + refreshMemoryCache(); 508 + setMemoryStatus(`${c.green}Refreshed memory stats${c.reset}`); 509 + } 458 510 needsRender = true; 511 + break; 512 + case 'r': 513 + if (state.mode === 'memory') { 514 + refreshMemoryCache(); 515 + setMemoryStatus(`${c.green}Refreshed memory stats${c.reset}`); 516 + needsRender = true; 517 + } 459 518 break; 460 519 case 'c': 461 520 if (state.mode === 'memory') {