History

V8 memory usage statistics

ksuprynowicz committed 3 years ago

Commit 56c3bad1 parent 2faacfa6 files · +130 −33Browse files

Showing the changes to scripts/developer/debugging/scriptMemoryReport.js (1 of 6 files). Show all

Unified · Split

scripts/developer/debugging/scriptMemoryReport.js+27−0
@@ -0,0 +1,27 @@
1//
2// scriptMemoryReport.js
3// scripts/developer/debugging
4//
5// Created by dr Karol Suprynowicz on 2023/04/23
6// Copyright 2023 Overte e.V.
7//
8// Distributed under the Apache License, Version 2.0.
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10// SPDX-License-Identifier: Apache-2.0
11//
12
13// A simple script that prints memory usage statistics for a given script engine every 5 seconds
14// It can be included for example as a part of default scripts or controller scripts
15
16var memoryStatisticsIntervalHandle = Script.setInterval(function () {
17 statistics = Script.getMemoryUsageStatistics();
18 print("Script memory usage: Total heap size: " + statistics.totalHeapSize
19 + " usedHeapSize: " + statistics.usedHeapSize
20 + " totalAvailableSize: " + statistics.totalAvailableSize
21 + " totalGlobalHandlesSize: " + statistics.totalGlobalHandlesSize
22 + " usedGlobalHandlesSize: " + statistics.usedGlobalHandlesSize);
23}, 5000);
24
25Script.scriptEnding.connect(function () {
26 Script.clearInterval(memoryStatisticsIntervalHandle);
27});