diff --git a/packages/api/src/controllers/jsldata.js b/packages/api/src/controllers/jsldata.js index 8b0d29ffa..4778e2f59 100644 --- a/packages/api/src/controllers/jsldata.js +++ b/packages/api/src/controllers/jsldata.js @@ -101,13 +101,14 @@ module.exports = { // }, async ensureDatastore(jslid, formatterFunction) { - const rowFormatter = requirePluginFunction(formatterFunction); - const dskey = `${jslid}||${formatterFunction}`; - let datastore = this.datastores[dskey]; - if (!datastore) { - datastore = new JsonLinesDatastore(getJslFileName(jslid), rowFormatter); + let datastore = this.datastores[jslid]; + if (!datastore || datastore.formatterFunction != formatterFunction) { + if (datastore) { + datastore._closeReader(); + } + datastore = new JsonLinesDatastore(getJslFileName(jslid), formatterFunction); // datastore = new DatastoreProxy(getJslFileName(jslid)); - this.datastores[dskey] = datastore; + this.datastores[jslid] = datastore; } return datastore; }, diff --git a/packages/api/src/utility/JsonLinesDatastore.js b/packages/api/src/utility/JsonLinesDatastore.js index b3a2005d8..a5e12da47 100644 --- a/packages/api/src/utility/JsonLinesDatastore.js +++ b/packages/api/src/utility/JsonLinesDatastore.js @@ -3,6 +3,7 @@ const AsyncLock = require('async-lock'); const lock = new AsyncLock(); const stableStringify = require('json-stable-stringify'); const { evaluateCondition } = require('dbgate-sqltree'); +const requirePluginFunction = require('./requirePluginFunction'); function fetchNextLineFromReader(reader) { return new Promise((resolve, reject) => { @@ -22,15 +23,16 @@ function fetchNextLineFromReader(reader) { } class JsonLinesDatastore { - constructor(file, rowFormatter) { + constructor(file, formatterFunction) { this.file = file; - this.rowFormatter = rowFormatter; + this.formatterFunction = formatterFunction; this.reader = null; this.readedDataRowCount = 0; this.readedSchemaRow = false; // this.firstRowToBeReturned = null; this.notifyChangedCallback = null; this.currentFilter = null; + this.rowFormatter = requirePluginFunction(formatterFunction); } _closeReader() { diff --git a/packages/web/src/appobj/ArchiveFileAppObject.svelte b/packages/web/src/appobj/ArchiveFileAppObject.svelte index e77e42e31..4cecca45d 100644 --- a/packages/web/src/appobj/ArchiveFileAppObject.svelte +++ b/packages/web/src/appobj/ArchiveFileAppObject.svelte @@ -213,12 +213,12 @@ icon: 'img profiler', tabComponent: 'ProfilerTab', props: { - jslid: `archive://${data.folderName}/${data.fileName}`, - // engine: eng.engine, - profilerFormatterFunction: eng.profilerFormatterFunction, - profilerTimestampFunction: eng.profilerTimestampFunction, - profilerChartAggregateFunction: eng.profilerChartAggregateFunction, - profilerChartMeasures: eng.profilerChartMeasures, + jslidLoad: `archive://${data.folderName}/${data.fileName}`, + engine: eng.engine, + // profilerFormatterFunction: eng.profilerFormatterFunction, + // profilerTimestampFunction: eng.profilerTimestampFunction, + // profilerChartAggregateFunction: eng.profilerChartAggregateFunction, + // profilerChartMeasures: eng.profilerChartMeasures, }, }); }, diff --git a/packages/web/src/tabs/ProfilerTab.svelte b/packages/web/src/tabs/ProfilerTab.svelte index ae691bdb5..774f6d4de 100644 --- a/packages/web/src/tabs/ProfilerTab.svelte +++ b/packages/web/src/tabs/ProfilerTab.svelte @@ -56,13 +56,12 @@ export let conid; export let database; - export let jslid; - export let profilerFormatterFunction; - export let profilerTimestampFunction; - export let profilerChartAggregateFunction; - export let profilerChartMeasures; + export let engine; + export let jslidLoad; - let profiling = false; + let jslidSession; + + let isProfiling = false; let sessionId; let isLoadingChart = false; @@ -70,7 +69,8 @@ let chartData; $: connection = useConnectionInfo({ conid }); - $: driver = findEngineDriver($connection, $extensions); + $: driver = findEngineDriver(engine || $connection, $extensions); + $: jslid = jslidSession || jslidLoad; onMount(() => { intervalId = setInterval(() => { @@ -80,22 +80,20 @@ }); } }, 15 * 1000); + }); - if (jslid) { + $: { + if (jslidLoad && driver) { loadChart(); } - }); + } onDestroy(() => { clearInterval(intervalId); }); - export function isProfiling() { - return profiling; - } - export async function startProfiling() { - profiling = true; + isProfiling = true; let sesid = sessionId; if (!sesid) { @@ -110,7 +108,7 @@ const resp = await apiCall('sessions/start-profiler', { sesid, }); - jslid = resp.jslid; + jslidSession = resp.jslid; invalidateCommands(); } @@ -123,15 +121,15 @@ isLoadingChart = true; const colors = randomcolor({ - count: (profilerChartMeasures || driver.profilerChartMeasures).length, + count: driver.profilerChartMeasures.length, seed: 5, }); const data = await apiCall('jsldata/extract-timeline-chart', { jslid, - timestampFunction: profilerTimestampFunction || driver.profilerTimestampFunction, - aggregateFunction: profilerChartAggregateFunction || driver.profilerChartAggregateFunction, - measures: profilerChartMeasures || driver.profilerChartMeasures, + timestampFunction: driver.profilerTimestampFunction, + aggregateFunction: driver.profilerChartAggregateFunction, + measures: driver.profilerChartMeasures, }); chartData = { ...data, @@ -145,8 +143,10 @@ } export async function stopProfiling() { - profiling = false; - apiCall('sessions/stop-profiler', { sesid: sessionId }); + isProfiling = false; + await apiCall('sessions/stop-profiler', { sesid: sessionId }); + await apiCall('sessions/kill', { sesid: sessionId }); + sessionId = null; invalidateCommands(); @@ -158,7 +158,7 @@ } export function saveEnabled() { - return !!jslid; + return !!jslidSession; } async function doSave(folder, file) { @@ -199,11 +199,9 @@ {#if jslid} - + {#key jslid} + + {/key} {#if isLoadingChart}