Multicore statmemprof support, with a caller-supplied Memprof implementation - #1
Open
dimitris-m wants to merge 6 commits into
Open
dimitris-m wants to merge 6 commits into
dimitris-m wants to merge 6 commits into
Conversation
Signed-off-by: Tim McGilchrist <timmcgil@gmail.com>
Signed-off-by: Tim McGilchrist <timmcgil@gmail.com>
Signed-off-by: Tim McGilchrist <timmcgil@gmail.com>
Signed-off-by: Tim McGilchrist <timmcgil@gmail.com>
Take a sample when an external allocation crosses the sampling threshold, rather than one allocation later. Treat an empty MEMTRACE_RATE as unset, so the rate falls back to the one given by the caller or to the default, rather than raising Invalid_argument. Re-test the failed flag after acquiring the tracer mutex. One domain can mark the tracer as failed while another is already waiting for the lock, which can cause an assertion failure in the waiting domain. Use an ordinary reference for the external sample count, which is only read and written inside the critical section.
Only one Memprof profile can run per domain, so a library that starts its own profile, such as memprof-limits, cannot be used together with memtrace. The caller can now pass the Memprof implementation that memtrace should use, so that both use the same profile. It defaults to the standard library's Gc.Memprof. Stopping the tracer also discards the profile, so no further callbacks arrive once tracing has ended. Starting tracing manually now takes a final unit argument. Requires OCaml 5.3 or later. domainslib is needed only for the examples.
dimitris-m
force-pushed
the
dm/multicore-memprof-limits-compat
branch
from
September 17, 2026 13:04
e07ce89 to
874e70b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on janestreet#22 by @tmcgilchrist. The first four commits are
taken unchanged from the tip of that branch, one of them authored by
@grouptheoryiscool.
Fix external sampling, MEMTRACE_RATE and locking defects
ext_allocsamples when an external allocation crosses the threshold, not oneallocation later.
MEMTRACE_RATEis treated as unset.lock_tracerre-tests the failed flag after acquiring the mutex.Allow the caller to supply the Memprof implementation
start_tracingandtrace_if_requestedtake?memprof:(module Memtrace.Memprof_sig), whereMemprof_sigismodule type of Stdlib.Gc.Memprof, defaulting toGc.Memprof. This letsmemtrace share a profile with another user of the interface, such as
memprof-limits.
No plans to merge this but we need it in opengrep.