From 8c1bf30b0ca8431dbbcfbb456ec394ccc19f4de3 Mon Sep 17 00:00:00 2001 From: Mathieu Le Muzic <130933088+mlemuzic-bentley@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:50:10 +0200 Subject: [PATCH 1/5] enable log --- .../display-performance-test-app/src/backend/WebMain.ts | 9 ++++++++- .../src/frontend/TestRunner.ts | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test-apps/display-performance-test-app/src/backend/WebMain.ts b/test-apps/display-performance-test-app/src/backend/WebMain.ts index 81bbb2a31698..1c295edea925 100644 --- a/test-apps/display-performance-test-app/src/backend/WebMain.ts +++ b/test-apps/display-performance-test-app/src/backend/WebMain.ts @@ -9,6 +9,7 @@ import * as path from "path"; import { BentleyCloudRpcConfiguration, BentleyCloudRpcManager, IModelReadRpcInterface, IModelTileRpcInterface, SnapshotIModelRpcInterface } from "@itwin/core-common"; import DisplayPerfRpcInterface from "../common/DisplayPerfRpcInterface"; import { initializeBackend } from "./backend"; +import { Logger, LogLevel } from "@itwin/core-bentley"; /* eslint-disable no-console */ @@ -36,7 +37,7 @@ function startWebServer() { }); // Run the server... appExp.set("port", 3000); - const announceWebServer = () => { }; + const announceWebServer = () => console.log(`Serving web files on port 3000`); DisplayPerfRpcInterface.webServer = appExp.listen(appExp.get("port"), announceWebServer); } @@ -44,6 +45,9 @@ function startWebServer() { // Initialize the webserver startWebServer(); + Logger.initializeToConsole(); + Logger.setLevelDefault(LogLevel.Info); + // Initialize the backend await initializeBackend(); @@ -61,6 +65,7 @@ function startWebServer() { else if (arg === "egl"){ chromeFlags.push("--use-gl=angle"); chromeFlags.push("--use-angle=gl-egl"); + chromeFlags.push("--enable-logging"); } }); @@ -108,9 +113,11 @@ function startWebServer() { if (process.platform === "darwin") { // Ie, if running on Mac child_process.execSync("open -a \"Google Chrome\" http://localhost:3000"); } else { + console.log(`logLevel: verbose`); chromeLauncher.launch({ // eslint-disable-line @typescript-eslint/no-floating-promises startingUrl: "http://localhost:3000", chromeFlags, + logLevel: "verbose", }).then((val) => { DisplayPerfRpcInterface.chrome = val; }); } break; diff --git a/test-apps/display-performance-test-app/src/frontend/TestRunner.ts b/test-apps/display-performance-test-app/src/frontend/TestRunner.ts index 4e36a2ffb850..36db113f41d4 100644 --- a/test-apps/display-performance-test-app/src/frontend/TestRunner.ts +++ b/test-apps/display-performance-test-app/src/frontend/TestRunner.ts @@ -5,7 +5,7 @@ import { RealityDataAccessClient, RealityDataClientOptions } from "@itwin/reality-data-client"; import { - assert, Dictionary, Id64, Id64Array, Id64String, ProcessDetector, SortedArray, StopWatch, + assert, Dictionary, Id64, Id64Array, Id64String, Logger, LoggingMetaData, LogLevel, ProcessDetector, SortedArray, StopWatch, } from "@itwin/core-bentley"; import { BackgroundMapType, BaseMapLayerSettings, DisplayStyleProps, FeatureAppearance, Hilite, RenderMode, ViewStateProps, @@ -209,6 +209,12 @@ export class TestRunner { await this.logToConsole(msg); await this.logToFile(msg, { noAppend: true }); + const logConsole = (level: string) => async (category: string, message: string, metaData: LoggingMetaData) => + this.logToConsole(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); + + Logger.initialize(logConsole("Error"), logConsole("Warning"), logConsole("Info"), logConsole("Trace")); + Logger.setLevelDefault(LogLevel.Info); + let needRestart = this.curConfig.requiresRestart(new TestConfig({})); // If current config differs from default, restart const renderOptions: RenderSystem.Options = this.curConfig.renderOptions ?? {}; if (!this.curConfig.useDisjointTimer) { From 5fb156c3bec05bf6cede430304ad17b657e922b8 Mon Sep 17 00:00:00 2001 From: Mathieu Le Muzic <130933088+mlemuzic-bentley@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:40:48 +0200 Subject: [PATCH 2/5] restore --- .../display-performance-test-app/src/backend/WebMain.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test-apps/display-performance-test-app/src/backend/WebMain.ts b/test-apps/display-performance-test-app/src/backend/WebMain.ts index 1c295edea925..81bbb2a31698 100644 --- a/test-apps/display-performance-test-app/src/backend/WebMain.ts +++ b/test-apps/display-performance-test-app/src/backend/WebMain.ts @@ -9,7 +9,6 @@ import * as path from "path"; import { BentleyCloudRpcConfiguration, BentleyCloudRpcManager, IModelReadRpcInterface, IModelTileRpcInterface, SnapshotIModelRpcInterface } from "@itwin/core-common"; import DisplayPerfRpcInterface from "../common/DisplayPerfRpcInterface"; import { initializeBackend } from "./backend"; -import { Logger, LogLevel } from "@itwin/core-bentley"; /* eslint-disable no-console */ @@ -37,7 +36,7 @@ function startWebServer() { }); // Run the server... appExp.set("port", 3000); - const announceWebServer = () => console.log(`Serving web files on port 3000`); + const announceWebServer = () => { }; DisplayPerfRpcInterface.webServer = appExp.listen(appExp.get("port"), announceWebServer); } @@ -45,9 +44,6 @@ function startWebServer() { // Initialize the webserver startWebServer(); - Logger.initializeToConsole(); - Logger.setLevelDefault(LogLevel.Info); - // Initialize the backend await initializeBackend(); @@ -65,7 +61,6 @@ function startWebServer() { else if (arg === "egl"){ chromeFlags.push("--use-gl=angle"); chromeFlags.push("--use-angle=gl-egl"); - chromeFlags.push("--enable-logging"); } }); @@ -113,11 +108,9 @@ function startWebServer() { if (process.platform === "darwin") { // Ie, if running on Mac child_process.execSync("open -a \"Google Chrome\" http://localhost:3000"); } else { - console.log(`logLevel: verbose`); chromeLauncher.launch({ // eslint-disable-line @typescript-eslint/no-floating-promises startingUrl: "http://localhost:3000", chromeFlags, - logLevel: "verbose", }).then((val) => { DisplayPerfRpcInterface.chrome = val; }); } break; From 9c783e5801fd576cb821011ade8de99a13a483c1 Mon Sep 17 00:00:00 2001 From: Mathieu Le Muzic <130933088+mlemuzic-bentley@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:08:26 +0200 Subject: [PATCH 3/5] log --- .../src/backend/DisplayPerfRpcImpl.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts b/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts index 3b917e3f14ed..a324d8f29636 100644 --- a/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts +++ b/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts @@ -166,6 +166,10 @@ export default class DisplayPerfRpcImpl extends DisplayPerfRpcInterface { } public override async terminate() { + + // eslint-disable-next-line no-console + console.log("terminating DPTA"); + await IModelHost.shutdown(); // Electron only From 245626e8ab0a56f70e2f730de961147447dc0ad8 Mon Sep 17 00:00:00 2001 From: Mathieu Le Muzic <130933088+mlemuzic-bentley@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:12:22 +0200 Subject: [PATCH 4/5] test --- .../src/backend/DisplayPerfRpcImpl.ts | 42 ++++++++++++++++++- .../src/frontend/DisplayPerformanceTestApp.ts | 13 ++++-- .../src/frontend/TestRunner.ts | 10 +++-- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts b/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts index a324d8f29636..449fa8778269 100644 --- a/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts +++ b/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. @@ -12,6 +13,41 @@ import { Reporter } from "@itwin/perf-tools"; import DisplayPerfRpcInterface from "../common/DisplayPerfRpcInterface"; import { addColumnsToCsvFile, addDataToCsvFile, addEndOfTestToCsvFile, createFilePath, createNewCsvFile } from "./CsvWriter"; import { DptaEnvConfig, getConfig } from "../common/DisplayPerfEnvConfig"; +import * as child_process from "child_process"; + +function killProcess(processId: number) { + try { + console.log(`Killing process ${processId}`); + if (process.platform === "win32") { + try { + child_process.execSync(`taskkill /pid ${processId} /T /F`); + } catch (error) { + console.error(error); + console.error(`Killing ${processId} using taskkill failed`, error); + // taskkill can fail to kill the process e.g. due to missing permissions. + // Let's kill the process via Node API. This delays killing of all child + // processes of `this.proc` until the main Node.js process dies. + process.kill(processId); + } + } else { + try { + // on linux the process group can be killed with the group id prefixed with + // a minus sign. The process group id is the group leader's pid. + process.kill(-processId, "SIGKILL"); + } catch (error) { + console.error(error); + console.error(`Killing ${processId} using process.kill failed.`); + // Killing the process group can fail due e.g. to missing permissions. + // Let's kill the process via Node API. This delays killing of all child + // processes of `this.proc` until the main Node.js process dies. + process.kill(processId, "SIGKILL"); + } + } + } catch (error) { + console.error(`DPTA was unable to kill the process.`); + console.error(error); + } +} /** The backend implementation of DisplayPerfRpcImpl. */ export default class DisplayPerfRpcImpl extends DisplayPerfRpcInterface { @@ -167,8 +203,7 @@ export default class DisplayPerfRpcImpl extends DisplayPerfRpcInterface { public override async terminate() { - // eslint-disable-next-line no-console - console.log("terminating DPTA"); + console.log("backlog: terminating"); await IModelHost.shutdown(); @@ -185,6 +220,9 @@ export default class DisplayPerfRpcImpl extends DisplayPerfRpcInterface { if (DisplayPerfRpcInterface.chrome) DisplayPerfRpcInterface.chrome.kill(); + + console.log("backlog: terminated"); + killProcess(process.pid); } private createFullFilePath(filePath: string | undefined, fileName: string | undefined): string | undefined { diff --git a/test-apps/display-performance-test-app/src/frontend/DisplayPerformanceTestApp.ts b/test-apps/display-performance-test-app/src/frontend/DisplayPerformanceTestApp.ts index 79824933be63..de2b483b05c3 100644 --- a/test-apps/display-performance-test-app/src/frontend/DisplayPerformanceTestApp.ts +++ b/test-apps/display-performance-test-app/src/frontend/DisplayPerformanceTestApp.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. @@ -17,6 +18,7 @@ import { IModelsClient } from "@itwin/imodels-client-management"; import DisplayPerfRpcInterface from "../common/DisplayPerfRpcInterface"; import { TestRunner, TestSetsProps } from "./TestRunner"; import { DptaEnvConfig } from "../common/DisplayPerfEnvConfig"; +import { child_process } from "child_process"; export const envConfiguration: DptaEnvConfig = {}; let runner: TestRunner; @@ -89,7 +91,7 @@ export class DisplayPerfTestApp { const frontendTilesNopFallback = (runner && runner.curConfig && runner.curConfig.frontendTilesNopFallback) ? runner.curConfig.frontendTilesNopFallback : false; - if(frontendTilesNopFallback){ + if (frontendTilesNopFallback) { await DisplayPerfRpcInterface.getClient().consoleLog("Nop fallback enabled for frontend tiles."); } @@ -168,13 +170,18 @@ async function main() { } catch (err: any) { await DisplayPerfTestApp.logException(err); } finally { + console.log("Frontend: terminating"); await DisplayPerfRpcInterface.getClient().terminate(); } - - return IModelApp.shutdown(); + console.log("Frontend: shutting down"); + await IModelApp.shutdown(); + console.log("Frontend: shut down"); } window.onload = async () => { + + console.log("Frontend: initializing..."); + // Choose RpcConfiguration based on whether we are in electron or browser RpcConfiguration.developmentMode = true; RpcConfiguration.disableRoutingValidation = true; diff --git a/test-apps/display-performance-test-app/src/frontend/TestRunner.ts b/test-apps/display-performance-test-app/src/frontend/TestRunner.ts index 36db113f41d4..3cc4b6824609 100644 --- a/test-apps/display-performance-test-app/src/frontend/TestRunner.ts +++ b/test-apps/display-performance-test-app/src/frontend/TestRunner.ts @@ -209,11 +209,13 @@ export class TestRunner { await this.logToConsole(msg); await this.logToFile(msg, { noAppend: true }); - const logConsole = (level: string) => async (category: string, message: string, metaData: LoggingMetaData) => - this.logToConsole(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); + // eslint-disable-next-line no-console + console.log("Running tests..."); + // const logConsole = (level: string) => async (category: string, message: string, metaData: LoggingMetaData) => + // this.logToConsole(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); - Logger.initialize(logConsole("Error"), logConsole("Warning"), logConsole("Info"), logConsole("Trace")); - Logger.setLevelDefault(LogLevel.Info); + // Logger.initialize(logConsole("Error"), logConsole("Warning"), logConsole("Info"), logConsole("Trace")); + // Logger.setLevelDefault(LogLevel.Info); let needRestart = this.curConfig.requiresRestart(new TestConfig({})); // If current config differs from default, restart const renderOptions: RenderSystem.Options = this.curConfig.renderOptions ?? {}; From 8d007a711f649204ea967a3e2899222e305fd9c8 Mon Sep 17 00:00:00 2001 From: Mathieu Le Muzic <130933088+mlemuzic-bentley@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:30:32 +0200 Subject: [PATCH 5/5] revert --- .../src/backend/DisplayPerfRpcImpl.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts b/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts index 449fa8778269..bf22d1745ca3 100644 --- a/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts +++ b/test-apps/display-performance-test-app/src/backend/DisplayPerfRpcImpl.ts @@ -222,7 +222,6 @@ export default class DisplayPerfRpcImpl extends DisplayPerfRpcInterface { DisplayPerfRpcInterface.chrome.kill(); console.log("backlog: terminated"); - killProcess(process.pid); } private createFullFilePath(filePath: string | undefined, fileName: string | undefined): string | undefined {