mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-05-04 23:01:51 +00:00
chore(format): no intentional behaviour change - runs pretty
This commit is contained in:
@@ -1,19 +1,15 @@
|
||||
import {
|
||||
ItemView,
|
||||
WorkspaceLeaf
|
||||
} from "obsidian";
|
||||
import TestPaneComponent from "./TestPane.svelte"
|
||||
import type ObsidianLiveSyncPlugin from "../../../main.ts"
|
||||
import { ItemView, WorkspaceLeaf } from "obsidian";
|
||||
import TestPaneComponent from "./TestPane.svelte";
|
||||
import type ObsidianLiveSyncPlugin from "../../../main.ts";
|
||||
import type { ModuleDev } from "../ModuleDev.ts";
|
||||
export const VIEW_TYPE_TEST = "ols-pane-test";
|
||||
//Log view
|
||||
export class TestPaneView extends ItemView {
|
||||
|
||||
component?: TestPaneComponent;
|
||||
plugin: ObsidianLiveSyncPlugin;
|
||||
moduleDev: ModuleDev;
|
||||
icon = "view-log";
|
||||
title: string = "Self-hosted LiveSync Test and Results"
|
||||
title: string = "Self-hosted LiveSync Test and Results";
|
||||
navigation = true;
|
||||
|
||||
getIcon(): string {
|
||||
@@ -26,7 +22,6 @@ export class TestPaneView extends ItemView {
|
||||
this.moduleDev = moduleDev;
|
||||
}
|
||||
|
||||
|
||||
getViewType() {
|
||||
return VIEW_TYPE_TEST;
|
||||
}
|
||||
@@ -41,7 +36,7 @@ export class TestPaneView extends ItemView {
|
||||
target: this.contentEl,
|
||||
props: {
|
||||
plugin: this.plugin,
|
||||
moduleDev: this.moduleDev
|
||||
moduleDev: this.moduleDev,
|
||||
},
|
||||
});
|
||||
await Promise.resolve();
|
||||
|
||||
@@ -7,40 +7,44 @@ export function enableTestFunction(plugin_: ObsidianLiveSyncPlugin) {
|
||||
plugin = plugin_;
|
||||
}
|
||||
export function addDebugFileLog(message: any, stackLog = false) {
|
||||
fireAndForget(serialized("debug-log", async () => {
|
||||
const now = new Date();
|
||||
const filename = `debug-log`
|
||||
const time = now.toISOString().split("T")[0];
|
||||
const outFile = `${filename}${time}.jsonl`;
|
||||
// const messageContent = typeof message == "string" ? message : message instanceof Error ? `${message.name}:${message.message}` : JSON.stringify(message, null, 2);
|
||||
const timestamp = now.toLocaleString();
|
||||
const timestampEpoch = now;
|
||||
let out = { "timestamp": timestamp, epoch: timestampEpoch, } as Record<string, any>;
|
||||
if (message instanceof Error) {
|
||||
// debugger;
|
||||
// console.dir(message.stack);
|
||||
out = { ...out, message };
|
||||
} else if (stackLog) {
|
||||
if (stackLog) {
|
||||
const stackE = new Error();
|
||||
const stack = stackE.stack;
|
||||
out = { ...out, stack }
|
||||
fireAndForget(
|
||||
serialized("debug-log", async () => {
|
||||
const now = new Date();
|
||||
const filename = `debug-log`;
|
||||
const time = now.toISOString().split("T")[0];
|
||||
const outFile = `${filename}${time}.jsonl`;
|
||||
// const messageContent = typeof message == "string" ? message : message instanceof Error ? `${message.name}:${message.message}` : JSON.stringify(message, null, 2);
|
||||
const timestamp = now.toLocaleString();
|
||||
const timestampEpoch = now;
|
||||
let out = { timestamp: timestamp, epoch: timestampEpoch } as Record<string, any>;
|
||||
if (message instanceof Error) {
|
||||
// debugger;
|
||||
// console.dir(message.stack);
|
||||
out = { ...out, message };
|
||||
} else if (stackLog) {
|
||||
if (stackLog) {
|
||||
const stackE = new Error();
|
||||
const stack = stackE.stack;
|
||||
out = { ...out, stack };
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof message == "object") {
|
||||
out = { ...out, ...message, }
|
||||
} else {
|
||||
out = {
|
||||
result: message
|
||||
if (typeof message == "object") {
|
||||
out = { ...out, ...message };
|
||||
} else {
|
||||
out = {
|
||||
result: message,
|
||||
};
|
||||
}
|
||||
}
|
||||
// const out = "--" + timestamp + "--\n" + messageContent + " " + (stack || "");
|
||||
// const out
|
||||
try {
|
||||
await plugin.storageAccess.appendHiddenFile(plugin.app.vault.configDir + "/ls-debug/" + outFile, JSON.stringify(out) + "\n")
|
||||
} catch {
|
||||
|
||||
//NO OP
|
||||
}
|
||||
}));
|
||||
}
|
||||
// const out = "--" + timestamp + "--\n" + messageContent + " " + (stack || "");
|
||||
// const out
|
||||
try {
|
||||
await plugin.storageAccess.appendHiddenFile(
|
||||
plugin.app.vault.configDir + "/ls-debug/" + outFile,
|
||||
JSON.stringify(out) + "\n"
|
||||
);
|
||||
} catch {
|
||||
//NO OP
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ const measures = new Map<string, MeasureResult>();
|
||||
function clearResult(name: string) {
|
||||
measures.set(name, [0, 0]);
|
||||
}
|
||||
async function measureEach(name: string, proc: () => (void | Promise<void>)) {
|
||||
async function measureEach(name: string, proc: () => void | Promise<void>) {
|
||||
const [times, spent] = measures.get(name) ?? [0, 0];
|
||||
|
||||
const start = performance.now();
|
||||
@@ -15,57 +15,76 @@ async function measureEach(name: string, proc: () => (void | Promise<void>)) {
|
||||
if (result instanceof Promise) await result;
|
||||
const end = performance.now();
|
||||
measures.set(name, [times + 1, spent + (end - start)]);
|
||||
|
||||
}
|
||||
function formatNumber(num: number) {
|
||||
return num.toLocaleString('en-US', { maximumFractionDigits: 2 });
|
||||
return num.toLocaleString("en-US", { maximumFractionDigits: 2 });
|
||||
}
|
||||
async function measure(name: string, proc: () => (void | Promise<void>), times: number = 10000, duration: number = 1000): Promise<NamedMeasureResult> {
|
||||
async function measure(
|
||||
name: string,
|
||||
proc: () => void | Promise<void>,
|
||||
times: number = 10000,
|
||||
duration: number = 1000
|
||||
): Promise<NamedMeasureResult> {
|
||||
const from = Date.now();
|
||||
let last = times;
|
||||
clearResult(name);
|
||||
do {
|
||||
await measureEach(name, proc);
|
||||
} while (last-- > 0 && (Date.now() - from) < duration)
|
||||
} while (last-- > 0 && Date.now() - from < duration);
|
||||
return [name, measures.get(name) as MeasureResult];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-await, @typescript-eslint/require-await
|
||||
async function formatPerfResults(items: NamedMeasureResult[]) {
|
||||
return `| Name | Runs | Each | Total |\n| --- | --- | --- | --- | \n` + items.map(e => `| ${e[0]} | ${e[1][0]} | ${e[1][0] != 0 ? formatNumber(e[1][1] / e[1][0]) : "-"} | ${formatNumber(e[1][0])} |`).join("\n");
|
||||
|
||||
return (
|
||||
`| Name | Runs | Each | Total |\n| --- | --- | --- | --- | \n` +
|
||||
items
|
||||
.map(
|
||||
(e) =>
|
||||
`| ${e[0]} | ${e[1][0]} | ${e[1][0] != 0 ? formatNumber(e[1][1] / e[1][0]) : "-"} | ${formatNumber(e[1][0])} |`
|
||||
)
|
||||
.join("\n")
|
||||
);
|
||||
}
|
||||
export async function perf_trench(plugin: ObsidianLiveSyncPlugin) {
|
||||
clearResult("trench");
|
||||
const trench = new Trench(plugin.simpleStore);
|
||||
const result = [] as NamedMeasureResult[];
|
||||
result.push(await measure("trench-short-string", async () => {
|
||||
const p = trench.evacuate("string");
|
||||
await p();
|
||||
}));
|
||||
result.push(
|
||||
await measure("trench-short-string", async () => {
|
||||
const p = trench.evacuate("string");
|
||||
await p();
|
||||
})
|
||||
);
|
||||
{
|
||||
const testBinary = await plugin.storageAccess.readHiddenFileBinary("testdata/10kb.png");
|
||||
const uint8Array = new Uint8Array(testBinary);
|
||||
result.push(await measure("trench-binary-10kb", async () => {
|
||||
const p = trench.evacuate(uint8Array);
|
||||
await p();
|
||||
}));
|
||||
result.push(
|
||||
await measure("trench-binary-10kb", async () => {
|
||||
const p = trench.evacuate(uint8Array);
|
||||
await p();
|
||||
})
|
||||
);
|
||||
}
|
||||
{
|
||||
const testBinary = await plugin.storageAccess.readHiddenFileBinary("testdata/100kb.jpeg");
|
||||
const uint8Array = new Uint8Array(testBinary);
|
||||
result.push(await measure("trench-binary-100kb", async () => {
|
||||
const p = trench.evacuate(uint8Array);
|
||||
await p();
|
||||
}));
|
||||
result.push(
|
||||
await measure("trench-binary-100kb", async () => {
|
||||
const p = trench.evacuate(uint8Array);
|
||||
await p();
|
||||
})
|
||||
);
|
||||
}
|
||||
{
|
||||
const testBinary = await plugin.storageAccess.readHiddenFileBinary("testdata/1mb.png");
|
||||
const uint8Array = new Uint8Array(testBinary);
|
||||
result.push(await measure("trench-binary-1mb", async () => {
|
||||
const p = trench.evacuate(uint8Array);
|
||||
await p();
|
||||
}));
|
||||
result.push(
|
||||
await measure("trench-binary-1mb", async () => {
|
||||
const p = trench.evacuate(uint8Array);
|
||||
await p();
|
||||
})
|
||||
);
|
||||
}
|
||||
return formatPerfResults(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user