-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional module for performance measurements
- Introduce an optional performance module that add performance measurements to core GLSP concepts. - Performance is simply measured using console.time which also allows inspection of the tracked events in the dev tools trace viewer - The module is opt-in and disabled by default. To enable it the &performance=true query parameter has to be added to the url
- Loading branch information
Showing
9 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Action, GLSPActionDispatcher, RequestAction, ResponseAction } from '@eclipse-glsp/client'; | ||
import { injectable } from 'inversify'; | ||
|
||
@injectable() | ||
export class PerfActionDispatcher extends GLSPActionDispatcher { | ||
protected counter = 0; | ||
|
||
override request<Res extends ResponseAction>(action: RequestAction<Res>): Promise<Res> { | ||
const counter = ++this.counter; | ||
console.time(`request-${action.kind}-${counter}`); | ||
const result = super.request(action); | ||
console.timeEnd(`request-${action.kind}-${counter}`); | ||
this.counter++; | ||
return result; | ||
} | ||
|
||
override async dispatch(action: Action): Promise<void> { | ||
const counter = ++this.counter; | ||
console.time(`dispatch-${action.kind}-${counter}`); | ||
await super.dispatch(action); | ||
console.timeEnd(`dispatch-${action.kind}-${counter}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { DiagramLoader, IDiagramStartup, ResolvedDiagramLoadingOptions } from '@eclipse-glsp/client'; | ||
import { injectable } from 'inversify'; | ||
|
||
@injectable() | ||
export class PerfDiagramLoader extends DiagramLoader { | ||
protected override async invokeStartupHook(hook: keyof Omit<IDiagramStartup, 'rank'>): Promise<void> { | ||
console.time('invokeStartupHook-' + hook); | ||
await super.invokeStartupHook(hook); | ||
console.timeEnd('invokeStartupHook-' + hook); | ||
} | ||
|
||
protected override async initialize(options: ResolvedDiagramLoadingOptions): Promise<void> { | ||
console.time('DiagramLoader.initialize'); | ||
await super.initialize(options); | ||
console.timeEnd('DiagramLoader.initialize'); | ||
} | ||
|
||
protected override async requestModel(options: ResolvedDiagramLoadingOptions): Promise<void> { | ||
console.time('DiagramLoader.requestModel'); | ||
await super.requestModel(options); | ||
console.timeEnd('DiagramLoader.requestModel'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Action, GModelRoot, ModelViewer } from '@eclipse-glsp/client'; | ||
import { injectable } from 'inversify'; | ||
|
||
@injectable() | ||
export class PerfModelViewer extends ModelViewer { | ||
protected counter = 0; | ||
|
||
update(model: Readonly<GModelRoot>, cause?: Action): void { | ||
const counter = ++this.counter; | ||
console.time('Viewer update ' + counter); | ||
super.update(model, cause); | ||
console.timeEnd('Viewer update ' + counter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DiagramLoader, FeatureModule, GLSPActionDispatcher, TYPES } from '@eclipse-glsp/client'; | ||
import { PerfDiagramLoader } from './perf-diagram-loader'; | ||
import { PerfActionDispatcher } from './perf-action-dispatcher'; | ||
import { PerfModelViewer } from './perf-viewer'; | ||
|
||
export function createPerformanceModule(enabled?: boolean): FeatureModule { | ||
return new FeatureModule( | ||
(bind, unbind, isBound, rebind) => { | ||
if (!enabled) { | ||
return; | ||
} | ||
rebind(DiagramLoader).to(PerfDiagramLoader).inSingletonScope(); | ||
rebind(GLSPActionDispatcher).to(PerfActionDispatcher).inSingletonScope(); | ||
rebind(TYPES.ModelViewer).to(PerfModelViewer).inSingletonScope(); | ||
}, | ||
{ featureId: Symbol('performance') } | ||
); | ||
} |