Skip to content

Commit

Permalink
[PROF-8543] Sprinkle some fprintfs for CI test debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJF committed Nov 7, 2023
1 parent 6f36290 commit 646dd5d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ext/ddtrace_profiling_native_extension/heap_recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ void commit_allocation(heap_recorder *heap_recorder, heap_stack *heap_stack, VAL
return;
}

fprintf(stderr, "Committed allocation of %lu (heap_record=%p, object_record=%p)\n", obj, heap_record, object_record);

heap_record->num_tracked_objects++;
heap_record->inuse_objects += weight;
}
Expand All @@ -216,13 +218,17 @@ void commit_free(heap_recorder *heap_recorder, VALUE obj) {
heap_record->num_tracked_objects--;
heap_record->inuse_objects -= object_record->weight;

fprintf(stderr, "Committed free of %lu (heap_record=%p, object_record=%p)\n", obj, heap_record, object_record);

object_record_free(object_record);
}

static void flush_queue(heap_recorder *heap_recorder) {
for (size_t i = 0; i < heap_recorder->queued_samples_len; i++) {
sample *queued_sample = &heap_recorder->queued_samples[i];
if (!queued_sample->skip) {
fprintf(stderr, "Flushing sample %p\n", queued_sample);

if (queued_sample->free) {
commit_free(heap_recorder, queued_sample->obj);
} else {
Expand All @@ -236,7 +242,9 @@ static void flush_queue(heap_recorder *heap_recorder) {
}

static void enqueue_sample(heap_recorder *heap_recorder, sample new_sample) {
fprintf(stderr, "Enqueuing sample for %lu (weight=%u free=%i)\n", new_sample.obj, new_sample.weight, new_sample.free);
if (heap_recorder->queued_samples_len >= MAX_QUEUE_LIMIT) {
fprintf(stderr, "Dropping sample on the floor.\n");
return;
}

Expand Down Expand Up @@ -265,6 +273,7 @@ static void enqueue_free(heap_recorder *heap_recorder, VALUE obj) {
}

void start_heap_allocation_recording(heap_recorder* heap_recorder, VALUE new_obj, unsigned int weight, ddog_CharSlice *class_name) {
fprintf(stderr, "Started recording allocation of %lu with weight %u\n", new_obj, weight);
partial_heap_recording *active_recording = &heap_recorder->active_recording;
active_recording->obj = new_obj;
active_recording->weight = weight;
Expand Down Expand Up @@ -437,6 +446,19 @@ void heap_stack_free(heap_stack *stack) {
ruby_xfree(stack);
}

void heap_stack_debug(const heap_stack *stack) {
fprintf(stderr, "stack {\n");
for (uint64_t i = 0; i < stack->frames_len; i++) {
heap_frame *frame = &stack->frames[i];
fprintf(stderr, " frame {\n");
fprintf(stderr, " name: '%s'\n", frame->name);
fprintf(stderr, " filename: '%s'\n", frame->filename);
fprintf(stderr, " line: %lli\n", frame->line);
fprintf(stderr, " }\n");
}
fprintf(stderr, "}\n");
}

int heap_stack_cmp(heap_stack *st1, heap_stack *st2) {
if (st1->frames_len != st2->frames_len) {
return (int) (st1->frames_len - st2->frames_len);
Expand Down

0 comments on commit 646dd5d

Please sign in to comment.