Skip to content

Commit 19db45e

Browse files
committed
wip
1 parent 5e6fc62 commit 19db45e

File tree

7 files changed

+12
-19
lines changed

7 files changed

+12
-19
lines changed

ext/datadog_profiling_native_extension/ruby_helpers.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,19 @@ void _raise_native_error(VALUE native_exception_class, const char *detailed_mess
4949
rb_exc_raise(exception);
5050
}
5151

52+
#define MAX_RAISE_MESSAGE_SIZE 256
53+
5254
// Use `raise_error` the macro instead, as it provides additional argument checks.
5355
void _raise_error(VALUE native_exception_class, const char *fmt, ...) {
5456
va_list args;
5557
va_start(args, fmt);
56-
VALUE formatted_msg = rb_vsprintf(fmt, args);
58+
char formatted_msg[MAX_RAISE_MESSAGE_SIZE];
59+
vsnprintf(formatted_msg, MAX_RAISE_MESSAGE_SIZE, fmt, args);
5760
va_end(args);
5861

59-
_raise_native_error(native_exception_class, fmt, formatted_msg);
62+
_raise_native_error(native_exception_class, formatted_msg, rb_str_new_cstr(fmt));
6063
}
6164

62-
#define MAX_RAISE_MESSAGE_SIZE 256
63-
6465
typedef struct {
6566
VALUE exception_class;
6667
char exception_message[MAX_RAISE_MESSAGE_SIZE];

ext/datadog_profiling_native_extension/setup_signal_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void install_sigprof_signal_handler_internal(
3838
sigemptyset(&signal_handler_config.sa_mask);
3939

4040
if (sigaction(SIGPROF, &signal_handler_config, &existing_signal_handler_config) != 0) {
41-
rb_exc_raise(rb_syserr_new_str(errno, rb_sprintf("Could not install profiling signal handler (%s)", handler_pretty_name)));
41+
raise_syserr(errno, true, "Could not install profiling signal handler", __FILE__, __LINE__, handler_pretty_name);
4242
}
4343

4444
// Because signal handler functions are global, let's check if we're not stepping on someone else's toes.

lib/datadog/profiling.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ class NativeTypeError < TypeError
101101
prepend NativeError
102102
end
103103

104-
class NativeSystemCallError < SystemCallError
105-
prepend NativeError
106-
end
107-
108104
private_class_method def self.replace_noop_allocation_count
109105
class << self
110106
remove_method :allocation_count

lib/datadog/profiling/stack_recorder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def serialize!
8888
else
8989
error_message = result
9090

91-
raise NativeRuntimeError.new("Failed to serialize profiling data", "Failed to serialize profiling data: #{error_message}")
91+
raise "Failed to serialize profiling data: #{error_message}"
9292
end
9393
end
9494

spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@
200200

201201
exception = try_wait_until(backoff: 0.01) { cpu_and_wall_time_worker.send(:failure_exception) }
202202

203-
expect(exception.message).to include "pre-existing SIGPROF"
204-
expect(exception.telemetry_message).to eq("Could not install profiling signal handler (%s): There's a pre-existing SIGPROF signal handler")
203+
expect(exception.message).to include "(empty_signal_handler): There's a pre-existing SIGPROF"
204+
expect(exception.telemetry_message).to include "There's a pre-existing SIGPROF"
205+
expect(exception.telemetry_message).to_not include "empty_signal_handler"
205206
end
206207

207208
it "leaves the existing signal handler in place" do

spec/datadog/profiling/native_extension_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
.to raise_native_error(Datadog::Profiling::NativeRuntimeError, "this is a test", "this is a test")
1717
end
1818

19-
it "accepts printf-style string formatting" do
19+
it "on printf-style, only report the fixed string for telemetry" do
2020
expect { described_class::Testing._native_grab_gvl_and_raise(Datadog::Profiling::NativeRuntimeError, "divided zero by %d", 42, true) }
2121
.to raise_native_error(Datadog::Profiling::NativeRuntimeError, "divided zero by 42", "divided zero by %d")
2222
end

spec/datadog/profiling/stack_recorder_spec.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,7 @@ def sample_and_clear
934934
context "when serialization fails" do
935935
before { expect(described_class).to receive(:_native_serialize).and_return([:error, "test error message"]) }
936936

937-
it {
938-
expect { serialize! }.to raise_error(Datadog::Profiling::NativeRuntimeError) do |error|
939-
expect(error.message).to include('test error message')
940-
expect(error.telemetry_message).to eq('Failed to serialize profiling data')
941-
end
942-
}
937+
it { expect { serialize! }.to raise_error(RuntimeError, /test error message/) }
943938
end
944939
end
945940

0 commit comments

Comments
 (0)