Skip to content

Commit

Permalink
feat: Add hidden user setting to control whether PerformanceTracker i…
Browse files Browse the repository at this point in the history
…s enabled
  • Loading branch information
claremacrae committed Mar 25, 2024
1 parent 7d54ccb commit 4f11d21
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Config/DebugSettings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export class DebugSettings {
constructor(ignoreSortInstructions = false, showTaskHiddenData = false) {
constructor(ignoreSortInstructions = false, showTaskHiddenData = false, recordTimings = false) {
this.ignoreSortInstructions = ignoreSortInstructions;
this.showTaskHiddenData = showTaskHiddenData;
this.recordTimings = recordTimings; // Enables or disables PerformanceTracker
}

// Optionally disable all sorting of search results, so that tasks are
// displayed in the order they appear in the file.
readonly ignoreSortInstructions: boolean;
readonly showTaskHiddenData: boolean;
readonly recordTimings: boolean;
}
1 change: 1 addition & 0 deletions src/Config/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export const getSettings = (): Settings => {
// Check to see if there are any new options that need to be added to the user's settings.
addNewOptionsToUserSettings(Feature.settingsFlags, settings.features);
addNewOptionsToUserSettings(defaultSettings.loggingOptions.minLevels, settings.loggingOptions.minLevels);
addNewOptionsToUserSettings(defaultSettings.debugSettings, settings.debugSettings);

// In case saves pre-dated StatusConfiguration.type
// TODO Special case for symbol 'X' or 'x' (just in case)
Expand Down
14 changes: 14 additions & 0 deletions src/lib/PerformanceTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* // ... some slow code
* tracker.finish();
*/
import { getSettings } from '../Config/Settings';

export class PerformanceTracker {
private readonly label: string;
Expand All @@ -16,10 +17,18 @@ export class PerformanceTracker {
}

public start() {
if (!this.recordTimings()) {
return;
}

performance.mark(this.labelForStart());
}

public finish() {
if (!this.recordTimings()) {
return;
}

performance.mark(this.labelForEnd());

// Measure the time between the marks
Expand Down Expand Up @@ -49,4 +58,9 @@ export class PerformanceTracker {
private labelForEnd() {
return `${this.label} - end`;
}

private recordTimings() {
const { debugSettings } = getSettings();
return debugSettings.recordTimings;
}
}

0 comments on commit 4f11d21

Please sign in to comment.