mirror of
https://github.com/NotAShelf/nix-evaluator-stats.git
synced 2026-05-17 12:44:16 +00:00
add cli
This commit is contained in:
parent
5af2457177
commit
7697319a4d
11 changed files with 76 additions and 103 deletions
|
|
@ -1,4 +0,0 @@
|
|||
# @ns/tui
|
||||
|
||||
Provides a terminal-based interface for viewing and analyzing Nix evaluator
|
||||
statistics.
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"name": "@ns/tui",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"ns-tui": "./dist/cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"check": "tsc --noEmit",
|
||||
"dev": "node --loader ts-node/esm src/cli.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ns/core": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.5.2",
|
||||
"typescript": "^6.0.2"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import { readFile } from 'fs/promises';
|
||||
import { parseStats } from '@ns/core';
|
||||
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
// FIXME: nuke all of this actually
|
||||
if (args.length === 0) {
|
||||
console.log('NS');
|
||||
console.log('\nUsage: ns-tui <stats.json>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const filePath = args[0];
|
||||
|
||||
try {
|
||||
const content = await readFile(filePath, 'utf-8');
|
||||
const raw = JSON.parse(content);
|
||||
const stats = parseStats(raw);
|
||||
|
||||
console.log('\n=== Nix Evaluator Statistics ===\n');
|
||||
console.log(`CPU Time: ${stats.cpuTime.toFixed(3)}s`);
|
||||
console.log(`Expressions: ${stats.nrExprs.toLocaleString()}`);
|
||||
console.log(`Thunks: ${stats.nrThunks.toLocaleString()}`);
|
||||
console.log(` - Avoided: ${stats.nrAvoided.toLocaleString()}`);
|
||||
console.log(` - Ratio: ${((stats.nrAvoided / stats.nrThunks) * 100).toFixed(2)}%`);
|
||||
|
||||
const totalMemory =
|
||||
stats.envs.bytes +
|
||||
stats.list.bytes +
|
||||
stats.values.bytes +
|
||||
stats.symbols.bytes +
|
||||
stats.sets.bytes;
|
||||
console.log(`Total Memory: ${(totalMemory / 1024 / 1024).toFixed(2)} MB`);
|
||||
|
||||
console.log('\n=== Memory Breakdown ===\n');
|
||||
console.log(`Environments: ${(stats.envs.bytes / 1024 / 1024).toFixed(2)} MB`);
|
||||
console.log(`Lists: ${(stats.list.bytes / 1024 / 1024).toFixed(2)} MB`);
|
||||
console.log(`Values: ${(stats.values.bytes / 1024 / 1024).toFixed(2)} MB`);
|
||||
console.log(`Symbols: ${(stats.symbols.bytes / 1024 / 1024).toFixed(2)} MB`);
|
||||
console.log(`Sets: ${(stats.sets.bytes / 1024 / 1024).toFixed(2)} MB`);
|
||||
|
||||
if (stats.gc) {
|
||||
console.log('\n=== Garbage Collection ===\n');
|
||||
console.log(`Heap Size: ${(stats.gc.heapSize / 1024 / 1024).toFixed(2)} MB`);
|
||||
console.log(`Total Alloc: ${(stats.gc.totalBytes / 1024 / 1024).toFixed(2)} MB`);
|
||||
console.log(`GC Cycles: ${stats.gc.cycles.toLocaleString()}`);
|
||||
}
|
||||
|
||||
console.log('\n' + '='.repeat(40));
|
||||
console.log('='.repeat(40) + '\n');
|
||||
} catch (error) {
|
||||
console.error('Error:', error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"lib": ["ES2022"],
|
||||
"types": ["node"],
|
||||
"moduleResolution": "bundler",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
|
|
@ -38,6 +38,13 @@ function App() {
|
|||
|
||||
// Load from localStorage on mount
|
||||
onMount(() => {
|
||||
const query = window.location.search;
|
||||
const urlParams = new URLSearchParams(query);
|
||||
|
||||
const file = urlParams.get('file');
|
||||
if (file) {
|
||||
loadFromText(atob(file));
|
||||
}
|
||||
try {
|
||||
const saved = localStorage.getItem(STORAGE_KEY);
|
||||
if (saved) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue