Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 9183d0d

Browse files
authored
feat: memory metrics for debug panel in renderer (#578)
* Sending memory metrics to renderer * Added function to get jsHepSize * SetMemoryUsage poitinting to Main * Lint fix
1 parent 1a56785 commit 9183d0d

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

packages/unity-interface/BrowserInterface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,10 @@ export class BrowserInterface {
837837
)
838838
}
839839

840+
public async UpdateMemoryUsage() {
841+
getUnityInstance().SendMemoryUsageToRenderer()
842+
}
843+
840844
public ScenesLoadingFeedback(data: { message: string; loadPercentage: number }) {
841845
const { message, loadPercentage } = data
842846
store.dispatch(updateStatusMessage(message, loadPercentage))

packages/unity-interface/IUnityInterface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export interface IUnityInterface {
201201
UpdateRealmsInfo(realmsInfo: Partial<RealmsInfoForRenderer>): void
202202
SetENSOwnerQueryResult(searchInput: string, profiles: Avatar[] | undefined, contentServerBaseUrl: string): void
203203
SendHeaders(endpoint: string, headers: Record<string, string>): void
204+
SendMemoryUsageToRenderer(): void
204205

205206
// *********************************************************************************
206207
// ************** Builder in world messages **************

packages/unity-interface/UnityInterface.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ export class UnityInterface implements IUnityInterface {
225225
this.SendMessageToUnity('Bridges', 'SetLoadingScreen', JSON.stringify(data))
226226
}
227227

228+
public SendMemoryUsageToRenderer() {
229+
const memory = (performance as any).memory
230+
const jsHeapSizeLimit = memory?.jsHeapSizeLimit
231+
const totalJSHeapSize = memory?.totalJSHeapSize
232+
const usedJSHeapSize = memory?.usedJSHeapSize
233+
234+
this.SendMessageToUnity(
235+
'Main',
236+
'SetMemoryUsage',
237+
JSON.stringify({ jsHeapSizeLimit, totalJSHeapSize, usedJSHeapSize })
238+
)
239+
}
240+
228241
public DeactivateRendering() {
229242
this.SendMessageToUnity('Main', 'DeactivateRendering')
230243
}

0 commit comments

Comments
 (0)