mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
run daily perf-agent and add analysis scripts
- Added scripts/agent/perf-search.mjs to scan for performance anti-patterns. - Added scripts/agent/generate-perf-report.mjs to summarize findings. - Generated perf/hits-2026-02-18.json and perf/daily-perf-report-2026-02-18.md. - Created completion log. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
f340560765
commit
45917d6e2b
5 files changed
+9308
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const DATE = new Date().toISOString().split('T')[0];
|
||||
const HITS_FILE = path.join('perf', `hits-${DATE}.json`);
|
||||
const REPORT_FILE = path.join('perf', `daily-perf-report-${DATE}.md`);
|
||||
|
||||
if (!fs.existsSync(HITS_FILE)) {
|
||||
console.error(`Hits file not found: ${HITS_FILE}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const hits = JSON.parse(fs.readFileSync(HITS_FILE, 'utf8'));
|
||||
|
||||
// Summarize by pattern
|
||||
const patternCounts = {};
|
||||
hits.forEach(hit => {
|
||||
patternCounts[hit.pattern] = (patternCounts[hit.pattern] || 0) + 1;
|
||||
});
|
||||
|
||||
// Summarize by file
|
||||
const fileCounts = {};
|
||||
hits.forEach(hit => {
|
||||
fileCounts[hit.file] = (fileCounts[hit.file] || 0) + 1;
|
||||
});
|
||||
|
||||
// Sort files by hit count
|
||||
const sortedFiles = Object.entries(fileCounts)
|
||||
.sort(([, a], [, b]) => b - a)
|
||||
.slice(0, 10);
|
||||
|
||||
// Detect potential issues
|
||||
const p0Candidates = hits.filter(hit =>
|
||||
(hit.pattern === 'Promise Concurrency' && hit.content.includes('.map(')) ||
|
||||
(hit.pattern === 'Nostr/Relay/Auth' && hit.content.includes('pool.list'))
|
||||
).slice(0, 10);
|
||||
|
||||
let report = `# Daily Performance Report - ${DATE}\n\n`;
|
||||
|
||||
report += `## Summary\n`;
|
||||
report += `Total Hits: ${hits.length}\n\n`;
|
||||
report += `### Hits by Pattern\n`;
|
||||
Object.entries(patternCounts).forEach(([pattern, count]) => {
|
||||
report += `- ${pattern}: ${count}\n`;
|
||||
});
|
||||
|
||||
report += `\n## Top Files by Activity\n`;
|
||||
sortedFiles.forEach(([file, count]) => {
|
||||
report += `- ${file}: ${count} hits\n`;
|
||||
});
|
||||
|
||||
report += `\n## Potential P0/P1 Candidates (Sample)\n`;
|
||||
report += `These locations involve concurrency or heavy relay operations:\n\n`;
|
||||
p0Candidates.forEach(hit => {
|
||||
report += `- **${hit.file}:${hit.line}** (${hit.pattern}): \`${hit.content}\`\n`;
|
||||
});
|
||||
|
||||
report += `\n## Actions Taken\n`;
|
||||
report += `- Ran search patterns and generated inventory.\n`;
|
||||
report += `- No automatic fixes applied in this run.\n`;
|
||||
|
||||
fs.writeFileSync(REPORT_FILE, report);
|
||||
console.log(`Report generated at ${REPORT_FILE}`);
|
||||
@@ -0,0 +1,70 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const SEARCH_DIR = 'js';
|
||||
const OUTPUT_DIR = 'perf';
|
||||
const DATE = new Date().toISOString().split('T')[0];
|
||||
const OUTPUT_FILE = path.join(OUTPUT_DIR, `hits-${DATE}.json`);
|
||||
|
||||
const PATTERNS = [
|
||||
{ name: 'Timeouts/Intervals', regex: /setInterval|setTimeout|requestAnimationFrame|requestIdleCallback/g },
|
||||
{ name: 'Promise Concurrency', regex: /Promise\.allSettled|Promise\.all|Promise\.any|Promise\.race/g },
|
||||
{ name: 'Workers', regex: /new Worker|Worker\(|postMessage\(|getDmDecryptWorkerQueueSize|decryptDmInWorker/g },
|
||||
{ name: 'WebTorrent', regex: /new WebTorrent|WebTorrent|torrent|magnet|torrentHash|magnetValidators/g },
|
||||
{ name: 'Nostr/Relay/Auth', regex: /nostrClient\.pool|publishEventToRelays|pool\.list|queueSignEvent|relayManager|authService|hydrateFromStorage/g },
|
||||
{ name: 'Visibility', regex: /document\.hidden|visibilitychange/g }
|
||||
];
|
||||
|
||||
function getAllFiles(dirPath, arrayOfFiles) {
|
||||
const files = fs.readdirSync(dirPath);
|
||||
|
||||
arrayOfFiles = arrayOfFiles || [];
|
||||
|
||||
files.forEach(function(file) {
|
||||
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
|
||||
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
|
||||
} else {
|
||||
if (file.endsWith('.js') && !file.endsWith('.min.js')) {
|
||||
arrayOfFiles.push(path.join(dirPath, "/", file));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return arrayOfFiles;
|
||||
}
|
||||
|
||||
function searchInFiles() {
|
||||
const files = getAllFiles(SEARCH_DIR);
|
||||
const hits = [];
|
||||
|
||||
files.forEach(file => {
|
||||
const content = fs.readFileSync(file, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
|
||||
lines.forEach((line, index) => {
|
||||
PATTERNS.forEach(pattern => {
|
||||
if (line.match(pattern.regex)) {
|
||||
hits.push({
|
||||
file: file,
|
||||
line: index + 1,
|
||||
content: line.trim(),
|
||||
pattern: pattern.name,
|
||||
match: line.match(pattern.regex)[0]
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return hits;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(OUTPUT_DIR)){
|
||||
fs.mkdirSync(OUTPUT_DIR);
|
||||
}
|
||||
|
||||
const results = searchInFiles();
|
||||
fs.writeFileSync(OUTPUT_FILE, JSON.stringify(results, null, 2));
|
||||
|
||||
console.log(`Search complete. Found ${results.length} hits.`);
|
||||
console.log(`Results saved to ${OUTPUT_FILE}`);
|
||||
Reference in new issue
Block a user