Skip to content

Commit 519f81b

Browse files
authored
Fix closure warnings with --threadprofiler and --memoryprofiler. NFC (#22786)
1 parent 8064a6c commit 519f81b

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

src/library_pthread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ var LibraryPThread = {
168168
}
169169
PThread.unusedWorkers = [];
170170
PThread.runningWorkers = [];
171-
PThread.pthreads = [];
171+
PThread.pthreads = {};
172172
},
173173
returnWorkerToPool: (worker) => {
174174
// We don't want to run main thread queued calls here, since we are doing

src/memoryprofiler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ var emscriptenMemoryProfiler = {
503503
html += '<br />STACK memory area used now (should be zero): ' + self.formatBytes(stackBase - stackCurrent) + '.' + colorBar('#FFFF00') + ' STACK watermark highest seen usage (approximate lower-bound!): ' + self.formatBytes(stackBase - self.stackTopWatermark);
504504

505505
var heap_base = Module['___heap_base'];
506-
var heap_end = _sbrk();
506+
var heap_end = _sbrk({{{ to64('0') }}});
507507
html += "<br />DYNAMIC memory area size: " + self.formatBytes(heap_end - heap_base);
508508
html += ". start: " + toHex(heap_base, width);
509509
html += ". end: " + toHex(heap_end, width) + ".";
@@ -612,8 +612,8 @@ var emscriptenMemoryProfiler = {
612612
calls.sort((a,b) => b[sortIdx] - a[sortIdx]);
613613
}
614614
html += '<h4>Allocation sites with more than ' + self.formatBytes(self.trackedCallstackMinSizeBytes) + ' of accumulated allocations, or more than ' + self.trackedCallstackMinAllocCount + ' simultaneously outstanding allocations:</h4>'
615-
for (var i in calls) {
616-
html += "<b>" + self.formatBytes(calls[i][1]) + '/' + calls[i][0] + " allocs</b>: " + calls[i][2] + "<br />";
615+
for (var call of calls) {
616+
html += "<b>" + self.formatBytes(call[1]) + '/' + call[0] + " allocs</b>: " + call[2] + "<br />";
617617
}
618618
}
619619
}

src/threadprofiler.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ var emscriptenThreadProfiler = {
1515

1616
// Installs startup hook and periodic UI update timer.
1717
initialize() {
18-
this.threadProfilerDiv = document.getElementById('threadprofiler');
19-
if (!this.threadProfilerDiv) {
18+
var self = emscriptenThreadProfiler;
19+
self.threadProfilerDiv = document.getElementById('threadprofiler');
20+
if (!self.threadProfilerDiv) {
2021
var div = document.createElement("div");
2122
div.innerHTML = "<div id='threadprofiler' style='margin: 20px; border: solid 1px black;'></div>";
2223
document.body.appendChild(div);
23-
this.threadProfilerDiv = document.getElementById('threadprofiler');
24+
self.threadProfilerDiv = document.getElementById('threadprofiler');
2425
}
25-
var i = setInterval(function() { emscriptenThreadProfiler.updateUi() }, this.uiUpdateIntervalMsecs);
26+
var i = setInterval(() => self.updateUi(), self.uiUpdateIntervalMsecs);
2627
addOnExit(() => clearInterval(i));
2728
},
2829

2930
initializeNode() {
3031
addOnInit(() => {
31-
emscriptenThreadProfiler.dumpState();
32-
var i = setInterval(function() { emscriptenThreadProfiler.dumpState() }, this.uiUpdateIntervalMsecs);
32+
var self = emscriptenThreadProfiler;
33+
self.dumpState();
34+
var i = setInterval(() => self.dumpState(), self.uiUpdateIntervalMsecs);
3335
addOnExit(() => clearInterval(i));
3436
});
3537
},
@@ -38,11 +40,10 @@ var emscriptenThreadProfiler = {
3840
var mainThread = _emscripten_main_runtime_thread_id();
3941

4042
var threads = [mainThread];
41-
for (var i in PThread.pthreads) {
42-
threads.push(PThread.pthreads[i].pthread_ptr);
43+
for (var thread of Object.values(PThread.pthreads)) {
44+
threads.push(thread.pthread_ptr);
4345
}
44-
for (var i = 0; i < threads.length; ++i) {
45-
var threadPtr = threads[i];
46+
for (var threadPtr of threads) {
4647
var threadName = PThread.getThreadName(threadPtr);
4748
if (threadName) {
4849
threadName = `"${threadName}" (${ptrToString(threadPtr)})`;
@@ -60,16 +61,18 @@ var emscriptenThreadProfiler = {
6061
// initialized yet, ignore updating.
6162
return;
6263
}
64+
if (!runtimeInitialized) {
65+
return;
66+
}
6367
var str = '';
6468
var mainThread = _emscripten_main_runtime_thread_id();
6569

6670
var threads = [mainThread];
67-
for (var i in PThread.pthreads) {
68-
threads.push(PThread.pthreads[i].pthread_ptr);
71+
for (var thread of Object.values(PThread.pthreads)) {
72+
threads.push(thread.pthread_ptr);
6973
}
7074

71-
for (var i = 0; i < threads.length; ++i) {
72-
var threadPtr = threads[i];
75+
for (var threadPtr of threads) {
7376
var profilerBlock = Atomics.load({{{ getHeapForType('*') }}}, {{{ getHeapOffset('threadPtr + ' + C_STRUCTS.pthread.profilerBlock, '*') }}});
7477
#if MEMORY64
7578
profilerBlock = Number(profilerBlock);
@@ -100,7 +103,7 @@ var emscriptenThreadProfiler = {
100103
if (recent.length > 0) str += `Recent activity: ${recent}`;
101104
str += '<br />';
102105
}
103-
this.threadProfilerDiv.innerHTML = str;
106+
emscriptenThreadProfiler.threadProfilerDiv.innerHTML = str;
104107
}
105108
};
106109

test/test_other.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12813,13 +12813,11 @@ def test_cpuprofiler_closure(self):
1281312813

1281412814
# Make sure that --memoryprofiler compiles with --closure 1
1281512815
def test_memoryprofiler_closure(self):
12816-
# TODO: Enable '-Werror=closure' in the following, but that has currently regressed.
12817-
self.run_process([EMCC, test_file('hello_world.c'), '-O2', '--closure=1', '--memoryprofiler'])
12816+
self.run_process([EMCC, test_file('hello_world.c'), '-O2', '--closure=1', '--memoryprofiler'] + self.get_emcc_args())
1281812817

1281912818
# Make sure that --threadprofiler compiles with --closure 1
1282012819
def test_threadprofiler_closure(self):
12821-
# TODO: Enable '-Werror=closure' in the following, but that has currently regressed.
12822-
self.run_process([EMCC, test_file('hello_world.c'), '-O2', '-pthread', '--closure=1', '--threadprofiler', '-sASSERTIONS'])
12820+
self.run_process([EMCC, test_file('hello_world.c'), '-O2', '-pthread', '--closure=1', '--threadprofiler', '-sASSERTIONS'] + self.get_emcc_args())
1282312821

1282412822
@node_pthreads
1282512823
def test_threadprofiler(self):

0 commit comments

Comments
 (0)