mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 23:56:00 +00:00
profile refactoring, fixes
This commit is contained in:
@@ -101,13 +101,14 @@ module.exports = {
|
|||||||
// },
|
// },
|
||||||
|
|
||||||
async ensureDatastore(jslid, formatterFunction) {
|
async ensureDatastore(jslid, formatterFunction) {
|
||||||
const rowFormatter = requirePluginFunction(formatterFunction);
|
let datastore = this.datastores[jslid];
|
||||||
const dskey = `${jslid}||${formatterFunction}`;
|
if (!datastore || datastore.formatterFunction != formatterFunction) {
|
||||||
let datastore = this.datastores[dskey];
|
if (datastore) {
|
||||||
if (!datastore) {
|
datastore._closeReader();
|
||||||
datastore = new JsonLinesDatastore(getJslFileName(jslid), rowFormatter);
|
}
|
||||||
|
datastore = new JsonLinesDatastore(getJslFileName(jslid), formatterFunction);
|
||||||
// datastore = new DatastoreProxy(getJslFileName(jslid));
|
// datastore = new DatastoreProxy(getJslFileName(jslid));
|
||||||
this.datastores[dskey] = datastore;
|
this.datastores[jslid] = datastore;
|
||||||
}
|
}
|
||||||
return datastore;
|
return datastore;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const AsyncLock = require('async-lock');
|
|||||||
const lock = new AsyncLock();
|
const lock = new AsyncLock();
|
||||||
const stableStringify = require('json-stable-stringify');
|
const stableStringify = require('json-stable-stringify');
|
||||||
const { evaluateCondition } = require('dbgate-sqltree');
|
const { evaluateCondition } = require('dbgate-sqltree');
|
||||||
|
const requirePluginFunction = require('./requirePluginFunction');
|
||||||
|
|
||||||
function fetchNextLineFromReader(reader) {
|
function fetchNextLineFromReader(reader) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -22,15 +23,16 @@ function fetchNextLineFromReader(reader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class JsonLinesDatastore {
|
class JsonLinesDatastore {
|
||||||
constructor(file, rowFormatter) {
|
constructor(file, formatterFunction) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.rowFormatter = rowFormatter;
|
this.formatterFunction = formatterFunction;
|
||||||
this.reader = null;
|
this.reader = null;
|
||||||
this.readedDataRowCount = 0;
|
this.readedDataRowCount = 0;
|
||||||
this.readedSchemaRow = false;
|
this.readedSchemaRow = false;
|
||||||
// this.firstRowToBeReturned = null;
|
// this.firstRowToBeReturned = null;
|
||||||
this.notifyChangedCallback = null;
|
this.notifyChangedCallback = null;
|
||||||
this.currentFilter = null;
|
this.currentFilter = null;
|
||||||
|
this.rowFormatter = requirePluginFunction(formatterFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
_closeReader() {
|
_closeReader() {
|
||||||
|
|||||||
@@ -213,12 +213,12 @@
|
|||||||
icon: 'img profiler',
|
icon: 'img profiler',
|
||||||
tabComponent: 'ProfilerTab',
|
tabComponent: 'ProfilerTab',
|
||||||
props: {
|
props: {
|
||||||
jslid: `archive://${data.folderName}/${data.fileName}`,
|
jslidLoad: `archive://${data.folderName}/${data.fileName}`,
|
||||||
// engine: eng.engine,
|
engine: eng.engine,
|
||||||
profilerFormatterFunction: eng.profilerFormatterFunction,
|
// profilerFormatterFunction: eng.profilerFormatterFunction,
|
||||||
profilerTimestampFunction: eng.profilerTimestampFunction,
|
// profilerTimestampFunction: eng.profilerTimestampFunction,
|
||||||
profilerChartAggregateFunction: eng.profilerChartAggregateFunction,
|
// profilerChartAggregateFunction: eng.profilerChartAggregateFunction,
|
||||||
profilerChartMeasures: eng.profilerChartMeasures,
|
// profilerChartMeasures: eng.profilerChartMeasures,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -56,13 +56,12 @@
|
|||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
export let jslid;
|
export let engine;
|
||||||
export let profilerFormatterFunction;
|
export let jslidLoad;
|
||||||
export let profilerTimestampFunction;
|
|
||||||
export let profilerChartAggregateFunction;
|
|
||||||
export let profilerChartMeasures;
|
|
||||||
|
|
||||||
let profiling = false;
|
let jslidSession;
|
||||||
|
|
||||||
|
let isProfiling = false;
|
||||||
let sessionId;
|
let sessionId;
|
||||||
let isLoadingChart = false;
|
let isLoadingChart = false;
|
||||||
|
|
||||||
@@ -70,7 +69,8 @@
|
|||||||
let chartData;
|
let chartData;
|
||||||
|
|
||||||
$: connection = useConnectionInfo({ conid });
|
$: connection = useConnectionInfo({ conid });
|
||||||
$: driver = findEngineDriver($connection, $extensions);
|
$: driver = findEngineDriver(engine || $connection, $extensions);
|
||||||
|
$: jslid = jslidSession || jslidLoad;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
intervalId = setInterval(() => {
|
intervalId = setInterval(() => {
|
||||||
@@ -80,22 +80,20 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 15 * 1000);
|
}, 15 * 1000);
|
||||||
|
});
|
||||||
|
|
||||||
if (jslid) {
|
$: {
|
||||||
|
if (jslidLoad && driver) {
|
||||||
loadChart();
|
loadChart();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
});
|
});
|
||||||
|
|
||||||
export function isProfiling() {
|
|
||||||
return profiling;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function startProfiling() {
|
export async function startProfiling() {
|
||||||
profiling = true;
|
isProfiling = true;
|
||||||
|
|
||||||
let sesid = sessionId;
|
let sesid = sessionId;
|
||||||
if (!sesid) {
|
if (!sesid) {
|
||||||
@@ -110,7 +108,7 @@
|
|||||||
const resp = await apiCall('sessions/start-profiler', {
|
const resp = await apiCall('sessions/start-profiler', {
|
||||||
sesid,
|
sesid,
|
||||||
});
|
});
|
||||||
jslid = resp.jslid;
|
jslidSession = resp.jslid;
|
||||||
|
|
||||||
invalidateCommands();
|
invalidateCommands();
|
||||||
}
|
}
|
||||||
@@ -123,15 +121,15 @@
|
|||||||
isLoadingChart = true;
|
isLoadingChart = true;
|
||||||
|
|
||||||
const colors = randomcolor({
|
const colors = randomcolor({
|
||||||
count: (profilerChartMeasures || driver.profilerChartMeasures).length,
|
count: driver.profilerChartMeasures.length,
|
||||||
seed: 5,
|
seed: 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await apiCall('jsldata/extract-timeline-chart', {
|
const data = await apiCall('jsldata/extract-timeline-chart', {
|
||||||
jslid,
|
jslid,
|
||||||
timestampFunction: profilerTimestampFunction || driver.profilerTimestampFunction,
|
timestampFunction: driver.profilerTimestampFunction,
|
||||||
aggregateFunction: profilerChartAggregateFunction || driver.profilerChartAggregateFunction,
|
aggregateFunction: driver.profilerChartAggregateFunction,
|
||||||
measures: profilerChartMeasures || driver.profilerChartMeasures,
|
measures: driver.profilerChartMeasures,
|
||||||
});
|
});
|
||||||
chartData = {
|
chartData = {
|
||||||
...data,
|
...data,
|
||||||
@@ -145,8 +143,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function stopProfiling() {
|
export async function stopProfiling() {
|
||||||
profiling = false;
|
isProfiling = false;
|
||||||
apiCall('sessions/stop-profiler', { sesid: sessionId });
|
await apiCall('sessions/stop-profiler', { sesid: sessionId });
|
||||||
|
await apiCall('sessions/kill', { sesid: sessionId });
|
||||||
|
sessionId = null;
|
||||||
|
|
||||||
invalidateCommands();
|
invalidateCommands();
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function saveEnabled() {
|
export function saveEnabled() {
|
||||||
return !!jslid;
|
return !!jslidSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doSave(folder, file) {
|
async function doSave(folder, file) {
|
||||||
@@ -199,11 +199,9 @@
|
|||||||
{#if jslid}
|
{#if jslid}
|
||||||
<VerticalSplitter allowCollapseChild1 allowCollapseChild2>
|
<VerticalSplitter allowCollapseChild1 allowCollapseChild2>
|
||||||
<svelte:fragment slot="1">
|
<svelte:fragment slot="1">
|
||||||
<JslDataGrid
|
{#key jslid}
|
||||||
{jslid}
|
<JslDataGrid {jslid} listenInitializeFile formatterFunction={driver?.profilerFormatterFunction} />
|
||||||
listenInitializeFile
|
{/key}
|
||||||
formatterFunction={profilerFormatterFunction || driver?.profilerFormatterFunction}
|
|
||||||
/>
|
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
<svelte:fragment slot="2">
|
<svelte:fragment slot="2">
|
||||||
{#if isLoadingChart}
|
{#if isLoadingChart}
|
||||||
|
|||||||
Reference in New Issue
Block a user