Skip to content

Memoryprofiler doesn't support multi-threaded application #18107

Closed

Description

@junyuecao

I was using memoryprofiler to monitor the memory usage of a multi-threaded application. But it looks like it doesn't support to record the malloc and free from a worker thread.

Activity

  1. junyuecao commented on Oct 28, 2022

    @junyuecao
    ContributorAuthor

    I thinks the problem is here(src/library_trace.js)

    emscripten_trace_record_allocation: function(address, size) {
        // This line: only the main thread has onMalloc callback
        if (typeof Module['onMalloc'] == 'function') Module['onMalloc'](address, size); 
        if (EmscriptenTrace.postEnabled) {
          var now = EmscriptenTrace.now();
          EmscriptenTrace.post([EmscriptenTrace.EVENT_ALLOCATE,
                                now, address, size]);
        }
      },
    
  2. kripken commented on Nov 3, 2022

    @kripken
    Member

    One option here might be to add emscripten_trace_record_allocation__proxy: 'async' to library.js, which would send messages to the main thread. Does that work? If so a PR would be welcome.

  3. junyuecao commented on Nov 4, 2022

    @junyuecao
    ContributorAuthor

    @kripken Thank you for the advice.
    I looked into the proxy module, it's not that straightforward. The emscripten_run_in_main_runtime_thread_js (library_pthread.c) function will call malloc and cause a infinite loop deadlock.

    I'll continue to try to find a way to fix it.

  4. added a commit that references this issue on Feb 27, 2026
    375bba6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions