Skip to content

Conversation

@NickBarnes
Copy link
Contributor

@NickBarnes NickBarnes commented Apr 3, 2024

A couple of very minor improvements to statmemprof, following comments made after the merge of #12923:

  • One is an incorrect C type, which is harmless at present as both of the relevant types are currently typedef'ed to the same underlying type.
  • The other attempts to run any pending allocation callbacks during caml_memprof_stop(), to further increase the likelihood of running all appropriate allocation callbacks.

@NickBarnes NickBarnes marked this pull request as ready for review April 3, 2024 13:25
@NickBarnes NickBarnes force-pushed the nick-statmemprof-tweaks branch from 4e1c367 to 6f6ef42 Compare April 3, 2024 14:00
Copy link
Contributor

@gadmm gadmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. One minor question below about something that could be worth documenting in the code.

Comment on lines 2282 to 2290
/* Final attempt to run allocation callbacks. */
if (!thread->suspended) {
update_suspended(domain, true);
value res = entries_run_callbacks_exn(thread, &thread->entries);
update_suspended(domain, false);
(void) caml_raise_if_exception(res);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seems careful not to call caml_memprof_run_callbacks_exn (another choice could be caml_process_pending_actions). What is the reason for this choice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a judgement call. I mainly want to run any pending allocation callbacks here, to avoid them being discarded. Pending allocation callbacks are all on the thread->entries table. If I callcaml_memprof_run_callbacks_exn, then other entries tables for this domain will be processed too, including (at present) the domain->entries table before the thread->entries callbacks. This may prevent the thread->entries callbacks from running, for example if one of the domain->entries callbacks raises an exception.
This is really just an aesthetic choice, as of course those other callbacks might run at any time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment.

Try to run deferred allocation callbacks before stopping sampling.

No change entry needed.
@NickBarnes NickBarnes force-pushed the nick-statmemprof-tweaks branch from 6f6ef42 to b029b8c Compare April 5, 2024 13:14
Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on @gadmm's behalf. Thanks!

@gasche gasche added the merge-me label Apr 5, 2024
@gasche gasche merged commit 753c8ac into ocaml:trunk Apr 5, 2024
sadiqj pushed a commit to sadiqj/ocaml that referenced this pull request Apr 24, 2024
* Import new Gc.Memprof API

* Import new statmemprof testsuite

* Runtime4 support for new statmemprof testsuite

* Port 12383: backtrace abstractions

* Import runtime5 statmemprof implementation

Ports PRs ocaml#12382, ocaml#12817, ocaml#12824, ocaml#12923, ocaml#13068

* Avoid allocating unnecessarily during bytecode callbacks

* Minor statmemprof testsuite robustness fixes
NickBarnes pushed a commit to NickBarnes/ocaml that referenced this pull request May 21, 2024
Minor post-merge improvements to statmemprof
NickBarnes pushed a commit to NickBarnes/ocaml that referenced this pull request May 21, 2024
Minor post-merge improvements to statmemprof

(cherry picked from commit 753c8ac)
MisterDA pushed a commit to MisterDA/ocaml that referenced this pull request Feb 13, 2025
Minor post-merge improvements to statmemprof

(cherry picked from commit 753c8ac)
(cherry picked from commit ac20138)
dra27 pushed a commit to ocaml-multicore/ocaml that referenced this pull request Feb 13, 2025
Minor post-merge improvements to statmemprof

(cherry picked from commit 753c8ac)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants