feat: improve logger
This commit is contained in:
parent
070a5b52d0
commit
415d773610
@ -78,11 +78,20 @@ export const createLogger = (() => {
|
|||||||
return (scope: string) => {
|
return (scope: string) => {
|
||||||
maxLength = Math.max(maxLength, scope.length);
|
maxLength = Math.max(maxLength, scope.length);
|
||||||
let muted = false;
|
let muted = false;
|
||||||
|
|
||||||
|
let isGrouped = false;
|
||||||
|
|
||||||
|
function s(color: string, ...args: any) {
|
||||||
|
return isGrouped ? [...args] : [`[%c${scope.padEnd(maxLength, " ")}]:`, `color: ${color}`, ...args];
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
log: (...args: any[]) => !muted && console.log(`[%c${scope.padEnd(maxLength, " ")}]:`, "color: #888", ...args),
|
log: (...args: any[]) => !muted && console.log(...s("#888", ...args)),
|
||||||
info: (...args: any[]) => !muted && console.info(`[%c${scope.padEnd(maxLength, " ")}]:`, "color: #888", ...args),
|
info: (...args: any[]) => !muted && console.info(...s("#888", ...args)),
|
||||||
warn: (...args: any[]) => !muted && console.warn(`[%c${scope.padEnd(maxLength, " ")}]:`, "color: #888", ...args),
|
warn: (...args: any[]) => !muted && console.warn(...s("#888", ...args)),
|
||||||
error: (...args: any[]) => console.error(`[%c${scope.padEnd(maxLength, " ")}]:`, "color: #f88", ...args),
|
error: (...args: any[]) => console.error(...s("#f88", ...args)),
|
||||||
|
group: (...args: any[]) => { if (!muted) { console.groupCollapsed(...s("#888", ...args)); isGrouped = true; } },
|
||||||
|
groupEnd: () => { if (!muted) { console.groupEnd(); isGrouped = false } },
|
||||||
mute() {
|
mute() {
|
||||||
muted = true;
|
muted = true;
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import type { Graph, NodeRegistry, NodeDefinition, RuntimeExecutor } from "@nodes/types";
|
import type { Graph, NodeRegistry, NodeDefinition, RuntimeExecutor } from "@nodes/types";
|
||||||
import { fastHash, concatEncodedArrays, encodeFloat, encodeNestedArray, decodeNestedArray } from "@nodes/utils"
|
import { fastHash, concatEncodedArrays, encodeFloat, decodeNestedArray } from "@nodes/utils"
|
||||||
|
import { createLogger } from "./helpers";
|
||||||
|
|
||||||
|
const log = createLogger("runtime-executor");
|
||||||
|
|
||||||
export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||||
|
|
||||||
@ -131,7 +134,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
if (input.value !== undefined) {
|
if (input.value !== undefined) {
|
||||||
inputs[key] = input.value;
|
inputs[key] = input.value;
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Setting ${input.setting} is not defined`);
|
log.warn(`Setting ${input.setting} is not defined`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
inputs[key] = settings[input.setting] as number;
|
inputs[key] = settings[input.setting] as number;
|
||||||
@ -160,8 +163,8 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// console.log(" ");
|
// log.log(" ");
|
||||||
// console.log("--> EXECUTING NODE " + node_type.id, node.id);
|
// log.log("--> EXECUTING NODE " + node_type.id, node.id);
|
||||||
|
|
||||||
|
|
||||||
// execute the node and store the result
|
// execute the node and store the result
|
||||||
@ -174,11 +177,11 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
}))}`;
|
}))}`;
|
||||||
|
|
||||||
const a1 = performance.now();
|
const a1 = performance.now();
|
||||||
// console.log(`${a1 - a0}ms hashed inputs: ${node.id} -> ${cacheKey}`);
|
// log.log(`${a1 - a0}ms hashed inputs: ${node.id} -> ${cacheKey}`);
|
||||||
|
|
||||||
if (false && this.cache[cacheKey] && this.cache[cacheKey].eol > Date.now()) {
|
if (false && this.cache[cacheKey] && this.cache[cacheKey].eol > Date.now()) {
|
||||||
results[node.id] = this.cache[cacheKey].value;
|
results[node.id] = this.cache[cacheKey].value;
|
||||||
console.log(`Using cached value`);
|
log.log(`Using cached value`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,32 +202,32 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
|
|
||||||
// console.log(transformed_inputs);
|
// log.log(transformed_inputs);
|
||||||
|
|
||||||
const a2 = performance.now();
|
const a2 = performance.now();
|
||||||
|
|
||||||
// console.log(`${a2 - a1}ms TRANSFORMED_INPUTS`);
|
// log.log(`${a2 - a1}ms TRANSFORMED_INPUTS`);
|
||||||
|
|
||||||
const encoded_inputs = concatEncodedArrays(transformed_inputs);
|
const encoded_inputs = concatEncodedArrays(transformed_inputs);
|
||||||
const a3 = performance.now();
|
const a3 = performance.now();
|
||||||
console.groupCollapsed(`executing ${node_type.id || node.id}`);
|
log.group(`executing ${node_type.id || node.id}`);
|
||||||
console.log(`Inputs:`, transformed_inputs);
|
log.log(`Inputs:`, transformed_inputs);
|
||||||
console.log(`Encoded Inputs:`, encoded_inputs);
|
log.log(`Encoded Inputs:`, encoded_inputs);
|
||||||
results[node.id] = node_type.execute(encoded_inputs);
|
results[node.id] = node_type.execute(encoded_inputs);
|
||||||
console.log("Result:", results[node.id]);
|
log.log("Result:", results[node.id]);
|
||||||
console.log("Result (decoded):", decodeNestedArray(results[node.id]));
|
log.log("Result (decoded):", decodeNestedArray(results[node.id]));
|
||||||
console.groupEnd();
|
log.groupEnd();
|
||||||
const duration = performance.now() - a3;
|
const duration = performance.now() - a3;
|
||||||
if (duration > 5) {
|
if (duration > 5) {
|
||||||
this.cache[cacheKey] = { eol: Date.now() + 10_000, value: results[node.id] };
|
this.cache[cacheKey] = { eol: Date.now() + 10_000, value: results[node.id] };
|
||||||
// console.log(`Caching for 10 seconds`);
|
// log.log(`Caching for 10 seconds`);
|
||||||
}
|
}
|
||||||
// console.log(`${duration}ms Executed`);
|
// log.log(`${duration}ms Executed`);
|
||||||
const a4 = performance.now();
|
const a4 = performance.now();
|
||||||
// console.log(`${a4 - a0}ms e2e duration`);
|
// log.log(`${a4 - a0}ms e2e duration`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.groupEnd();
|
log.groupEnd();
|
||||||
console.error(`Error executing node ${node_type.id || node.id}`, e);
|
log.error(`Error executing node ${node_type.id || node.id}`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,21 @@
|
|||||||
},
|
},
|
||||||
shortcuts: {},
|
shortcuts: {},
|
||||||
nodeStore: {},
|
nodeStore: {},
|
||||||
graph: {},
|
graph: {
|
||||||
|
id: "graph",
|
||||||
|
icon: "i-tabler-git-fork",
|
||||||
|
definition: {
|
||||||
|
randomSeed: {
|
||||||
|
type: "boolean",
|
||||||
|
label: "Random Seed",
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
activeNode: {
|
activeNode: {
|
||||||
id: "Active Node",
|
id: "Active Node",
|
||||||
icon: "i-tabler-adjustments",
|
icon: "i-tabler-adjustments",
|
||||||
props: { node: undefined, manager },
|
props: { node: undefined, manager: undefined },
|
||||||
component: ActiveNode,
|
component: ActiveNode,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -122,18 +132,10 @@
|
|||||||
graph = templates.tree(store.amount);
|
graph = templates.tree(store.amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.graph = {
|
settings.graph.settings = writable(ev.detail.values);
|
||||||
icon: "i-tabler-git-fork",
|
settings.graph.definition = {
|
||||||
id: "graph",
|
...settings.graph.definition,
|
||||||
settings: writable(ev.detail.values),
|
|
||||||
definition: {
|
|
||||||
randomSeed: {
|
|
||||||
type: "boolean",
|
|
||||||
label: "Random Seed",
|
|
||||||
value: true,
|
|
||||||
},
|
|
||||||
...ev.detail.types,
|
...ev.detail.types,
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = settings;
|
settings = settings;
|
||||||
|
@ -70,20 +70,27 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
|||||||
for i in 0..points {
|
for i in 0..points {
|
||||||
let a = i as f64 / (points - 1) as f64;
|
let a = i as f64 / (points - 1) as f64;
|
||||||
|
|
||||||
let px = Vector2::new(j as f64 + a * length * scale, a * scale as f64);
|
let px = Vector2::new(1000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||||
let pz = Vector2::new(a * scale as f64, j as f64 + a * length * scale);
|
let py = Vector2::new(2000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||||
|
let pz = Vector2::new(3000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||||
|
|
||||||
let nx = open_simplex_2d(px, &hasher) as f32
|
let nx = open_simplex_2d(px, &hasher) as f32
|
||||||
* strength
|
* strength
|
||||||
* 0.1
|
* 0.1
|
||||||
* lerp(1.0, a as f32, fix_bottom);
|
* lerp(1.0, a as f32, fix_bottom);
|
||||||
|
|
||||||
|
let ny = open_simplex_2d(py, &hasher) as f32
|
||||||
|
* strength
|
||||||
|
* 0.1
|
||||||
|
* lerp(1.0, a as f32, fix_bottom);
|
||||||
|
|
||||||
let nz = open_simplex_2d(pz, &hasher) as f32
|
let nz = open_simplex_2d(pz, &hasher) as f32
|
||||||
* strength
|
* strength
|
||||||
* 0.1
|
* 0.1
|
||||||
* lerp(1.0, a as f32, fix_bottom);
|
* lerp(1.0, a as f32, fix_bottom);
|
||||||
|
|
||||||
plant[3 + i * 4] = encode_float(decode_float(plant[3 + i * 4]) + nx);
|
plant[3 + i * 4] = encode_float(decode_float(plant[3 + i * 4]) + nx);
|
||||||
|
plant[4 + i * 4] = encode_float(decode_float(plant[4 + i * 4]) + ny);
|
||||||
plant[5 + i * 4] = encode_float(decode_float(plant[5 + i * 4]) + nz);
|
plant[5 + i * 4] = encode_float(decode_float(plant[5 + i * 4]) + nz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user