Skip to content

[NO-MERGE] Log keybinding registry times #1477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ import { OutputEditorFactory } from './theia/output/output-editor-factory';
import { StartupTaskProvider } from '../electron-common/startup-task';
import { DeleteSketch } from './contributions/delete-sketch';
import { UserFields } from './contributions/user-fields';
import { KeybindingRegistry } from './theia/core/keybinding';
import { KeybindingRegistry as TheiaKeybindingRegistry } from '@theia/core/lib/browser/keybinding';
import { KeyboardLayoutService } from './theia/core/keyboard-layout-service';
import { KeyboardLayoutService as TheiaKeyboardLayoutService } from '@theia/core/lib/browser/keyboard/keyboard-layout-service';

const registerArduinoThemes = () => {
const themes: MonacoThemeJson[] = [
Expand Down Expand Up @@ -996,4 +1000,10 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(TheiaHostedPluginSupport).toService(HostedPluginSupport);
bind(HostedPluginEvents).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(HostedPluginEvents);

// #1428
bind(KeybindingRegistry).toSelf().inSingletonScope();
rebind(TheiaKeybindingRegistry).toService(KeybindingRegistry);
bind(KeyboardLayoutService).toSelf().inSingletonScope();
rebind(TheiaKeyboardLayoutService).toService(KeyboardLayoutService);
});
20 changes: 20 additions & 0 deletions arduino-ide-extension/src/browser/theia/core/keybinding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
KeybindingContext,
KeybindingRegistry as TheiaKeybindingRegistry,
} from '@theia/core/lib/browser/keybinding';
import { injectable } from '@theia/core/shared/inversify';
import { measure } from '../../../common/utils';

@injectable()
export class KeybindingRegistry extends TheiaKeybindingRegistry {
override onStart(): Promise<void> {
return measure('KeybindingRegistry#onStart', () => super.onStart());
}
protected override registerContext(...contexts: KeybindingContext[]): void {
return measure(
'KeybindingRegistry#registerContext',
() => super.registerContext(...contexts),
...contexts.map(({ id }) => id)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
KeyboardLayout,
KeyboardLayoutService as TheiaKeyboardLayoutService,
} from '@theia/core/lib/browser/keyboard/keyboard-layout-service';
import { NativeKeyboardLayout } from '@theia/core/lib/common/keyboard/keyboard-layout-provider';
import { injectable } from '@theia/core/shared/inversify';
import { measure } from '../../../common/utils';

@injectable()
export class KeyboardLayoutService extends TheiaKeyboardLayoutService {
override initialize(): Promise<void> {
return measure('KeyboardLayoutService#initialize', () =>
super.initialize()
);
}
protected override updateLayout(
newLayout: NativeKeyboardLayout
): KeyboardLayout {
return measure(
'KeyboardLayoutService#updateLayout',
() => super.updateLayout(newLayout),
newLayout
);
}
protected override transformNativeLayout(
nativeLayout: NativeKeyboardLayout
): KeyboardLayout {
return measure(
'KeyboardLayoutService#transformNativeLayout',
() => super.transformNativeLayout(nativeLayout),
nativeLayout
);
}
}
46 changes: 46 additions & 0 deletions arduino-ide-extension/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,49 @@ export function firstToUpperCase(what: string): string {
export function isNullOrUndefined(what: any): what is undefined | null {
return what === undefined || what === null;
}

export function measure<T>(
what: string,
task: () => Promise<T>,
...args: unknown[]
): Promise<T>;
export function measure<T>(what: string, task: () => T, ...args: unknown[]): T;
export function measure<T>(
what: string,
task: (() => Promise<T>) | (() => T),
...args: unknown[]
): Promise<T> | T {
const start = performance.now();
const result = task();
if (typeof result === 'object') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const object = result as any;
if ('then' in object) {
return Promise.resolve(result).then((resolved) =>
end(resolved, start, what, args)
);
}
}
return end(result, start, what, args);
}
function end<T>(object: T, start: number, what: string, args: unknown[]): T {
console.log(
`--- #1428 --- ${what} took ${performance.now() - start} ms.${
args.length ? ` Args: ${tryStringify(args)}` : ''
}`
);
return object;
}
function tryStringify(args: unknown[]): string {
try {
return JSON.stringify(args);
} catch (err) {
if (
err instanceof TypeError &&
err.message.toLowerCase().includes('circular structure to json')
) {
return '<circular>';
}
throw err;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IDEUpdaterImpl } from './ide-updater/ide-updater-impl';
import { ElectronMainApplication } from './theia/electron-main-application';
import { ElectronMainWindowServiceImpl } from './theia/electron-main-window-service';
import { TheiaElectronWindow } from './theia/theia-electron-window';
import { ElectronNativeKeymap } from '@theia/core/lib/electron-main/electron-native-keymap';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ElectronMainApplication).toSelf().inSingletonScope();
Expand Down Expand Up @@ -58,4 +59,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
.inSingletonScope();

bind(IsTempSketch).toSelf().inSingletonScope();

// https://github.com/eclipse-theia/theia/issues/11688
bind(ElectronNativeKeymap).toSelf().inSingletonScope();
bind(ElectronMainApplicationContribution).toService(ElectronNativeKeymap);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ElectronKeyboardLayoutProvider as TheiaElectronKeyboardLayoutProvider } from '@theia/core/lib/electron-node/keyboard/electron-keyboard-layout-provider';
import { NativeKeyboardLayout } from '@theia/core/lib/common/keyboard/keyboard-layout-provider';
import { injectable } from '@theia/core/shared/inversify';
import * as nativeKeymap from '@theia/electron/shared/native-keymap';
import { measure } from '../../common/utils';

@injectable()
export class ElectronKeyboardLayoutProvider extends TheiaElectronKeyboardLayoutProvider {
override getNativeLayout(): Promise<NativeKeyboardLayout> {
return measure('ElectronKeyboardLayoutProvider#getNativeLayout', () =>
super.getNativeLayout()
);
}
protected override getNativeLayoutSync(): NativeKeyboardLayout {
return {
info: measure(
'ElectronKeyboardLayoutProvider#getNativeLayoutSync#getCurrentKeyboardLayout',
() => nativeKeymap.getCurrentKeyboardLayout()
),
mapping: measure(
'ElectronKeyboardLayoutProvider#getNativeLayoutSync#getKeyMap',
() => nativeKeymap.getKeyMap()
),
};
}
}
8 changes: 8 additions & 0 deletions arduino-ide-extension/src/node/arduino-ide-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ import {
} from '../common/protocol/survey-service';
import { IsTempSketch } from './is-temp-sketch';
import { rebindNsfwFileSystemWatcher } from './theia/filesystem/nsfw-watcher/nsfw-bindings';
import { ElectronKeyboardLayoutProvider } from '../electron-node/theia/electron-keyboard-layout-provider';
import { ElectronKeyboardLayoutProvider as TheiaElectronKeyboardLayoutProvider } from '@theia/core/lib/electron-node/keyboard/electron-keyboard-layout-provider';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(BackendApplication).toSelf().inSingletonScope();
Expand Down Expand Up @@ -380,6 +382,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
.inSingletonScope();

bind(IsTempSketch).toSelf().inSingletonScope();

// #1428
bind(ElectronKeyboardLayoutProvider).toSelf().inSingletonScope();
rebind(TheiaElectronKeyboardLayoutProvider).toService(
ElectronKeyboardLayoutProvider
);
});

function bindChildLogger(bind: interfaces.Bind, name: string): void {
Expand Down