ts-knowledge-graph 0.1.2 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -41
- package/contribs/webview/README.md +83 -0
- package/contribs/webview/web/css/style.css +310 -0
- package/contribs/webview/web/index.html +109 -0
- package/contribs/webview/web/js/app.js +1249 -0
- package/contribs/webview/web/js_autogenerated/.gitignore +3 -0
- package/contribs/webview/web/js_autogenerated/kind_descriptions.js +39 -0
- package/contribs/webview/web/types/app_globals.d.ts +154 -0
- package/dist/benchmark/benchmark_stats.d.ts +41 -0
- package/dist/benchmark/benchmark_stats.d.ts.map +1 -0
- package/dist/benchmark/benchmark_stats.js +61 -0
- package/dist/benchmark/benchmark_stats.js.map +1 -0
- package/dist/benchmark/node_benchmark.d.ts +78 -0
- package/dist/benchmark/node_benchmark.d.ts.map +1 -0
- package/dist/benchmark/node_benchmark.js +112 -0
- package/dist/benchmark/node_benchmark.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +16 -4
- package/dist/cli.js.map +1 -1
- package/dist/cluster/cluster_weights.d.ts +20 -0
- package/dist/cluster/cluster_weights.d.ts.map +1 -0
- package/dist/cluster/cluster_weights.js +32 -0
- package/dist/cluster/cluster_weights.js.map +1 -0
- package/dist/cluster/community_detector.d.ts +61 -0
- package/dist/cluster/community_detector.d.ts.map +1 -0
- package/dist/cluster/community_detector.js +120 -0
- package/dist/cluster/community_detector.js.map +1 -0
- package/dist/cluster/community_labeler.d.ts +84 -0
- package/dist/cluster/community_labeler.d.ts.map +1 -0
- package/dist/cluster/community_labeler.js +194 -0
- package/dist/cluster/community_labeler.js.map +1 -0
- package/dist/cluster/graph_clusterer.d.ts +47 -0
- package/dist/cluster/graph_clusterer.d.ts.map +1 -0
- package/dist/cluster/graph_clusterer.js +126 -0
- package/dist/cluster/graph_clusterer.js.map +1 -0
- package/dist/commands/benchmark_command.d.ts +11 -0
- package/dist/commands/benchmark_command.d.ts.map +1 -0
- package/dist/commands/benchmark_command.js +94 -0
- package/dist/commands/benchmark_command.js.map +1 -0
- package/dist/commands/blast_radius_command.d.ts.map +1 -1
- package/dist/commands/blast_radius_command.js +7 -6
- package/dist/commands/blast_radius_command.js.map +1 -1
- package/dist/commands/cluster_command.d.ts +7 -0
- package/dist/commands/cluster_command.d.ts.map +1 -0
- package/dist/commands/cluster_command.js +55 -0
- package/dist/commands/cluster_command.js.map +1 -0
- package/dist/commands/command_helpers.d.ts +9 -4
- package/dist/commands/command_helpers.d.ts.map +1 -1
- package/dist/commands/command_helpers.js +13 -8
- package/dist/commands/command_helpers.js.map +1 -1
- package/dist/commands/cost_command.d.ts +13 -0
- package/dist/commands/cost_command.d.ts.map +1 -0
- package/dist/commands/cost_command.js +139 -0
- package/dist/commands/cost_command.js.map +1 -0
- package/dist/commands/{load.d.ts → enrich_command.d.ts} +3 -2
- package/dist/commands/enrich_command.d.ts.map +1 -0
- package/dist/commands/enrich_command.js +64 -0
- package/dist/commands/enrich_command.js.map +1 -0
- package/dist/commands/extract_command.d.ts.map +1 -1
- package/dist/commands/extract_command.js +12 -6
- package/dist/commands/extract_command.js.map +1 -1
- package/dist/commands/hotspots_command.d.ts +7 -0
- package/dist/commands/hotspots_command.d.ts.map +1 -0
- package/dist/commands/hotspots_command.js +68 -0
- package/dist/commands/hotspots_command.js.map +1 -0
- package/dist/commands/install_command.d.ts +15 -6
- package/dist/commands/install_command.d.ts.map +1 -1
- package/dist/commands/install_command.js +62 -25
- package/dist/commands/install_command.js.map +1 -1
- package/dist/commands/load_command.d.ts.map +1 -1
- package/dist/commands/load_command.js +20 -13
- package/dist/commands/load_command.js.map +1 -1
- package/dist/commands/neighbors_command.d.ts.map +1 -1
- package/dist/commands/neighbors_command.js +6 -5
- package/dist/commands/neighbors_command.js.map +1 -1
- package/dist/commands/references_command.d.ts.map +1 -1
- package/dist/commands/references_command.js +6 -5
- package/dist/commands/references_command.js.map +1 -1
- package/dist/commands/report_command.d.ts +16 -0
- package/dist/commands/report_command.d.ts.map +1 -0
- package/dist/commands/report_command.js +115 -0
- package/dist/commands/report_command.js.map +1 -0
- package/dist/commands/verify_command.d.ts +8 -0
- package/dist/commands/verify_command.d.ts.map +1 -0
- package/dist/commands/verify_command.js +57 -0
- package/dist/commands/verify_command.js.map +1 -0
- package/dist/commands/web_command.d.ts +27 -0
- package/dist/commands/web_command.d.ts.map +1 -1
- package/dist/commands/web_command.js +109 -3
- package/dist/commands/web_command.js.map +1 -1
- package/dist/commands/webview_command.d.ts +36 -0
- package/dist/commands/webview_command.d.ts.map +1 -0
- package/dist/commands/webview_command.js +186 -0
- package/dist/commands/webview_command.js.map +1 -0
- package/dist/enrich/cpu_profile.d.ts +160 -0
- package/dist/enrich/cpu_profile.d.ts.map +1 -0
- package/dist/enrich/cpu_profile.js +185 -0
- package/dist/enrich/cpu_profile.js.map +1 -0
- package/dist/enrich/runtime_enricher.d.ts +64 -0
- package/dist/enrich/runtime_enricher.d.ts.map +1 -0
- package/dist/enrich/runtime_enricher.js +98 -0
- package/dist/enrich/runtime_enricher.js.map +1 -0
- package/dist/enrich/runtime_join.d.ts +124 -0
- package/dist/enrich/runtime_join.d.ts.map +1 -0
- package/dist/enrich/runtime_join.js +270 -0
- package/dist/enrich/runtime_join.js.map +1 -0
- package/dist/extract/api_extractor.d.ts +24 -0
- package/dist/extract/api_extractor.d.ts.map +1 -0
- package/dist/extract/api_extractor.js +71 -0
- package/dist/extract/api_extractor.js.map +1 -0
- package/dist/extract/config_extractor.d.ts +22 -0
- package/dist/extract/config_extractor.d.ts.map +1 -0
- package/dist/extract/config_extractor.js +61 -0
- package/dist/extract/config_extractor.js.map +1 -0
- package/dist/extract/endpoint_extractor.d.ts +36 -0
- package/dist/extract/endpoint_extractor.d.ts.map +1 -0
- package/dist/extract/endpoint_extractor.js +117 -0
- package/dist/extract/endpoint_extractor.js.map +1 -0
- package/dist/extract/git_source.d.ts +23 -0
- package/dist/extract/git_source.d.ts.map +1 -0
- package/dist/extract/git_source.js +75 -0
- package/dist/extract/git_source.js.map +1 -0
- package/dist/extract/graph_builder.d.ts +8 -0
- package/dist/extract/graph_builder.d.ts.map +1 -1
- package/dist/extract/graph_builder.js +23 -1
- package/dist/extract/graph_builder.js.map +1 -1
- package/dist/extract/node_id.d.ts +16 -0
- package/dist/extract/node_id.d.ts.map +1 -1
- package/dist/extract/node_id.js +22 -0
- package/dist/extract/node_id.js.map +1 -1
- package/dist/extract/scope_resolver.d.ts +22 -0
- package/dist/extract/scope_resolver.d.ts.map +1 -0
- package/dist/extract/scope_resolver.js +53 -0
- package/dist/extract/scope_resolver.js.map +1 -0
- package/dist/extract/semantic_extractor.d.ts +25 -0
- package/dist/extract/semantic_extractor.d.ts.map +1 -1
- package/dist/extract/semantic_extractor.js +96 -2
- package/dist/extract/semantic_extractor.js.map +1 -1
- package/dist/extract/structural_extractor.d.ts +6 -0
- package/dist/extract/structural_extractor.d.ts.map +1 -1
- package/dist/extract/structural_extractor.js +22 -12
- package/dist/extract/structural_extractor.js.map +1 -1
- package/dist/project_root.d.ts +7 -0
- package/dist/project_root.d.ts.map +1 -0
- package/dist/project_root.js +9 -0
- package/dist/project_root.js.map +1 -0
- package/dist/query/graph_query.d.ts +269 -0
- package/dist/query/graph_query.d.ts.map +1 -1
- package/dist/query/graph_query.js +585 -11
- package/dist/query/graph_query.js.map +1 -1
- package/dist/report/graph_report.d.ts +51 -0
- package/dist/report/graph_report.d.ts.map +1 -0
- package/dist/report/graph_report.js +312 -0
- package/dist/report/graph_report.js.map +1 -0
- package/dist/report/pdf_renderer.d.ts +22 -0
- package/dist/report/pdf_renderer.d.ts.map +1 -0
- package/dist/report/pdf_renderer.js +54 -0
- package/dist/report/pdf_renderer.js.map +1 -0
- package/dist/report/report_data.d.ts +128 -0
- package/dist/report/report_data.d.ts.map +1 -0
- package/dist/report/report_data.js +191 -0
- package/dist/report/report_data.js.map +1 -0
- package/dist/schema/edge.d.ts +40 -5
- package/dist/schema/edge.d.ts.map +1 -1
- package/dist/schema/edge.js +73 -0
- package/dist/schema/edge.js.map +1 -1
- package/dist/schema/node.d.ts +20 -5
- package/dist/schema/node.d.ts.map +1 -1
- package/dist/schema/node.js +36 -0
- package/dist/schema/node.js.map +1 -1
- package/dist/schema/runtime_manifest.d.ts +36 -0
- package/dist/schema/runtime_manifest.d.ts.map +1 -0
- package/dist/schema/runtime_manifest.js +23 -0
- package/dist/schema/runtime_manifest.js.map +1 -0
- package/dist/schema/source_manifest.d.ts +30 -0
- package/dist/schema/source_manifest.d.ts.map +1 -0
- package/dist/schema/source_manifest.js +21 -0
- package/dist/schema/source_manifest.js.map +1 -0
- package/dist/store/jsonl_reader.d.ts +4 -0
- package/dist/store/jsonl_reader.d.ts.map +1 -1
- package/dist/store/jsonl_reader.js +13 -1
- package/dist/store/jsonl_reader.js.map +1 -1
- package/dist/store/jsonl_store.d.ts +2 -1
- package/dist/store/jsonl_store.d.ts.map +1 -1
- package/dist/store/jsonl_store.js +4 -1
- package/dist/store/jsonl_store.js.map +1 -1
- package/dist/store/kuzu_store.d.ts +59 -0
- package/dist/store/kuzu_store.d.ts.map +1 -1
- package/dist/store/kuzu_store.js +124 -5
- package/dist/store/kuzu_store.js.map +1 -1
- package/dist/store/output_folder.d.ts +43 -0
- package/dist/store/output_folder.d.ts.map +1 -0
- package/dist/store/output_folder.js +61 -0
- package/dist/store/output_folder.js.map +1 -0
- package/dist/verify/project_verifier.d.ts +85 -0
- package/dist/verify/project_verifier.d.ts.map +1 -0
- package/dist/verify/project_verifier.js +138 -0
- package/dist/verify/project_verifier.js.map +1 -0
- package/dotclaude_folder/commands/code-graph-interview.md +123 -0
- package/dotclaude_folder/commands/code-graph-optimize.md +65 -0
- package/{skills/ts-knowledge-graph → dotclaude_folder/skills/code-graph-query}/SKILL.md +6 -6
- package/package.json +99 -10
- package/.env-sample +0 -34
- package/contribs/web_visualisation/README.md +0 -55
- package/contribs/web_visualisation/web/css/style.css +0 -115
- package/contribs/web_visualisation/web/data/.gitignore +0 -2
- package/contribs/web_visualisation/web/index.html +0 -58
- package/contribs/web_visualisation/web/js/app.js +0 -364
- package/dist/agent/agent-tools.d.ts +0 -13
- package/dist/agent/agent-tools.d.ts.map +0 -1
- package/dist/agent/agent-tools.js +0 -153
- package/dist/agent/agent-tools.js.map +0 -1
- package/dist/agent/agent_tools.d.ts +0 -13
- package/dist/agent/agent_tools.d.ts.map +0 -1
- package/dist/agent/agent_tools.js +0 -153
- package/dist/agent/agent_tools.js.map +0 -1
- package/dist/agent/code-editor.d.ts +0 -18
- package/dist/agent/code-editor.d.ts.map +0 -1
- package/dist/agent/code-editor.js +0 -43
- package/dist/agent/code-editor.js.map +0 -1
- package/dist/agent/code_editor.d.ts +0 -18
- package/dist/agent/code_editor.d.ts.map +0 -1
- package/dist/agent/code_editor.js +0 -43
- package/dist/agent/code_editor.js.map +0 -1
- package/dist/agent/optimizer-agent.d.ts +0 -30
- package/dist/agent/optimizer-agent.d.ts.map +0 -1
- package/dist/agent/optimizer-agent.js +0 -97
- package/dist/agent/optimizer-agent.js.map +0 -1
- package/dist/agent/optimizer_agent.d.ts +0 -30
- package/dist/agent/optimizer_agent.d.ts.map +0 -1
- package/dist/agent/optimizer_agent.js +0 -97
- package/dist/agent/optimizer_agent.js.map +0 -1
- package/dist/agent/verifier.d.ts +0 -9
- package/dist/agent/verifier.d.ts.map +0 -1
- package/dist/agent/verifier.js +0 -19
- package/dist/agent/verifier.js.map +0 -1
- package/dist/commands/blast-radius.d.ts +0 -5
- package/dist/commands/blast-radius.d.ts.map +0 -1
- package/dist/commands/blast-radius.js +0 -18
- package/dist/commands/blast-radius.js.map +0 -1
- package/dist/commands/blast_radius.d.ts +0 -5
- package/dist/commands/blast_radius.d.ts.map +0 -1
- package/dist/commands/blast_radius.js +0 -18
- package/dist/commands/blast_radius.js.map +0 -1
- package/dist/commands/calls.d.ts +0 -5
- package/dist/commands/calls.d.ts.map +0 -1
- package/dist/commands/calls.js +0 -7
- package/dist/commands/calls.js.map +0 -1
- package/dist/commands/command-helpers.d.ts +0 -15
- package/dist/commands/command-helpers.d.ts.map +0 -1
- package/dist/commands/command-helpers.js +0 -61
- package/dist/commands/command-helpers.js.map +0 -1
- package/dist/commands/dead-exports.d.ts +0 -5
- package/dist/commands/dead-exports.d.ts.map +0 -1
- package/dist/commands/dead-exports.js +0 -7
- package/dist/commands/dead-exports.js.map +0 -1
- package/dist/commands/dead_exports.d.ts +0 -5
- package/dist/commands/dead_exports.d.ts.map +0 -1
- package/dist/commands/dead_exports.js +0 -7
- package/dist/commands/dead_exports.js.map +0 -1
- package/dist/commands/extract.d.ts +0 -8
- package/dist/commands/extract.d.ts.map +0 -1
- package/dist/commands/extract.js +0 -49
- package/dist/commands/extract.js.map +0 -1
- package/dist/commands/find.d.ts +0 -5
- package/dist/commands/find.d.ts.map +0 -1
- package/dist/commands/find.js +0 -7
- package/dist/commands/find.js.map +0 -1
- package/dist/commands/load.d.ts.map +0 -1
- package/dist/commands/load.js +0 -28
- package/dist/commands/load.js.map +0 -1
- package/dist/commands/neighbors.d.ts +0 -5
- package/dist/commands/neighbors.d.ts.map +0 -1
- package/dist/commands/neighbors.js +0 -17
- package/dist/commands/neighbors.js.map +0 -1
- package/dist/commands/optimize.d.ts +0 -6
- package/dist/commands/optimize.d.ts.map +0 -1
- package/dist/commands/optimize.js +0 -59
- package/dist/commands/optimize.js.map +0 -1
- package/dist/commands/optimize_command.d.ts +0 -6
- package/dist/commands/optimize_command.d.ts.map +0 -1
- package/dist/commands/optimize_command.js +0 -59
- package/dist/commands/optimize_command.js.map +0 -1
- package/dist/commands/references.d.ts +0 -5
- package/dist/commands/references.d.ts.map +0 -1
- package/dist/commands/references.js +0 -17
- package/dist/commands/references.js.map +0 -1
- package/dist/commands/web.d.ts +0 -19
- package/dist/commands/web.d.ts.map +0 -1
- package/dist/commands/web.js +0 -120
- package/dist/commands/web.js.map +0 -1
- package/dist/commands/who-calls.d.ts +0 -5
- package/dist/commands/who-calls.d.ts.map +0 -1
- package/dist/commands/who-calls.js +0 -7
- package/dist/commands/who-calls.js.map +0 -1
- package/dist/commands/who_calls.d.ts +0 -5
- package/dist/commands/who_calls.d.ts.map +0 -1
- package/dist/commands/who_calls.js +0 -7
- package/dist/commands/who_calls.js.map +0 -1
- package/dist/extract/graph-builder.d.ts +0 -16
- package/dist/extract/graph-builder.d.ts.map +0 -1
- package/dist/extract/graph-builder.js +0 -39
- package/dist/extract/graph-builder.js.map +0 -1
- package/dist/extract/node-id.d.ts +0 -8
- package/dist/extract/node-id.d.ts.map +0 -1
- package/dist/extract/node-id.js +0 -22
- package/dist/extract/node-id.js.map +0 -1
- package/dist/extract/project-loader.d.ts +0 -5
- package/dist/extract/project-loader.d.ts.map +0 -1
- package/dist/extract/project-loader.js +0 -19
- package/dist/extract/project-loader.js.map +0 -1
- package/dist/extract/semantic-extractor.d.ts +0 -22
- package/dist/extract/semantic-extractor.d.ts.map +0 -1
- package/dist/extract/semantic-extractor.js +0 -254
- package/dist/extract/semantic-extractor.js.map +0 -1
- package/dist/extract/structural-extractor.d.ts +0 -18
- package/dist/extract/structural-extractor.d.ts.map +0 -1
- package/dist/extract/structural-extractor.js +0 -97
- package/dist/extract/structural-extractor.js.map +0 -1
- package/dist/query/graph-query.d.ts +0 -28
- package/dist/query/graph-query.d.ts.map +0 -1
- package/dist/query/graph-query.js +0 -93
- package/dist/query/graph-query.js.map +0 -1
- package/dist/store/jsonl-reader.d.ts +0 -11
- package/dist/store/jsonl-reader.d.ts.map +0 -1
- package/dist/store/jsonl-reader.js +0 -19
- package/dist/store/jsonl-reader.js.map +0 -1
- package/dist/store/jsonl-store.d.ts +0 -7
- package/dist/store/jsonl-store.d.ts.map +0 -1
- package/dist/store/jsonl-store.js +0 -13
- package/dist/store/jsonl-store.js.map +0 -1
- package/dist/store/kuzu-store.d.ts +0 -14
- package/dist/store/kuzu-store.d.ts.map +0 -1
- package/dist/store/kuzu-store.js +0 -52
- package/dist/store/kuzu-store.js.map +0 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { createServer } from 'node:http';
|
|
4
|
+
import { extname, join, normalize, resolve, sep } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import { GitSource } from '../extract/git_source.js';
|
|
8
|
+
import { SOURCE_MANIFEST_KEY, SourceManifestSchema } from '../schema/source_manifest.js';
|
|
9
|
+
import { KuzuStore } from '../store/kuzu_store.js';
|
|
10
|
+
import { OutputFolder } from '../store/output_folder.js';
|
|
11
|
+
import { CommandHelpers } from './command_helpers.js';
|
|
12
|
+
/**
|
|
13
|
+
* Static assets of the web visualisation, resolved relative to this module so
|
|
14
|
+
* the same path works from `src/` (tsx) and from `dist/` (published package).
|
|
15
|
+
*/
|
|
16
|
+
const WEB_ROOT = fileURLToPath(new URL('../../contribs/webview/web', import.meta.url));
|
|
17
|
+
const DATA_SCRIPT_PATH = '/js_autogenerated/graph_data.js';
|
|
18
|
+
const DEFAULT_PORT = '4173';
|
|
19
|
+
const MIME_TYPES = {
|
|
20
|
+
'.css': 'text/css; charset=utf-8',
|
|
21
|
+
'.html': 'text/html; charset=utf-8',
|
|
22
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
23
|
+
'.json': 'application/json; charset=utf-8',
|
|
24
|
+
'.png': 'image/png',
|
|
25
|
+
'.svg': 'image/svg+xml',
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* `webview` command — serves the knowledge graph database in an interactive web
|
|
29
|
+
* visualisation. The graph is read from Kùzu once at startup and injected into
|
|
30
|
+
* the page as `/js_autogenerated/graph_data.js`; all other assets are served statically
|
|
31
|
+
* from the contribs/webview/web directory.
|
|
32
|
+
*/
|
|
33
|
+
export class WebviewCommand {
|
|
34
|
+
static register(program) {
|
|
35
|
+
const command = program
|
|
36
|
+
.command('webview')
|
|
37
|
+
.description('serve the knowledge graph database in a web visualisation');
|
|
38
|
+
CommandHelpers.addOutputFolderOption(command)
|
|
39
|
+
.option('-p, --port <port>', 'HTTP port to listen on', DEFAULT_PORT)
|
|
40
|
+
.option('-s, --source <dir>', 'fallback project root for GitHub links when the graph records no source', '.')
|
|
41
|
+
.action(async (options) => {
|
|
42
|
+
await WebviewCommand.run(options);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
static async run(options) {
|
|
46
|
+
const dbPath = new OutputFolder(options.outputFolder).dbPath;
|
|
47
|
+
if (existsSync(dbPath) === false) {
|
|
48
|
+
console.error(chalk.red(`database not found at ${dbPath} — run \`extract\` then \`load\` first`));
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const github = await WebviewCommand.resolveGitHubSource(dbPath, resolve(options.source));
|
|
53
|
+
const sourceScript = github === undefined ? '' : `window.GRAPH_SOURCE = ${JSON.stringify({ github })};\n`;
|
|
54
|
+
const dataScript = sourceScript + await WebviewCommand.buildDataScript(dbPath);
|
|
55
|
+
const server = createServer((request, response) => {
|
|
56
|
+
void WebviewCommand.handle(request, response, dataScript);
|
|
57
|
+
});
|
|
58
|
+
server.listen(Number(options.port), () => {
|
|
59
|
+
console.log(chalk.green(`✓ serving the knowledge graph at http://localhost:${options.port}/`));
|
|
60
|
+
console.log(chalk.gray(' press Ctrl+C to stop'));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Reads every node and edge from the database and renders them as the
|
|
65
|
+
* `window.GRAPH_DATA` script the visualisation page loads on boot.
|
|
66
|
+
*/
|
|
67
|
+
static async buildDataScript(dbPath) {
|
|
68
|
+
const store = new KuzuStore(dbPath);
|
|
69
|
+
await store.initSchema();
|
|
70
|
+
try {
|
|
71
|
+
const nodeRows = await store.run('MATCH (n:GraphNode) RETURN n.id AS id, n.kind AS kind, n.name AS name, n.filePath AS filePath, n.exported AS exported, n.startLine AS startLine, n.endLine AS endLine, n.metadata AS metadata');
|
|
72
|
+
const edgeRows = await store.run('MATCH (f:GraphNode)-[e:Edge]->(t:GraphNode) RETURN f.id AS from, e.kind AS kind, t.id AS to, e.metadata AS metadata');
|
|
73
|
+
const nodes = nodeRows.map((row) => ({
|
|
74
|
+
id: String(row.id),
|
|
75
|
+
kind: String(row.kind),
|
|
76
|
+
name: String(row.name),
|
|
77
|
+
filePath: String(row.filePath),
|
|
78
|
+
exported: row.exported === true,
|
|
79
|
+
range: {
|
|
80
|
+
startLine: Number(row.startLine),
|
|
81
|
+
startColumn: 0,
|
|
82
|
+
endLine: Number(row.endLine),
|
|
83
|
+
endColumn: 0,
|
|
84
|
+
},
|
|
85
|
+
metadata: WebviewCommand.decodeMetadata(row.metadata),
|
|
86
|
+
}));
|
|
87
|
+
const edges = edgeRows.map((row, index) => ({
|
|
88
|
+
id: `e${index}`,
|
|
89
|
+
kind: String(row.kind),
|
|
90
|
+
from: String(row.from),
|
|
91
|
+
to: String(row.to),
|
|
92
|
+
metadata: WebviewCommand.decodeMetadata(row.metadata),
|
|
93
|
+
}));
|
|
94
|
+
console.log(chalk.cyan(`loaded ${nodes.length} nodes, ${edges.length} edges from ${dbPath}`));
|
|
95
|
+
return `window.GRAPH_DATA = ${JSON.stringify({ nodes, edges })};\n`;
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
await store.close();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Decodes the JSON `metadata` column into a record so the visualisation can
|
|
103
|
+
* read `metadata.runtime`. A missing, empty (`{}`), or malformed value yields
|
|
104
|
+
* `undefined`, which `JSON.stringify` omits — keeping the payload small and
|
|
105
|
+
* letting un-enriched nodes simply carry no metadata.
|
|
106
|
+
*/
|
|
107
|
+
static decodeMetadata(value) {
|
|
108
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(value);
|
|
113
|
+
if (typeof parsed === 'object' && parsed !== null && Object.keys(parsed).length > 0) {
|
|
114
|
+
return parsed;
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Resolves the GitHub source for the served graph. Prefers the provenance
|
|
124
|
+
* `extract` recorded in the database — it pins the exact commit and in-repo
|
|
125
|
+
* `prefix` that was parsed — and falls back to detecting it live from
|
|
126
|
+
* `sourceDir` for graphs built before provenance was captured. Returns
|
|
127
|
+
* `undefined` when neither is available, so the page shows plain-text paths.
|
|
128
|
+
*/
|
|
129
|
+
static async resolveGitHubSource(dbPath, sourceDir) {
|
|
130
|
+
const stored = await WebviewCommand.readStoredSource(dbPath);
|
|
131
|
+
if (stored !== undefined) {
|
|
132
|
+
console.log(chalk.cyan(`linking files to ${stored.baseUrl} @ ${stored.commit.slice(0, 7)} (recorded by extract)`));
|
|
133
|
+
return stored;
|
|
134
|
+
}
|
|
135
|
+
const detected = await GitSource.detect(sourceDir);
|
|
136
|
+
if (detected === undefined) {
|
|
137
|
+
console.log(chalk.gray('no GitHub source recorded or detected — file paths will not link to source'));
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
console.log(chalk.cyan(`linking files to ${detected.baseUrl} @ ${detected.commit.slice(0, 7)} (detected from ${sourceDir})`));
|
|
141
|
+
return detected;
|
|
142
|
+
}
|
|
143
|
+
/** Reads the source provenance `load` stored in the database, or `undefined` when absent or malformed. */
|
|
144
|
+
static async readStoredSource(dbPath) {
|
|
145
|
+
const store = new KuzuStore(dbPath);
|
|
146
|
+
await store.initSchema();
|
|
147
|
+
try {
|
|
148
|
+
const raw = await store.readGraphMeta(SOURCE_MANIFEST_KEY);
|
|
149
|
+
if (raw === null) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
const parsed = SourceManifestSchema.safeParse(raw);
|
|
153
|
+
return parsed.success === true ? parsed.data : undefined;
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
await store.close();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
static async handle(request, response, dataScript) {
|
|
160
|
+
const url = new URL(request.url ?? '/', 'http://localhost');
|
|
161
|
+
const pathname = url.pathname === '/' ? '/index.html' : url.pathname;
|
|
162
|
+
if (pathname === DATA_SCRIPT_PATH) {
|
|
163
|
+
response.writeHead(200, { 'content-type': MIME_TYPES['.js'] });
|
|
164
|
+
response.end(dataScript);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const filePath = normalize(join(WEB_ROOT, pathname));
|
|
168
|
+
if (filePath.startsWith(WEB_ROOT + sep) === false) {
|
|
169
|
+
WebviewCommand.notFound(response);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const content = await readFile(filePath);
|
|
174
|
+
response.writeHead(200, { 'content-type': MIME_TYPES[extname(filePath)] ?? 'application/octet-stream' });
|
|
175
|
+
response.end(content);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
WebviewCommand.notFound(response);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
static notFound(response) {
|
|
182
|
+
response.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' });
|
|
183
|
+
response.end('not found');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=webview_command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webview_command.js","sourceRoot":"","sources":["../../src/commands/webview_command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO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,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE,CAAC,CAAC;QACzE,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3B,CAAC;CACD"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The on-disk shape of a `node --cpu-prof` output (`.cpuprofile`). `samples`
|
|
4
|
+
* holds one profile-node id per sampling tick; `timeDeltas` holds the elapsed
|
|
5
|
+
* microseconds preceding each tick. Both are optional because some producers
|
|
6
|
+
* emit only per-node `hitCount`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CpuProfileSchema: z.ZodObject<{
|
|
9
|
+
nodes: z.ZodArray<z.ZodObject<{
|
|
10
|
+
id: z.ZodNumber;
|
|
11
|
+
callFrame: z.ZodObject<{
|
|
12
|
+
functionName: z.ZodString;
|
|
13
|
+
scriptId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
14
|
+
url: z.ZodString;
|
|
15
|
+
lineNumber: z.ZodNumber;
|
|
16
|
+
columnNumber: z.ZodNumber;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
functionName: string;
|
|
19
|
+
url: string;
|
|
20
|
+
lineNumber: number;
|
|
21
|
+
columnNumber: number;
|
|
22
|
+
scriptId?: string | number | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
functionName: string;
|
|
25
|
+
url: string;
|
|
26
|
+
lineNumber: number;
|
|
27
|
+
columnNumber: number;
|
|
28
|
+
scriptId?: string | number | undefined;
|
|
29
|
+
}>;
|
|
30
|
+
hitCount: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
children: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
id: number;
|
|
34
|
+
callFrame: {
|
|
35
|
+
functionName: string;
|
|
36
|
+
url: string;
|
|
37
|
+
lineNumber: number;
|
|
38
|
+
columnNumber: number;
|
|
39
|
+
scriptId?: string | number | undefined;
|
|
40
|
+
};
|
|
41
|
+
hitCount?: number | undefined;
|
|
42
|
+
children?: number[] | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
id: number;
|
|
45
|
+
callFrame: {
|
|
46
|
+
functionName: string;
|
|
47
|
+
url: string;
|
|
48
|
+
lineNumber: number;
|
|
49
|
+
columnNumber: number;
|
|
50
|
+
scriptId?: string | number | undefined;
|
|
51
|
+
};
|
|
52
|
+
hitCount?: number | undefined;
|
|
53
|
+
children?: number[] | undefined;
|
|
54
|
+
}>, "many">;
|
|
55
|
+
startTime: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
endTime: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
samples: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
58
|
+
timeDeltas: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
nodes: {
|
|
61
|
+
id: number;
|
|
62
|
+
callFrame: {
|
|
63
|
+
functionName: string;
|
|
64
|
+
url: string;
|
|
65
|
+
lineNumber: number;
|
|
66
|
+
columnNumber: number;
|
|
67
|
+
scriptId?: string | number | undefined;
|
|
68
|
+
};
|
|
69
|
+
hitCount?: number | undefined;
|
|
70
|
+
children?: number[] | undefined;
|
|
71
|
+
}[];
|
|
72
|
+
startTime?: number | undefined;
|
|
73
|
+
endTime?: number | undefined;
|
|
74
|
+
samples?: number[] | undefined;
|
|
75
|
+
timeDeltas?: number[] | undefined;
|
|
76
|
+
}, {
|
|
77
|
+
nodes: {
|
|
78
|
+
id: number;
|
|
79
|
+
callFrame: {
|
|
80
|
+
functionName: string;
|
|
81
|
+
url: string;
|
|
82
|
+
lineNumber: number;
|
|
83
|
+
columnNumber: number;
|
|
84
|
+
scriptId?: string | number | undefined;
|
|
85
|
+
};
|
|
86
|
+
hitCount?: number | undefined;
|
|
87
|
+
children?: number[] | undefined;
|
|
88
|
+
}[];
|
|
89
|
+
startTime?: number | undefined;
|
|
90
|
+
endTime?: number | undefined;
|
|
91
|
+
samples?: number[] | undefined;
|
|
92
|
+
timeDeltas?: number[] | undefined;
|
|
93
|
+
}>;
|
|
94
|
+
export type CpuProfileData = z.infer<typeof CpuProfileSchema>;
|
|
95
|
+
/**
|
|
96
|
+
* One executing location distilled from the profile: its call frame plus the
|
|
97
|
+
* self time and sample count attributed to it. `line` is converted to the
|
|
98
|
+
* one-based convention so it can be compared against graph node ranges.
|
|
99
|
+
*/
|
|
100
|
+
export type FrameSample = {
|
|
101
|
+
functionName: string;
|
|
102
|
+
url: string;
|
|
103
|
+
line: number;
|
|
104
|
+
column: number;
|
|
105
|
+
samples: number;
|
|
106
|
+
selfMicros: number;
|
|
107
|
+
};
|
|
108
|
+
/** The minimal frame identity the join needs: a function name, a script url, and a one-based line. */
|
|
109
|
+
export type FrameRef = {
|
|
110
|
+
functionName: string;
|
|
111
|
+
url: string;
|
|
112
|
+
line: number;
|
|
113
|
+
};
|
|
114
|
+
/** One caller → callee relation from the profile's call tree, weighted by the callee's subtree samples. */
|
|
115
|
+
export type RuntimeCallEdge = {
|
|
116
|
+
caller: FrameRef;
|
|
117
|
+
callee: FrameRef;
|
|
118
|
+
samples: number;
|
|
119
|
+
};
|
|
120
|
+
export declare class CpuProfile {
|
|
121
|
+
/**
|
|
122
|
+
* Parses and validates raw `.cpuprofile` JSON text. Throws a `ZodError` if
|
|
123
|
+
* the document does not match the V8 profile shape.
|
|
124
|
+
*/
|
|
125
|
+
static parse(jsonText: string): CpuProfileData;
|
|
126
|
+
/**
|
|
127
|
+
* Collapses the profile into one {@link FrameSample} per profile node that
|
|
128
|
+
* received at least one sample.
|
|
129
|
+
*
|
|
130
|
+
* Self time is summed from `timeDeltas`, attributing `timeDeltas[i]` to
|
|
131
|
+
* `samples[i]` — the standard self-time approximation where total attributed
|
|
132
|
+
* time equals the sum of all deltas. When `samples`/`timeDeltas` are absent,
|
|
133
|
+
* it falls back to each node's `hitCount` with zero self time.
|
|
134
|
+
*/
|
|
135
|
+
static aggregate(profile: CpuProfileData): FrameSample[];
|
|
136
|
+
/** Total number of sampling ticks in the profile, for coverage reporting. */
|
|
137
|
+
static totalSamples(profile: CpuProfileData): number;
|
|
138
|
+
/**
|
|
139
|
+
* Extracts the runtime call graph from the profile's call tree: one edge per
|
|
140
|
+
* parent → child relation (the parent function was on the stack directly above
|
|
141
|
+
* the child), weighted by the child's subtree sample count — how much execution
|
|
142
|
+
* flowed through that call. Frames carry one-based lines so they resolve against
|
|
143
|
+
* graph node ranges, mirroring {@link aggregate}.
|
|
144
|
+
*/
|
|
145
|
+
static callEdges(profile: CpuProfileData): RuntimeCallEdge[];
|
|
146
|
+
private static frameRef;
|
|
147
|
+
/**
|
|
148
|
+
* Sample count per profile-node id: from the per-tick `samples` array when
|
|
149
|
+
* present, otherwise each node's `hitCount`. The same weight {@link aggregate}
|
|
150
|
+
* attributes, keyed here for the call-tree walk.
|
|
151
|
+
*/
|
|
152
|
+
private static samplesByNode;
|
|
153
|
+
/**
|
|
154
|
+
* Total samples in each profile node's subtree (itself plus all descendants)
|
|
155
|
+
* over the call tree. Iterative post-order with an explicit stack so a deep call
|
|
156
|
+
* chain cannot overflow, and a guard so a malformed non-tree cannot loop.
|
|
157
|
+
*/
|
|
158
|
+
private static subtreeSamples;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=cpu_profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cpu_profile.d.ts","sourceRoot":"","sources":["../../src/enrich/cpu_profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAsBxB;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM3B,CAAC;AACH,MAAM,MAA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based** in the V8 inspector protocol, unlike the one-based
|
|
5
|
+
* lines ts-morph (and therefore the graph's `range`) uses.
|
|
6
|
+
*/
|
|
7
|
+
const CallFrameSchema = z.object({
|
|
8
|
+
functionName: z.string(),
|
|
9
|
+
scriptId: z.union([z.string(), z.number()]).optional(),
|
|
10
|
+
url: z.string(),
|
|
11
|
+
lineNumber: z.number(),
|
|
12
|
+
columnNumber: z.number(),
|
|
13
|
+
});
|
|
14
|
+
const ProfileNodeSchema = z.object({
|
|
15
|
+
id: z.number(),
|
|
16
|
+
callFrame: CallFrameSchema,
|
|
17
|
+
hitCount: z.number().optional(),
|
|
18
|
+
children: z.array(z.number()).optional(),
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* The on-disk shape of a `node --cpu-prof` output (`.cpuprofile`). `samples`
|
|
22
|
+
* holds one profile-node id per sampling tick; `timeDeltas` holds the elapsed
|
|
23
|
+
* microseconds preceding each tick. Both are optional because some producers
|
|
24
|
+
* emit only per-node `hitCount`.
|
|
25
|
+
*/
|
|
26
|
+
export const CpuProfileSchema = z.object({
|
|
27
|
+
nodes: z.array(ProfileNodeSchema),
|
|
28
|
+
startTime: z.number().optional(),
|
|
29
|
+
endTime: z.number().optional(),
|
|
30
|
+
samples: z.array(z.number()).optional(),
|
|
31
|
+
timeDeltas: z.array(z.number()).optional(),
|
|
32
|
+
});
|
|
33
|
+
export class CpuProfile {
|
|
34
|
+
/**
|
|
35
|
+
* Parses and validates raw `.cpuprofile` JSON text. Throws a `ZodError` if
|
|
36
|
+
* the document does not match the V8 profile shape.
|
|
37
|
+
*/
|
|
38
|
+
static parse(jsonText) {
|
|
39
|
+
return CpuProfileSchema.parse(JSON.parse(jsonText));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Collapses the profile into one {@link FrameSample} per profile node that
|
|
43
|
+
* received at least one sample.
|
|
44
|
+
*
|
|
45
|
+
* Self time is summed from `timeDeltas`, attributing `timeDeltas[i]` to
|
|
46
|
+
* `samples[i]` — the standard self-time approximation where total attributed
|
|
47
|
+
* time equals the sum of all deltas. When `samples`/`timeDeltas` are absent,
|
|
48
|
+
* it falls back to each node's `hitCount` with zero self time.
|
|
49
|
+
*/
|
|
50
|
+
static aggregate(profile) {
|
|
51
|
+
const samplesByNode = new Map();
|
|
52
|
+
const microsByNode = new Map();
|
|
53
|
+
const samples = profile.samples;
|
|
54
|
+
if (samples !== undefined && samples.length > 0) {
|
|
55
|
+
const deltas = profile.timeDeltas ?? [];
|
|
56
|
+
for (let index = 0; index < samples.length; index += 1) {
|
|
57
|
+
const nodeId = samples[index];
|
|
58
|
+
samplesByNode.set(nodeId, (samplesByNode.get(nodeId) ?? 0) + 1);
|
|
59
|
+
const delta = deltas[index] ?? 0;
|
|
60
|
+
const safeDelta = delta > 0 ? delta : 0;
|
|
61
|
+
microsByNode.set(nodeId, (microsByNode.get(nodeId) ?? 0) + safeDelta);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
for (const node of profile.nodes) {
|
|
66
|
+
const hits = node.hitCount ?? 0;
|
|
67
|
+
if (hits > 0) {
|
|
68
|
+
samplesByNode.set(node.id, hits);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const frames = [];
|
|
73
|
+
for (const node of profile.nodes) {
|
|
74
|
+
const sampleCount = samplesByNode.get(node.id) ?? 0;
|
|
75
|
+
if (sampleCount === 0) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
frames.push({
|
|
79
|
+
functionName: node.callFrame.functionName,
|
|
80
|
+
url: node.callFrame.url,
|
|
81
|
+
line: node.callFrame.lineNumber + 1,
|
|
82
|
+
column: node.callFrame.columnNumber,
|
|
83
|
+
samples: sampleCount,
|
|
84
|
+
selfMicros: microsByNode.get(node.id) ?? 0,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return frames;
|
|
88
|
+
}
|
|
89
|
+
/** Total number of sampling ticks in the profile, for coverage reporting. */
|
|
90
|
+
static totalSamples(profile) {
|
|
91
|
+
if (profile.samples !== undefined && profile.samples.length > 0) {
|
|
92
|
+
return profile.samples.length;
|
|
93
|
+
}
|
|
94
|
+
return profile.nodes.reduce((sum, node) => sum + (node.hitCount ?? 0), 0);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Extracts the runtime call graph from the profile's call tree: one edge per
|
|
98
|
+
* parent → child relation (the parent function was on the stack directly above
|
|
99
|
+
* the child), weighted by the child's subtree sample count — how much execution
|
|
100
|
+
* flowed through that call. Frames carry one-based lines so they resolve against
|
|
101
|
+
* graph node ranges, mirroring {@link aggregate}.
|
|
102
|
+
*/
|
|
103
|
+
static callEdges(profile) {
|
|
104
|
+
const subtree = CpuProfile.subtreeSamples(profile);
|
|
105
|
+
const nodeById = new Map(profile.nodes.map((node) => [node.id, node]));
|
|
106
|
+
const edges = [];
|
|
107
|
+
for (const node of profile.nodes) {
|
|
108
|
+
for (const childId of node.children ?? []) {
|
|
109
|
+
const child = nodeById.get(childId);
|
|
110
|
+
if (child === undefined) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
edges.push({
|
|
114
|
+
caller: CpuProfile.frameRef(node.callFrame),
|
|
115
|
+
callee: CpuProfile.frameRef(child.callFrame),
|
|
116
|
+
samples: subtree.get(childId) ?? 0,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return edges;
|
|
121
|
+
}
|
|
122
|
+
static frameRef(callFrame) {
|
|
123
|
+
return { functionName: callFrame.functionName, url: callFrame.url, line: callFrame.lineNumber + 1 };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Sample count per profile-node id: from the per-tick `samples` array when
|
|
127
|
+
* present, otherwise each node's `hitCount`. The same weight {@link aggregate}
|
|
128
|
+
* attributes, keyed here for the call-tree walk.
|
|
129
|
+
*/
|
|
130
|
+
static samplesByNode(profile) {
|
|
131
|
+
const counts = new Map();
|
|
132
|
+
const samples = profile.samples;
|
|
133
|
+
if (samples !== undefined && samples.length > 0) {
|
|
134
|
+
for (const nodeId of samples) {
|
|
135
|
+
counts.set(nodeId, (counts.get(nodeId) ?? 0) + 1);
|
|
136
|
+
}
|
|
137
|
+
return counts;
|
|
138
|
+
}
|
|
139
|
+
for (const node of profile.nodes) {
|
|
140
|
+
const hits = node.hitCount ?? 0;
|
|
141
|
+
if (hits > 0) {
|
|
142
|
+
counts.set(node.id, hits);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return counts;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Total samples in each profile node's subtree (itself plus all descendants)
|
|
149
|
+
* over the call tree. Iterative post-order with an explicit stack so a deep call
|
|
150
|
+
* chain cannot overflow, and a guard so a malformed non-tree cannot loop.
|
|
151
|
+
*/
|
|
152
|
+
static subtreeSamples(profile) {
|
|
153
|
+
const self = CpuProfile.samplesByNode(profile);
|
|
154
|
+
const nodeById = new Map(profile.nodes.map((node) => [node.id, node]));
|
|
155
|
+
const subtree = new Map();
|
|
156
|
+
for (const root of profile.nodes) {
|
|
157
|
+
if (subtree.has(root.id)) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const stack = [root.id];
|
|
161
|
+
const onStack = new Set([root.id]);
|
|
162
|
+
while (stack.length > 0) {
|
|
163
|
+
const id = stack[stack.length - 1];
|
|
164
|
+
const children = (nodeById.get(id)?.children ?? []).filter((child) => nodeById.has(child));
|
|
165
|
+
const pending = children.filter((child) => subtree.has(child) === false && onStack.has(child) === false);
|
|
166
|
+
if (pending.length > 0) {
|
|
167
|
+
for (const child of pending) {
|
|
168
|
+
onStack.add(child);
|
|
169
|
+
stack.push(child);
|
|
170
|
+
}
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
let sum = self.get(id) ?? 0;
|
|
174
|
+
for (const child of children) {
|
|
175
|
+
sum += subtree.get(child) ?? 0;
|
|
176
|
+
}
|
|
177
|
+
subtree.set(id, sum);
|
|
178
|
+
onStack.delete(id);
|
|
179
|
+
stack.pop();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return subtree;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=cpu_profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cpu_profile.js","sourceRoot":"","sources":["../../src/enrich/cpu_profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtD,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,SAAS,EAAE,eAAe;IAC1B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CACxC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;IACjC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,OAAO,EAAE,CAAC,CAAC,MAAM,EAA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,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACrB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBACnB,KAAK,CAAC,GAAG,EAAE,CAAC;YACb,CAAC;QACF,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;CACD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { KuzuStore } from '../store/kuzu_store.js';
|
|
2
|
+
import { DroppedFrameGroup } from './runtime_join.js';
|
|
3
|
+
/** The telemetry source tag written into `metadata.runtime.source`. */
|
|
4
|
+
export declare const RUNTIME_SOURCE_CPU_PROFILE = "v8-cpuprofile";
|
|
5
|
+
/** Namespaced key under which runtime metrics are stored on a node's metadata. */
|
|
6
|
+
export declare const RUNTIME_METADATA_KEY = "runtime";
|
|
7
|
+
/** Edge kind under which the runtime call graph extracted from the profile is stored. */
|
|
8
|
+
export declare const RUNTIME_CALL_EDGE_KIND = "CALLS_RUNTIME";
|
|
9
|
+
/**
|
|
10
|
+
* The measured-weight metrics attached to a node under `metadata.runtime`. The
|
|
11
|
+
* shape is intentionally open-ended (latency, call frequency, cost, … may join
|
|
12
|
+
* later); a CPU profile populates self time and sample count.
|
|
13
|
+
*/
|
|
14
|
+
export type RuntimeMetrics = {
|
|
15
|
+
source: string;
|
|
16
|
+
samples: number;
|
|
17
|
+
selfMicros: number;
|
|
18
|
+
selfMs: number;
|
|
19
|
+
};
|
|
20
|
+
export type Hotspot = {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
kind: string;
|
|
24
|
+
filePath: string;
|
|
25
|
+
selfMs: number;
|
|
26
|
+
samples: number;
|
|
27
|
+
};
|
|
28
|
+
export type EnrichReport = {
|
|
29
|
+
totalSamples: number;
|
|
30
|
+
matchedNodes: number;
|
|
31
|
+
matchedFrames: number;
|
|
32
|
+
matchedSamples: number;
|
|
33
|
+
matchedSelfMs: number;
|
|
34
|
+
matchedByName: number;
|
|
35
|
+
matchedByRange: number;
|
|
36
|
+
droppedFrames: number;
|
|
37
|
+
droppedSamples: number;
|
|
38
|
+
/** Runtime call edges (`CALLS_RUNTIME`) attached after both endpoints resolved to graph nodes. */
|
|
39
|
+
runtimeEdges: number;
|
|
40
|
+
/** Profile call-tree edges dropped because an endpoint resolved to no node, or to the same node (recursion). */
|
|
41
|
+
droppedCallEdges: number;
|
|
42
|
+
dropped: DroppedFrameGroup[];
|
|
43
|
+
hotspots: Hotspot[];
|
|
44
|
+
};
|
|
45
|
+
export type EnrichOptions = {
|
|
46
|
+
/** Project root the profile's absolute frame urls resolve against. */
|
|
47
|
+
root: string;
|
|
48
|
+
};
|
|
49
|
+
export declare class RuntimeEnricher {
|
|
50
|
+
/**
|
|
51
|
+
* Ingests a V8 CPU profile and attaches `metadata.runtime` (self time and
|
|
52
|
+
* sample count) onto the graph nodes whose ranges enclose the profiled
|
|
53
|
+
* frames. Existing metadata is preserved; only the `runtime` key is written,
|
|
54
|
+
* so re-running with the same profile is idempotent. Unmatched frames are
|
|
55
|
+
* counted and returned in the report rather than dropped silently.
|
|
56
|
+
*/
|
|
57
|
+
static enrich(store: KuzuStore, profileText: string, options: EnrichOptions): Promise<EnrichReport>;
|
|
58
|
+
private static toMetrics;
|
|
59
|
+
/** Builds a `CALLS_RUNTIME` graph edge from a resolved runtime call edge, weighted by its sample count. */
|
|
60
|
+
private static toCallEdge;
|
|
61
|
+
/** Converts microseconds to milliseconds, rounded to microsecond precision. */
|
|
62
|
+
private static microsToMs;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=runtime_enricher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime_enricher.d.ts","sourceRoot":"","sources":["../../src/enrich/runtime_enricher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAgD,MAAM,mBAAmB,CAAC;AAEpG,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