Skip to content

Commit c51fb57

Browse files
authored
Merge branch 'master' into change-system-tests-workflow-run-conditions
2 parents 227b462 + 8818eb8 commit c51fb57

8 files changed

+86
-136
lines changed

benchmarks/profiler_memory_sample_serialize.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# This benchmark measures the performance of sampling + serializing memory profiles. It enables us to evaluate changes to
1313
# the profiler and/or libdatadog that may impact both individual samples, as well as samples over time.
1414
#
15-
METRIC_VALUES = { 'cpu-time' => 0, 'cpu-samples' => 0, 'wall-time' => 0, 'alloc-samples' => 1, 'timeline' => 0 }.freeze
15+
METRIC_VALUES = { 'cpu-time' => 0, 'cpu-samples' => 0, 'wall-time' => 0, 'alloc-samples' => 1, 'timeline' => 0, 'heap_sample' => true }.freeze
1616
OBJECT_CLASS = 'object'.freeze
1717

1818
def sample_object(recorder, depth = 0)
@@ -56,6 +56,21 @@ def setup
5656
}
5757
end
5858

59+
def create_objects(recorder)
60+
samples_per_second = 100
61+
simulate_seconds = 60
62+
retained_objs = []
63+
64+
(samples_per_second * simulate_seconds).times do |i|
65+
obj = sample_object(recorder, i % 400)
66+
retained_objs << obj if (i % @retain_every).zero?
67+
end
68+
69+
GC.start unless @skip_end_gc
70+
71+
retained_objs
72+
end
73+
5974
def run_benchmark
6075
Benchmark.ips do |x|
6176
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 30, warmup: 2 }
@@ -65,18 +80,11 @@ def run_benchmark
6580

6681
x.report("sample+serialize #{ENV['CONFIG']} retain_every=#{@retain_every} heap_samples=#{@heap_samples_enabled} heap_size=#{@heap_size_enabled} heap_sample_every=#{@heap_sample_every} skip_end_gc=#{@skip_end_gc}") do
6782
recorder = @recorder_factory.call
68-
samples_per_second = 100
69-
simulate_seconds = 60
70-
retained_objs = []
71-
72-
(samples_per_second * simulate_seconds).times do |i|
73-
obj = sample_object(recorder, i % 400)
74-
retained_objs << obj if (i % @retain_every).zero?
75-
end
76-
77-
GC.start unless @skip_end_gc
83+
retained_objs = create_objects(recorder)
7884

7985
recorder.serialize
86+
87+
retained_objs.size # Dummy action to make sure this is still alive
8088
end
8189

8290
x.save! "#{File.basename(__FILE__)}-results.json" unless VALIDATE_BENCHMARK_MODE

ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "setup_signal_handler.h"
1818
#include "time_helpers.h"
1919

20-
// Used to trigger the execution of Collectors::ThreadState, which implements all of the sampling logic
20+
// Used to trigger the execution of Collectors::ThreadContext, which implements all of the sampling logic
2121
// itself; this class only implements the "when to do it" part.
2222
//
2323
// This file implements the native bits of the Datadog::Profiling::Collectors::CpuAndWallTimeWorker class
@@ -33,7 +33,7 @@
3333
// Currently, sampling Ruby threads requires calling Ruby VM APIs that are only safe to call while holding on to the
3434
// global VM lock (and are not async-signal safe -- cannot be called from a signal handler).
3535
//
36-
// @ivoanjo: As a note, I don't think we should think of this constraint as set in stone. Since can reach into the Ruby
36+
// @ivoanjo: As a note, I don't think we should think of this constraint as set in stone. Since we can reach inside the Ruby
3737
// internals, we may be able to figure out a way of overcoming it. But it's definitely going to be hard so for now
3838
// we're considering it as a given.
3939
//

ext/datadog_profiling_native_extension/collectors_stack.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include "stack_recorder.h"
66

7-
#define MAX_FRAMES_LIMIT 10000
8-
#define MAX_FRAMES_LIMIT_AS_STRING "10000"
7+
#define MAX_FRAMES_LIMIT 3000
8+
#define MAX_FRAMES_LIMIT_AS_STRING "3000"
99

1010
typedef struct sampling_buffer sampling_buffer;
1111

ext/datadog_profiling_native_extension/collectors_thread_context.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,11 +1450,8 @@ void thread_context_collector_sample_allocation(VALUE self_instance, unsigned in
14501450

14511451
// Since this is stack allocated, be careful about moving it
14521452
ddog_CharSlice class_name;
1453-
ddog_CharSlice *optional_class_name = NULL;
14541453
char imemo_type[100];
14551454

1456-
optional_class_name = &class_name;
1457-
14581455
if (
14591456
type == RUBY_T_OBJECT ||
14601457
type == RUBY_T_CLASS ||
@@ -1510,7 +1507,7 @@ void thread_context_collector_sample_allocation(VALUE self_instance, unsigned in
15101507
class_name = ruby_vm_type; // For other weird internal things we just use the VM type
15111508
}
15121509

1513-
track_object(state->recorder_instance, new_object, sample_weight, optional_class_name);
1510+
track_object(state->recorder_instance, new_object, sample_weight, class_name);
15141511

15151512
per_thread_context *thread_context = get_or_create_context_for(current_thread, state);
15161513

@@ -1523,7 +1520,7 @@ void thread_context_collector_sample_allocation(VALUE self_instance, unsigned in
15231520
(sample_values) {.alloc_samples = sample_weight, .alloc_samples_unscaled = 1, .heap_sample = true},
15241521
INVALID_TIME, // For now we're not collecting timestamps for allocation events, as per profiling team internal discussions
15251522
&ruby_vm_type,
1526-
optional_class_name,
1523+
&class_name,
15271524
/* is_gvl_waiting_state: */ false,
15281525
/* is_safe_to_allocate_objects: */ false // Not safe to allocate further inside the NEWOBJ tracepoint
15291526
);

0 commit comments

Comments
 (0)