feat/debug-node #41
23
app/src/lib/node-registry/debugNode.ts
Normal file
23
app/src/lib/node-registry/debugNode.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const data: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
export function clearDebugData() {
|
||||||
|
for (const key in data) {
|
||||||
|
delete data[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDebugData() {
|
||||||
|
return { ...data };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const debugNode = {
|
||||||
|
id: 'max/plantarium/debug',
|
||||||
|
inputs: {
|
||||||
|
a: {
|
||||||
|
type: '*'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
execute(data: Int32Array) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
} as const;
|
||||||
@@ -59,6 +59,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
private definitionMap: Map<string, NodeDefinition> = new Map();
|
private definitionMap: Map<string, NodeDefinition> = new Map();
|
||||||
|
|
||||||
private seed = Math.floor(Math.random() * 100000000);
|
private seed = Math.floor(Math.random() * 100000000);
|
||||||
|
private debugData: Record<string, Int32Array> = {};
|
||||||
|
|
||||||
perf?: PerformanceStore;
|
perf?: PerformanceStore;
|
||||||
|
|
||||||
@@ -139,6 +140,14 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const node of graphNodes) {
|
||||||
|
if (node.type.endsWith('/debug')) {
|
||||||
|
node.state = node.state || {};
|
||||||
|
node.state.depth = Math.min(...node.state.parents.map(s => s.state.depth), 1) - 1;
|
||||||
|
nodes.push(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [outputNode, nodes] as const;
|
return [outputNode, nodes] as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +155,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
this.perf?.addPoint('runtime');
|
this.perf?.addPoint('runtime');
|
||||||
|
|
||||||
let a = performance.now();
|
let a = performance.now();
|
||||||
|
this.debugData = {};
|
||||||
|
|
||||||
// Then we add some metadata to the graph
|
// Then we add some metadata to the graph
|
||||||
const [outputNode, nodes] = await this.addMetaData(graph);
|
const [outputNode, nodes] = await this.addMetaData(graph);
|
||||||
@@ -245,6 +255,9 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
log.log(`Inputs:`, inputs);
|
log.log(`Inputs:`, inputs);
|
||||||
a = performance.now();
|
a = performance.now();
|
||||||
results[node.id] = node_type.execute(encoded_inputs);
|
results[node.id] = node_type.execute(encoded_inputs);
|
||||||
|
if (node_type.id.endsWith('/debug')) {
|
||||||
|
this.debugData[node.id] = results[node.id];
|
||||||
|
}
|
||||||
log.log('Executed', node.type, node.id);
|
log.log('Executed', node.type, node.id);
|
||||||
b = performance.now();
|
b = performance.now();
|
||||||
|
|
||||||
@@ -273,6 +286,10 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
return res as unknown as Int32Array;
|
return res as unknown as Int32Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDebugData() {
|
||||||
|
return this.debugData;
|
||||||
|
}
|
||||||
|
|
||||||
getPerformanceData() {
|
getPerformanceData() {
|
||||||
return this.perf?.get();
|
return this.perf?.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { debugNode } from '$lib/node-registry/debugNode';
|
||||||
import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index';
|
import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index';
|
||||||
import type { Graph } from '@nodarium/types';
|
import type { Graph } from '@nodarium/types';
|
||||||
import { createPerformanceStore } from '@nodarium/utils';
|
import { createPerformanceStore } from '@nodarium/utils';
|
||||||
@@ -5,7 +6,7 @@ import { MemoryRuntimeExecutor } from './runtime-executor';
|
|||||||
import { MemoryRuntimeCache } from './runtime-executor-cache';
|
import { MemoryRuntimeCache } from './runtime-executor-cache';
|
||||||
|
|
||||||
const indexDbCache = new IndexDBCache('node-registry');
|
const indexDbCache = new IndexDBCache('node-registry');
|
||||||
const nodeRegistry = new RemoteNodeRegistry('', indexDbCache);
|
const nodeRegistry = new RemoteNodeRegistry('', indexDbCache, [debugNode]);
|
||||||
|
|
||||||
const cache = new MemoryRuntimeCache();
|
const cache = new MemoryRuntimeCache();
|
||||||
const executor = new MemoryRuntimeExecutor(nodeRegistry, cache);
|
const executor = new MemoryRuntimeExecutor(nodeRegistry, cache);
|
||||||
@@ -43,3 +44,7 @@ export async function executeGraph(
|
|||||||
export function getPerformanceData() {
|
export function getPerformanceData() {
|
||||||
return performanceStore.get();
|
return performanceStore.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getDebugData() {
|
||||||
|
return executor.getDebugData();
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import Grid from '$lib/grid';
|
import Grid from '$lib/grid';
|
||||||
import { debounceAsyncFunction } from '$lib/helpers';
|
import { debounceAsyncFunction } from '$lib/helpers';
|
||||||
import { createKeyMap } from '$lib/helpers/createKeyMap';
|
import { createKeyMap } from '$lib/helpers/createKeyMap';
|
||||||
|
import { debugNode } from '$lib/node-registry/debugNode.js';
|
||||||
import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index';
|
import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index';
|
||||||
import NodeStore from '$lib/node-store/NodeStore.svelte';
|
import NodeStore from '$lib/node-store/NodeStore.svelte';
|
||||||
import PerformanceViewer from '$lib/performance/PerformanceViewer.svelte';
|
import PerformanceViewer from '$lib/performance/PerformanceViewer.svelte';
|
||||||
@@ -33,19 +34,6 @@
|
|||||||
|
|
||||||
const registryCache = new IndexDBCache('node-registry');
|
const registryCache = new IndexDBCache('node-registry');
|
||||||
|
|
||||||
const debugNode = {
|
|
||||||
id: 'max/plantarium/debug',
|
|
||||||
inputs: {
|
|
||||||
a: {
|
|
||||||
type: '*'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
execute(data: Int32Array) {
|
|
||||||
console.log({ data });
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
const nodeRegistry = new RemoteNodeRegistry('', registryCache, [debugNode]);
|
const nodeRegistry = new RemoteNodeRegistry('', registryCache, [debugNode]);
|
||||||
const workerRuntime = new WorkerRuntimeExecutor();
|
const workerRuntime = new WorkerRuntimeExecutor();
|
||||||
const runtimeCache = new MemoryRuntimeCache();
|
const runtimeCache = new MemoryRuntimeCache();
|
||||||
|
|||||||
Reference in New Issue
Block a user