|
22 | 22 | #include "mlvalues.h"
|
23 | 23 | #include "roots.h"
|
24 | 24 |
|
25 |
| -/* Suspend or unsuspend profiling */ |
| 25 | +/*** Sample allocations ***/ |
| 26 | + |
| 27 | +/* [Gc.Memprof.allocation_source] */ |
| 28 | + |
| 29 | +enum { CAML_MEMPROF_SRC_NORMAL = 0, |
| 30 | + CAML_MEMPROF_SRC_MARSHAL = 1, /* interning */ |
| 31 | + CAML_MEMPROF_SRC_CUSTOM = 2 /* custom memory */ }; |
| 32 | + |
| 33 | +/* Respond to the allocation of any block. Does not call callbacks. |
| 34 | + * `block` is the allocated block, to be tracked by memprof if |
| 35 | + * sampled. `allocated_words` is the number of words allocated, to be |
| 36 | + * passed to the allocation callback. `sampled_words` is the number of |
| 37 | + * words to use when computing the number of samples (this will |
| 38 | + * normally be one more than `allocated words` due to the header word, |
| 39 | + * but may not be for out-of-heap memory). `source` is one of the |
| 40 | + * `CAML_MEMPROF_SRC_* constants above. */ |
| 41 | + |
| 42 | +void caml_memprof_sample_block(value block, size_t allocated_words, |
| 43 | + size_t sampled_words, int source); |
| 44 | + |
| 45 | +/* Sample a minor heap "Comballoc" (combined allocation). Called when |
| 46 | + * the memprof trigger is hit (before the allocation is actually |
| 47 | + * performed, which may require a GC). `allocs` and `alloc_lens` |
| 48 | + * describe the combined allocation. Runs allocation callbacks. */ |
| 49 | + |
| 50 | +extern void caml_memprof_sample_young(uintnat wosize, int from_caml, |
| 51 | + int allocs, unsigned char* alloc_lens); |
| 52 | + |
| 53 | +/* Suspend or unsuspend sampling (for the current thread). */ |
| 54 | + |
26 | 55 | extern void caml_memprof_update_suspended(_Bool);
|
27 | 56 |
|
28 |
| -/* Freshly set sampling point on minor heap */ |
29 |
| -extern void caml_memprof_renew_minor_sample(caml_domain_state *state); |
30 | 57 |
|
31 |
| -/* Multi-domain support. */ |
| 58 | +/*** GC interface ***/ |
| 59 | + |
| 60 | +/* Apply `f(fdata, r, &r)` to each GC root `r` within memprof data |
| 61 | + * structures for the domain `state`. |
| 62 | + * |
| 63 | + * `fflags` is used to decide whether to only scan roots which may |
| 64 | + * point to minor heaps (the `SCANNING_ONLY_YOUNG_VALUES` flag). |
| 65 | + * |
| 66 | + * If `weak` is false then only scan strong roots. If `weak` |
| 67 | + * is true then also scan weak roots. |
| 68 | + * |
| 69 | + * If `global` is false then only scan roots for `state`. If `global` |
| 70 | + * is true then also scan roots shared between all domains. */ |
| 71 | + |
| 72 | +extern void caml_memprof_scan_roots(scanning_action f, |
| 73 | + scanning_action_flags fflags, |
| 74 | + void* fdata, |
| 75 | + caml_domain_state *state, |
| 76 | + _Bool weak, |
| 77 | + _Bool global); |
| 78 | + |
| 79 | +/* Update memprof data structures for the domain `state`, to reflect |
| 80 | + * survival and promotion, after a minor GC is completed. |
| 81 | + * |
| 82 | + * If `global` is false then only update structures for `state`. If |
| 83 | + * `global` is true then also update structures shared between all |
| 84 | + * domains. */ |
| 85 | + |
| 86 | +extern void caml_memprof_after_minor_gc(caml_domain_state *state, _Bool global); |
| 87 | + |
| 88 | +/* Update memprof data structures for the domain `state`, to reflect |
| 89 | + * survival, after a minor GC is completed. |
| 90 | + * |
| 91 | + * If `global` is false then only update structures for `state`. If |
| 92 | + * `global` is true then also update structures shared between all |
| 93 | + * domains. */ |
| 94 | + |
| 95 | +extern void caml_memprof_after_major_gc(caml_domain_state *state, _Bool global); |
| 96 | + |
| 97 | +/* Freshly computes state->memprof_young_trigger. *Does not* set the |
| 98 | + * young limit. */ |
| 99 | + |
| 100 | +extern void caml_memprof_set_trigger(caml_domain_state *state); |
| 101 | + |
| 102 | +/*** Callbacks ***/ |
| 103 | + |
| 104 | +/* Run any pending callbacks for the current domain (or adopted from a |
| 105 | + * terminated domain). */ |
| 106 | + |
| 107 | +extern value caml_memprof_run_callbacks_exn(void); |
| 108 | + |
| 109 | + |
| 110 | +/*** Multi-domain support. ***/ |
| 111 | + |
| 112 | +/* Notify memprof of the creation of a new domain `domain`. If there |
| 113 | + * was an existing domain (from which to inherit profiling behaviour), |
| 114 | + * it is passed in `parent`. Called before the new domain allocates |
| 115 | + * anything, and before the parent domain continues. Also creates |
| 116 | + * memprof thread state for the initial thread of the domain. */ |
32 | 117 |
|
33 | 118 | extern void caml_memprof_new_domain(caml_domain_state *parent,
|
34 | 119 | caml_domain_state *domain);
|
| 120 | + |
| 121 | +/* Notify memprof that the domain `domain` is terminating. Called |
| 122 | + * after the last allocation by the domain. */ |
| 123 | + |
35 | 124 | extern void caml_memprof_delete_domain(caml_domain_state *domain);
|
36 | 125 |
|
37 |
| -/* Multi-thread support */ |
| 126 | + |
| 127 | +/*** Multi-thread support ***/ |
| 128 | + |
| 129 | +/* Opaque type of memprof state for a single thread. */ |
38 | 130 |
|
39 | 131 | typedef struct memprof_thread_s *memprof_thread_t;
|
40 | 132 |
|
41 |
| -CAMLextern memprof_thread_t caml_memprof_main_thread(caml_domain_state *domain); |
| 133 | +/* Notify memprof that a new thread is being created. Returns a |
| 134 | + * pointer to memprof state for the new thread. */ |
| 135 | + |
42 | 136 | CAMLextern memprof_thread_t caml_memprof_new_thread(caml_domain_state *domain);
|
| 137 | + |
| 138 | +/* Obtain the memprof state for the initial thread of a domain. Called |
| 139 | + * when there is only one such thread. */ |
| 140 | + |
| 141 | +CAMLextern memprof_thread_t caml_memprof_main_thread(caml_domain_state *domain); |
| 142 | + |
| 143 | +/* Notify memprof that the current domain is switching to the given |
| 144 | + * thread. */ |
| 145 | + |
43 | 146 | CAMLextern void caml_memprof_enter_thread(memprof_thread_t);
|
| 147 | + |
| 148 | +/* Notify memprof that the given thread is being deleted. */ |
| 149 | + |
44 | 150 | CAMLextern void caml_memprof_delete_thread(memprof_thread_t);
|
45 | 151 |
|
46 | 152 | #endif
|
|
0 commit comments