Skip to content
Merged
5 changes: 3 additions & 2 deletions ddprof-lib/src/main/cpp/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Arguments {
_wall(-1),
_wall_collapsing(false),
_wall_threads_per_tick(DEFAULT_WALL_THREADS_PER_TICK),
_wallclock_sampler(ASGCT),
_memory(-1),
_record_allocations(false),
_record_liveness(false),
Expand All @@ -220,10 +221,10 @@ class Arguments {
_clock(CLK_DEFAULT),
_jfr_options(0),
_context_attributes({}),
_wallclock_sampler(ASGCT),
_lightweight(false),
_enable_method_cleanup(true),
_remote_symbolication(false) {}
_remote_symbolication(false) { }


~Arguments();

Expand Down
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class RecordingBuffer : public Buffer {
public:
RecordingBuffer() : Buffer() {
new (_data + sizeof(_data)) char[sizeof(_buf)];
memset(_buf, 0, _limit);
memset(_buf, 0, _limit);
}

int limit() const override { return _limit; }
Expand Down
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/callTraceHashTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void init_overflow_trace() {
CallTraceHashTable::_overflow_trace.frames[0] = {BCI_ERROR, LP64_ONLY(0 COMMA) (jmethodID)"storage_overflow"};
}

CallTraceHashTable::CallTraceHashTable() : _allocator(CALL_TRACE_CHUNK), _instance_id(0), _parent_storage(nullptr) {
CallTraceHashTable::CallTraceHashTable() : _instance_id(0), _parent_storage(nullptr), _allocator(CALL_TRACE_CHUNK) {
// Instance ID will be set externally via setInstanceId()

// Start with initial capacity, allowing expansion as needed
Expand Down
6 changes: 0 additions & 6 deletions ddprof-lib/src/main/cpp/callTraceStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ class CallTraceStorage {
std::unordered_set<CallTrace*> _traces_buffer; // All traces for JFR processing
std::unordered_set<u64> _preserve_set_buffer; // Preserve set for current cycle


private:




public:
CallTraceStorage();
~CallTraceStorage();
Expand Down
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void CodeCache::findSymbolsByPrefix(std::vector<const char *> &prefixes,
for (int i = 0; i < _count; i++) {
const char *blob_name = _blobs[i]._name;
if (blob_name != NULL) {
for (int i = 0; i < prefixes.size(); i++) {
for (size_t i = 0; i < prefixes.size(); i++) {
if (strncmp(blob_name, prefixes[i], prefix_lengths[i]) == 0) {
symbols.push_back(_blobs[i]._start);
}
Expand Down
2 changes: 2 additions & 0 deletions ddprof-lib/src/main/cpp/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Context& Contexts::initializeContextTls() {
return ctx;
}

static Context DD_EMPTY_CONTEXT = {};

Context& Contexts::get() {
ProfiledThread* thrd = ProfiledThread::currentSignalSafe();
if (thrd == nullptr || !thrd->isContextTlsInitialized()) {
Expand Down
2 changes: 0 additions & 2 deletions ddprof-lib/src/main/cpp/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class alignas(DEFAULT_CACHE_LINE_SIZE) Context {
Tag get_tag(int i) { return tags[i]; }
};

static Context DD_EMPTY_CONTEXT = {};

class Contexts {

public:
Expand Down
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const int INITIAL_PC_OFFSET = DW_LINK_REGISTER;

struct FrameDesc {
u32 loc;
int cfa;
u32 cfa;
int fp_off;
int pc_off;

Expand Down
11 changes: 6 additions & 5 deletions ddprof-lib/src/main/cpp/flightRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ void Recording::writeMetadata(Buffer *buf) {

std::vector<std::string> &strings = JfrMetadata::strings();
buf->putVar64(strings.size());
for (int i = 0; i < strings.size(); i++) {
for (size_t i = 0; i < strings.size(); i++) {
const char *string = strings[i].c_str();
int length = strlen(string);
flushIfNeeded(buf, RECORDING_BUFFER_LIMIT - length);
Expand Down Expand Up @@ -842,14 +842,14 @@ void Recording::writeElement(Buffer *buf, const Element *e) {
buf->putVar64(e->_name);

buf->putVar64(e->_attributes.size());
for (int i = 0; i < e->_attributes.size(); i++) {
for (size_t i = 0; i < e->_attributes.size(); i++) {
flushIfNeeded(buf);
buf->putVar64(e->_attributes[i]._key);
buf->putVar64(e->_attributes[i]._value);
}

buf->putVar64(e->_children.size());
for (int i = 0; i < e->_children.size(); i++) {
for (size_t i = 0; i < e->_children.size(); i++) {
flushIfNeeded(buf);
writeElement(buf, e->_children[i]);
}
Expand Down Expand Up @@ -1426,7 +1426,7 @@ void Recording::writeCounters(Buffer *buf) {
long long *counters = Counters::getCounters();
if (counters) {
std::vector<const char *> names = Counters::describeCounters();
for (int i = 0; i < names.size(); i++) {
for (size_t i = 0; i < names.size(); i++) {
int start = buf->skip(1);
buf->putVar64(T_DATADOG_COUNTER);
buf->putVar64(_start_ticks);
Expand Down Expand Up @@ -1683,10 +1683,11 @@ void FlightRecorder::stop() {
}

Error FlightRecorder::dump(const char *filename, const int length) {
assert(length >= 0);
ExclusiveLockGuard locker(&_rec_lock);
Recording* rec = _rec;
if (rec != nullptr) {
if (_filename.length() != length ||
if (_filename.length() != static_cast<size_t>(length) ||
strncmp(filename, _filename.c_str(), length) != 0) {
// if the filename to dump the recording to is specified move the current
// working file there
Expand Down
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/hotspot/vmStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ HeapUsage HeapUsage::get(bool allow_jmx) {
usage._maxSize = summary.maxSize();
}
}
if (usage._maxSize == -1 && _memory_usage_func != NULL && allow_jmx && isJMXSupported()) {
if (usage._maxSize == size_t(-1) && _memory_usage_func != NULL && allow_jmx && isJMXSupported()) {
// this path is for non-hotspot JVMs
// we need to patch the native method binding for JMX GetMemoryUsage to
// capture the native method pointer first also, it requires JMX and
Expand Down
5 changes: 4 additions & 1 deletion ddprof-lib/src/main/cpp/hotspot/vmStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class VMNMethod;
// sending SIGABRT which is uncatchable by crash protection.
// When crash protection is active the assert is redundant — any bad read will
// be caught by the SIGSEGV handler and recovered via longjmp — so we skip it.
//
// Defined at the bottom of this file after VMThread is declared so that the
// VMThread fallback path (isExceptionActive) is accessible without forward-
// declaring the full class.
inline bool crashProtectionActive();

template <typename T>
Expand Down Expand Up @@ -705,7 +709,6 @@ DECLARE(VMThread)
return *(const void***)this;
}


// This thread is considered a JavaThread if at least 2 of the selected 3 vtable entries
// match those of a known JavaThread (which is either application thread or AttachListener).
// Indexes were carefully chosen to work on OpenJDK 8 to 25, both product an debug builds.
Expand Down
5 changes: 3 additions & 2 deletions ddprof-lib/src/main/cpp/javaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,8 @@ Java_com_datadoghq_profiler_JavaProfiler_testlog(JNIEnv* env, jclass unused, jst

extern "C" DLLEXPORT void JNICALL
Java_com_datadoghq_profiler_JavaProfiler_dumpContext(JNIEnv* env, jclass unused) {
#ifdef DEBUG
Context& ctx = Contexts::get();

TEST_LOG("===> Context: tid:%lu, spanId=%lu, rootSpanId=%lu, checksum=%lu", OS::threadId(), ctx.spanId, ctx.rootSpanId, ctx.checksum);
TEST_LOG("===> Context: tid:%u, spanId=%llu, rootSpanId=%llu, checksum=%llu", OS::threadId(), ctx.spanId, ctx.rootSpanId, ctx.checksum);
#endif // DEBUG
}
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/jniHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <jni.h>

static bool jniExceptionCheck(JNIEnv *jni, bool describe = false) {
inline bool jniExceptionCheck(JNIEnv *jni, bool describe = false) {
if (jni->ExceptionCheck()) {
if (describe) {
jni->ExceptionDescribe();
Expand Down
5 changes: 3 additions & 2 deletions ddprof-lib/src/main/cpp/libraries.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Libraries {
// Get library by index (used for remote symbolication unpacking)
// Note: Parameter is uint32_t to match lib_index packing (17 bits = max 131K libraries)
CodeCache *getLibraryByIndex(uint32_t index) const {
if (index < _native_libs.count()) {
assert(_native_libs.count() >= 0);
if (index < static_cast<uint32_t>(_native_libs.count())) {
return _native_libs[index];
}
return nullptr;
Expand All @@ -43,4 +44,4 @@ class Libraries {
Libraries& operator=(const Libraries&) = delete;
};

#endif // _LIBRARIES_H
#endif // _LIBRARIES_H
4 changes: 1 addition & 3 deletions ddprof-lib/src/main/cpp/livenessTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void LivenessTracker::flush_table(std::set<int> *tracked_thread_ids) {
_table_lock.lock();

u32 sz;
for (int i = 0; i < (sz = _table_size); i++) {
for (u32 i = 0; i < (sz = _table_size); i++) {
jobject ref = env->NewLocalRef(_table[i].ref);
if (ref != nullptr) {
if (tracked_thread_ids != nullptr) {
Expand Down Expand Up @@ -208,8 +208,6 @@ void LivenessTracker::stop() {
// multiple recordings
}

static int _min(int a, int b) { return a < b ? a : b; }

Error LivenessTracker::initialize(Arguments &args) {
_enabled = args._gc_generations || args._record_liveness;

Expand Down
5 changes: 3 additions & 2 deletions ddprof-lib/src/main/cpp/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ SigAction OS::installSignalHandler(int signo, SigAction action, SigHandler handl
} else {
sa.sa_sigaction = action;
sa.sa_flags = SA_SIGINFO | SA_RESTART;
if (signo > 0 && signo < sizeof(installed_sigaction) / sizeof(installed_sigaction[0])) {
int num = sizeof(installed_sigaction) / sizeof(installed_sigaction[0]);
if (signo > 0 && signo < num) {
installed_sigaction[signo] = action;
}
}
Expand Down Expand Up @@ -345,7 +346,7 @@ bool OS::getCpuDescription(char* buf, size_t size) {
if (r <= 0) {
return false;
}
buf[r < size ? r : size - 1] = 0;
buf[static_cast<size_t>(r) < size ? r : size - 1] = 0;

char* c;
do {
Expand Down
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/otel_process_ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static otel_process_ctx_result otel_process_ctx_update(uint64_t monotonic_publis
// Step: Prepare the new payload to be published
// The payload SHOULD be ready and valid before trying to actually update the mapping.
uint32_t payload_size = 0;
char *payload;
char *payload = nullptr;
otel_process_ctx_result result = otel_process_ctx_encode_protobuf_payload(&payload, &payload_size, *data);
if (!result.success) return result;

Expand Down
4 changes: 2 additions & 2 deletions ddprof-lib/src/main/cpp/perfEvents_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static void resolvePmuEventName(const char *device, char *event, size_t size) {
}

ssize_t r = read(fd, event, size);
if (r > 0 && (r == size || event[r - 1] == '\n')) {
if (r > 0 && (size_t(r) == size || event[r - 1] == '\n')) {
Comment thread
zhengyu123 marked this conversation as resolved.
event[r - 1] = 0;
}
close(fd);
Expand All @@ -147,7 +147,7 @@ static bool setPmuConfig(const char *device, const char *param, __u64 *config,
ssize_t r = read(fd, buf, sizeof(buf));
close(fd);

if (r > 0 && r < sizeof(buf)) {
if (r > 0 && r < (int)sizeof(buf)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

r is ssize_t - should this be rather (ssize_t)sizeof(buf)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since we checked r > 0, so cast r to unsigned is safer.

if (strncmp(buf, "config:", 7) == 0) {
config[0] |= val << atoi(buf + 7);
return true;
Expand Down
5 changes: 3 additions & 2 deletions ddprof-lib/src/main/cpp/pidController.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ class PidController {
int sampling_window, double cutoff_secs)
: _target(target_per_second * sampling_window),
_proportional_gain(proportional_gain),
_integral_gain(integral_gain * sampling_window),
_derivative_gain(derivative_gain / sampling_window),
_alpha(computeAlpha(sampling_window / cutoff_secs)), _avg_error(0),
_integral_gain(integral_gain * sampling_window),
_alpha(computeAlpha(sampling_window / cutoff_secs)),
_avg_error(0),
_integral_value(0) {}

double compute(u64 input, double time_delta_seconds);
Expand Down
1 change: 0 additions & 1 deletion ddprof-lib/src/main/cpp/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Profiler *const Profiler::_instance = new Profiler();
volatile bool Profiler::_signals_initialized = false;
volatile bool Profiler::_need_JDK_8313796_workaround = true;

static void (*orig_trapHandler)(int signo, siginfo_t *siginfo, void *ucontext);
static void (*orig_segvHandler)(int signo, siginfo_t *siginfo, void *ucontext);
static void (*orig_busHandler)(int signo, siginfo_t *siginfo, void *ucontext);

Expand Down
22 changes: 12 additions & 10 deletions ddprof-lib/src/main/cpp/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,18 @@ class alignas(alignof(SpinLock)) Profiler {

public:
Profiler()
: _state(NEW), _class_unload_hook_trap(2),
_notify_class_unloaded_func(NULL), _thread_filter(), _call_trace_storage(), _jfr(),
_start_time(0), _epoch(0), _timer_id(NULL),
_max_stack_depth(0), _safe_mode(0), _thread_events_state(JVMTI_DISABLE),
_libs(Libraries::instance()), _stubs_lock(), _runtime_stubs("[stubs]"),
_call_stub_begin(NULL), _call_stub_end(NULL), _dlopen_entry(NULL),
_num_context_attributes(0), _class_map(1), _string_label_map(2),
_context_value_map(3), _cpu_engine(), _alloc_engine(), _event_mask(0),
_stop_time(), _total_samples(0), _failures(), _cstack(CSTACK_NO),
_omit_stacktraces(false) {
: _state_lock(), _state(NEW), _class_unload_hook_trap(2),
_notify_class_unloaded_func(NULL), _thread_info(), _class_map(1),
_string_label_map(2), _context_value_map(3), _thread_filter(),
_call_trace_storage(), _jfr(), _cpu_engine(NULL), _wall_engine(NULL),
_alloc_engine(NULL), _event_mask(0),
_start_time(0), _stop_time(0), _epoch(0), _timer_id(NULL),
_total_samples(0), _failures(), _class_map_lock(),
_max_stack_depth(0), _features(), _safe_mode(0), _cstack(CSTACK_NO),
_thread_events_state(JVMTI_DISABLE), _libs(Libraries::instance()), _stubs_lock(),
_runtime_stubs("[stubs]"), _call_stub_begin(NULL), _call_stub_end(NULL),
_num_context_attributes(0), _omit_stacktraces(false), _remote_symbolication(false),
_dlopen_entry(NULL) {

for (int i = 0; i < CONCURRENCY_LEVEL; i++) {
_calltrace_buffer[i] = NULL;
Expand Down
5 changes: 3 additions & 2 deletions ddprof-lib/src/main/cpp/reservoirSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class ReservoirSampler {

std::vector<T>& sample(const std::vector<T> &input) {
_reservoir.clear();
for (int i = 0; i < _size && i < input.size(); i++) {
for (int i = 0; i < _size && i < (int)input.size(); i++) {
_reservoir.push_back(input[i]);
}
double weight = exp(log(_uniform(_generator)) / _size);
int target = _size + (int) (log(_uniform(_generator)) / log(1 - weight));
while (target < input.size()) {
assert(target >= 0);
while (target < (int)input.size()) {
_reservoir[_random_index(_generator)] = input[target];
weight *= exp(log(_uniform(_generator)) / _size);
target += (int) (log(_uniform(_generator)) / log(1 - weight));
Expand Down
12 changes: 2 additions & 10 deletions ddprof-lib/src/main/cpp/symbols_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,6 @@ static void ensure_main_phdr_initialized() {
pthread_once(&_main_phdr_once, init_main_phdr_once);
}

static Range range_for_fbase(void* fbase) {
Range r = {0, 0};
if (!fbase) return r;
UnifiedCtx ctx = {fbase, &r, NULL, NULL, NULL, NULL, NULL};
dl_iterate_phdr(&unified_phdr_cb, &ctx);
return r;
}

static void init_lib_ranges_once() {
if (g_lib_ranges_inited) return;
g_lib_ranges_inited = true;
Expand Down Expand Up @@ -666,13 +658,13 @@ const char* ElfParser::getDebuginfodCache() {
const char* env_vars[] = {"DEBUGINFOD_CACHE_PATH", "XDG_CACHE_HOME", "HOME"};
const char* suffixes[] = {"/", "debuginfod_client/", ".cache/debuginfod_client/"};

for (int i = 0; i < sizeof(env_vars) / sizeof(env_vars[0]); i++) {
for (size_t i = 0; i < sizeof(env_vars) / sizeof(env_vars[0]); i++) {
const char* env_val = getenv(env_vars[i]);
if (!env_val || !env_val[0]) {
continue;
}

if (snprintf(_debuginfod_cache_buf, sizeof(_debuginfod_cache_buf), "%s/%s", env_val, suffixes[i]) < sizeof(_debuginfod_cache_buf)) {
if (snprintf(_debuginfod_cache_buf, sizeof(_debuginfod_cache_buf), "%s/%s", env_val, suffixes[i]) < static_cast<int>(sizeof(_debuginfod_cache_buf))) {
return _debuginfod_cache_buf;
}
}
Expand Down
1 change: 1 addition & 0 deletions ddprof-lib/src/main/cpp/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ProfiledThread : public ThreadLocalData {

void releaseFromBuffer();

virtual ~ProfiledThread() { }
public:
static ProfiledThread *forTid(int tid) { return new ProfiledThread(-1, tid); }
static ProfiledThread *inBuffer(int buffer_pos) {
Expand Down
4 changes: 2 additions & 2 deletions ddprof-lib/src/main/cpp/tsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static inline u64 rdtsc() {
}

// Returns true if this CPU has a good ("invariant") timestamp counter
static bool cpuHasGoodTimestampCounter() {
inline bool cpuHasGoodTimestampCounter() {
unsigned int eax, ebx, ecx, edx;

// Check if CPUID supports misc feature flags
Expand All @@ -59,7 +59,7 @@ static inline u64 rdtsc() {
return value;
}

static bool cpuHasGoodTimestampCounter() {
inline bool cpuHasGoodTimestampCounter() {
// AARCH64 always has a good timestamp counter.
return true;
}
Expand Down
Loading
Loading