Skip to content

Commit 71bbeda

Browse files
author
Akos Kitta
committed
Can start the IDE with content tracing.
Signed-off-by: Akos Kitta <[email protected]>
1 parent c81d1c5 commit 71bbeda

File tree

3 files changed

+84
-5
lines changed

3 files changed

+84
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ yarn*.log
1717
plugins
1818
# the config files for the CLI
1919
arduino-ide-extension/data/cli/config
20+
# content trace files for electron
21+
electron-app/traces

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"--plugins=local-dir:../plugins",
2222
"--hosted-plugin-inspect=9339",
2323
"--nosplash",
24-
"--open-devtools"
24+
"--content-trace"
2525
],
2626
"env": {
2727
"NODE_ENV": "development"

arduino-ide-extension/src/electron-main/theia/electron-main-application.ts

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { inject, injectable } from '@theia/core/shared/inversify';
2-
import { app, BrowserWindow, BrowserWindowConstructorOptions, ipcMain, screen, Event as ElectronEvent } from '@theia/core/electron-shared/electron';
2+
import {
3+
app,
4+
BrowserWindow,
5+
BrowserWindowConstructorOptions,
6+
contentTracing,
7+
ipcMain,
8+
screen,
9+
Event as ElectronEvent,
10+
} from '@theia/core/electron-shared/electron';
311
import { fork } from 'child_process';
412
import { AddressInfo } from 'net';
513
import { join, dirname } from 'path';
@@ -46,7 +54,15 @@ const APP_STARTED_WITH_NOSPLASH =
4654
* If the app is started with `--open-devtools` argument, the `Dev Tools` will be opened.
4755
*/
4856
const APP_STARTED_WITH_DEV_TOOLS =
49-
typeof process !== 'undefined' && process.argv.indexOf('--open-devtools') !== -1;
57+
typeof process !== 'undefined' &&
58+
process.argv.indexOf('--open-devtools') !== -1;
59+
60+
/**
61+
* If the app is started with `--content-trace` argument, the `Dev Tools` will be opened and content tracing will start.
62+
*/
63+
const APP_STARTED_WITH_CONTENT_TRACE =
64+
typeof process !== 'undefined' &&
65+
process.argv.indexOf('--content-trace') !== -1;
5066

5167
@injectable()
5268
export class ElectronMainApplication extends TheiaElectronMainApplication {
@@ -62,7 +78,68 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
6278
// Regression in Theia: https://github.com/eclipse-theia/theia/issues/8701
6379
app.on('ready', () => app.setName(config.applicationName));
6480
this.attachFileAssociations();
65-
return super.start(config);
81+
this.useNativeWindowFrame = this.getTitleBarStyle(config) === 'native';
82+
this._config = config;
83+
this.hookApplicationEvents();
84+
const [port] = await Promise.all([this.startBackend(), app.whenReady()]);
85+
this.startContentTracing();
86+
this._backendPort.resolve(port);
87+
await Promise.all([
88+
this.attachElectronSecurityToken(port),
89+
this.startContributions(),
90+
]);
91+
return this.launch({
92+
secondInstance: false,
93+
argv: this.processArgv.getProcessArgvWithoutBin(process.argv),
94+
cwd: process.cwd(),
95+
});
96+
}
97+
98+
private startContentTracing(): void {
99+
if (!APP_STARTED_WITH_CONTENT_TRACE) {
100+
return;
101+
}
102+
if (!app.isReady()) {
103+
throw new Error(
104+
'Cannot start content tracing when the electron app is not ready.'
105+
);
106+
}
107+
const defaultTraceCategories: Readonly<Array<string>> = [
108+
'-*',
109+
'devtools.timeline',
110+
'disabled-by-default-devtools.timeline',
111+
'disabled-by-default-devtools.timeline.frame',
112+
'toplevel',
113+
'blink.console',
114+
'disabled-by-default-devtools.timeline.stack',
115+
'disabled-by-default-v8.cpu_profile',
116+
'disabled-by-default-v8.cpu_profiler',
117+
'disabled-by-default-v8.cpu_profiler.hires',
118+
];
119+
const traceOptions = {
120+
categoryFilter: defaultTraceCategories.join(','),
121+
traceOptions: 'record-until-full',
122+
options: 'sampling-frequency=10000',
123+
};
124+
(async () => {
125+
const appPath = app.getAppPath();
126+
let traceFile: string | undefined;
127+
if (appPath) {
128+
const tracesPath = join(appPath, 'traces');
129+
await fs.promises.mkdir(tracesPath, { recursive: true });
130+
traceFile = join(tracesPath, `trace-${new Date().toISOString()}.trace`);
131+
}
132+
console.log('>>> Content tracing has started...');
133+
await contentTracing.startRecording(traceOptions);
134+
await new Promise((resolve) => setTimeout(resolve, 10_000));
135+
contentTracing
136+
.stopRecording(traceFile)
137+
.then((out) =>
138+
console.log(
139+
`<<< Content tracing has finished. The trace data was written to: ${out}.`
140+
)
141+
);
142+
})();
66143
}
67144

68145
attachFileAssociations() {
@@ -164,7 +241,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
164241
return super.avoidOverlap(options);
165242
}
166243

167-
protected override getTitleBarStyle(): 'native' | 'custom' {
244+
protected override getTitleBarStyle(config: FrontendApplicationConfig): 'native' | 'custom' {
168245
return 'native';
169246
}
170247

0 commit comments

Comments
 (0)