(core) Adding UI for timing API

Summary:
Adding new buttons to control the `timing` API and a way to view the results
using virtual table features.

Test Plan: Added new

Reviewers: georgegevoian

Reviewed By: georgegevoian

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D4252
This commit is contained in:
Jarosław Sadziński
2024-05-21 18:27:06 +02:00
parent 60423edc17
commit a6ffa6096a
29 changed files with 858 additions and 144 deletions

View File

@@ -1841,6 +1841,14 @@ export class ActiveDoc extends EventEmitter {
});
}
public async sendTimingsNotification() {
await this.docClients.broadcastDocMessage(null, 'docChatter', {
timing: {
status: this.isTimingOn ? 'active' : 'disabled'
},
});
}
public logTelemetryEvent(
docSession: OptDocSession | null,
event: TelemetryEvent,
@@ -1883,6 +1891,8 @@ export class ActiveDoc extends EventEmitter {
}
public async startTiming(): Promise<void> {
await this.waitForInitialization();
// Set the flag to indicate that timing is on.
this.isTimingOn = true;
@@ -1896,9 +1906,12 @@ export class ActiveDoc extends EventEmitter {
// Mark self as in timing mode, in case we get reloaded.
this._docManager.restoreTimingOn(this.docName, true);
await this.sendTimingsNotification();
}
public async stopTiming(): Promise<FormulaTimingInfo[]> {
await this.waitForInitialization();
// First call the data engine to stop timing, and gather results.
const timingResults = await this._pyCall('stop_timing');
@@ -1906,10 +1919,14 @@ export class ActiveDoc extends EventEmitter {
this.isTimingOn = false;
this._docManager.restoreTimingOn(this.docName, false);
await this.sendTimingsNotification();
return timingResults;
}
public async getTimings(): Promise<FormulaTimingInfo[]|void> {
await this.waitForInitialization();
if (this._modificationLock.isLocked()) {
return;
}

View File

@@ -46,7 +46,7 @@ export const DEFAULT_CACHE_TTL = 10000;
export const RECOVERY_CACHE_TTL = 30000; // 30 seconds
// How long to remember the timing mode of a document.
export const TIMING_ON_CACHE_TTL = 30000; // 30 seconds
export const TIMING_ON_CACHE_TTL = 10 * 60 * 1000; // 10 minutes
/**
* DocManager keeps track of "active" Grist documents, i.e. those loaded
@@ -416,6 +416,7 @@ export class DocManager extends EventEmitter {
recoveryMode: activeDoc.recoveryMode,
userOverride,
docUsage,
isTimingOn: activeDoc.isTimingOn,
};
if (!activeDoc.muted) {

View File

@@ -345,6 +345,10 @@ export async function doExportSection(
sortSpec = sortSpec || gutil.safeJsonParse(viewSection.sortColRefs, []);
sortSpec = sortSpec!.map((colSpec) => {
const colRef = Sort.getColRef(colSpec);
if (typeof colRef !== 'number') {
// colRef might be string for virtual tables, but we don't support them here.
throw new Error(`Unsupported colRef type: ${typeof colRef}`);
}
const col = metaColumns.getRecord(colRef);
if (!col) {
return 0;

View File

@@ -22,6 +22,10 @@ export class ServerColumnGetters implements ColumnGetters, ColumnGettersByColId
public getColGetter(colSpec: Sort.ColSpec): ColumnGetter | null {
const colRef = Sort.getColRef(colSpec);
if (typeof colRef !== 'number') {
// colRef might be string for virtual tables, but we don't support them here.
throw new Error(`Unsupported colRef type: ${typeof colRef}`);
}
const colId = this._colIndices.get(colRef);
if (colId === undefined) {
return null;