profile refactoring, fixes

This commit is contained in:
Jan Prochazka 2022-12-18 17:03:47 +01:00
parent 3bbdc56309
commit 0ff4f0d7e9
4 changed files with 42 additions and 41 deletions

View File

@ -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;
},

View File

@ -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() {

View File

@ -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,
},
});
},

View File

@ -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}
<VerticalSplitter allowCollapseChild1 allowCollapseChild2>
<svelte:fragment slot="1">
<JslDataGrid
{jslid}
listenInitializeFile
formatterFunction={profilerFormatterFunction || driver?.profilerFormatterFunction}
/>
{#key jslid}
<JslDataGrid {jslid} listenInitializeFile formatterFunction={driver?.profilerFormatterFunction} />
{/key}
</svelte:fragment>
<svelte:fragment slot="2">
{#if isLoadingChart}