Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Datadog::Uploader::export_to_file(ddog_prof_EncodedProfile& encoded, std::string
ddog_Error_drop(&bytes_res.err);
return false;
}
out.write(reinterpret_cast<const char*>(bytes_res.ok.ptr), bytes_res.ok.len);
out.write(reinterpret_cast<const char*>(bytes_res.ok.ptr), static_cast<std::streamsize>(bytes_res.ok.len));
if (out.fail()) {
std::cerr << "Error writing to output file " << pprof_filename << ": " << strerror(errno) << std::endl;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ class GreenletInfo
{
}

int unwind(EchionSampler& echion, PyObject*, PyThreadState*, FrameStack&);
void unwind(EchionSampler& echion, PyObject*, PyThreadState*, FrameStack&);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#pragma once

typedef unsigned long microsecond_t;
#include <cstdint>

typedef int64_t microsecond_t;

#define TS_TO_MICROSECOND(ts) ((ts).tv_sec * 1e6 + (ts).tv_nsec / 1e3)
#define TV_TO_MICROSECOND(tv) ((tv).seconds * 1e6 + (tv).microseconds)
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class StackRenderer
void render_task_begin(const std::string& task_name, bool on_cpu);
void render_stack_begin();
void render_frame(Frame& frame);
void render_cpu_time(uint64_t cpu_time_us);
void render_cpu_time(microsecond_t cpu_time_us);
void render_stack_end();

// Clear caches after fork to avoid using stale interned string/function IDs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ safe_memcpy(void* dst, const void* src, size_t n)

// Copy in page-bounded chunks (at most one fault per bad page).
while (rem) {
safe_memcpy_return_t to_src_pg =
page_size - (static_cast<uintptr_t>(reinterpret_cast<uintptr_t>(s)) & (page_size - 1));
safe_memcpy_return_t to_dst_pg =
page_size - (static_cast<uintptr_t>(reinterpret_cast<uintptr_t>(d)) & (page_size - 1));
// Values are always <= page_size, so the unsigned-to-signed narrowing is safe.
safe_memcpy_return_t to_src_pg = static_cast<safe_memcpy_return_t>(
page_size - (static_cast<uintptr_t>(reinterpret_cast<uintptr_t>(s)) & (page_size - 1)));
safe_memcpy_return_t to_dst_pg = static_cast<safe_memcpy_return_t>(
page_size - (static_cast<uintptr_t>(reinterpret_cast<uintptr_t>(d)) & (page_size - 1)));
safe_memcpy_return_t chunk = std::min(rem, std::min(to_src_pg, to_dst_pg));

// Optional early probe to fault before entering large memcpy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Frame::read(EchionSampler& echion, PyObject* frame_addr, PyObject** prev_addr)
(static_cast<int>(
(frame_addr->instr_ptr - 1 -
reinterpret_cast<_Py_CODEUNIT*>((reinterpret_cast<PyCodeObject*>(frame_addr->f_executable)))))) -
offsetof(PyCodeObject, co_code_adaptive) / sizeof(_Py_CODEUNIT);
static_cast<int>(offsetof(PyCodeObject, co_code_adaptive) / sizeof(_Py_CODEUNIT));
auto maybe_frame = Frame::get(echion, reinterpret_cast<PyCodeObject*>(frame_addr->f_executable), lasti);
if (!maybe_frame) {
return ErrorKind::FrameError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <echion/echion_sampler.h>

int
void
GreenletInfo::unwind(EchionSampler& echion, PyObject* cur_frame, PyThreadState* tstate, FrameStack& stack)
{
PyObject* frame_addr = NULL;
Expand All @@ -26,10 +26,7 @@ GreenletInfo::unwind(EchionSampler& echion, PyObject* cur_frame, PyThreadState*
#else // Python < 3.11
frame_addr = cur_frame == Py_None ? reinterpret_cast<PyObject*>(tstate->frame) : cur_frame;
#endif
auto count = unwind_frame(echion, frame_addr, stack);
unwind_frame(echion, frame_addr, stack);

stack.push_back(Frame::get(echion, name));

return count + 1; // We add an extra count for the frame with the greenlet
// name.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MirrorSet::create(PyObject* set_addr)
}

auto size = set.mask + 1;
ssize_t table_size = size * sizeof(setentry);
auto table_size = size * static_cast<ssize_t>(sizeof(setentry));
if (table_size < 0 || table_size > MAX_MIRROR_SIZE) {
return ErrorKind::MirrorError;
}
Expand Down
8 changes: 4 additions & 4 deletions ddtrace/internal/datadog/profiling/stack/src/echion/vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ VmReader::create(size_t sz)
unlink(tmpfile.data());

// Make sure we have enough size
if (ftruncate(fd, sz) == -1) {
if (ftruncate(fd, static_cast<off_t>(sz)) == -1) {
continue;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ VmReader::safe_copy(pid_t process_id,

// Check to see if we need to resize the buffer
if (remote_iov[0].iov_len > sz) {
if (ftruncate(fd, remote_iov[0].iov_len) == -1) {
if (ftruncate(fd, static_cast<off_t>(remote_iov[0].iov_len)) == -1) {
return 0;
} else {
void* tmp = mremap(buffer, sz, remote_iov[0].iov_len, MREMAP_MAYMOVE);
Expand All @@ -121,7 +121,7 @@ VmReader::safe_copy(pid_t process_id,
}
}

ssize_t ret = pwritev(fd, remote_iov, riovcnt, 0);
ssize_t ret = pwritev(fd, remote_iov, static_cast<int>(riovcnt), 0);
if (ret == -1) {
return ret;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ copy_memory(proc_ref_t proc_ref, const void* addr, ssize_t len, void* buf)

// Early exit on zero page
if (reinterpret_cast<uintptr_t>(addr) < 4096) {
return result;
return static_cast<int>(result);
}

#if defined PL_LINUX
Expand Down
3 changes: 2 additions & 1 deletion ddtrace/internal/datadog/profiling/stack/src/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ Sampler::adapt_sampling_interval()
info.system_time.seconds * 1e6 + info.system_time.microseconds);
#endif
auto sampler_thread_delta = static_cast<double>(new_sampler_thread_count - sampler_thread_count);
auto process_delta = static_cast<double>(new_process_count - process_count - sampler_thread_delta);
auto process_delta =
static_cast<double>(new_process_count) - static_cast<double>(process_count) - sampler_thread_delta;
if (process_delta <= 0) {
process_delta = 1; // Avoid division by zero or negative values
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace Datadog;
void
StackRenderer::render_thread_begin(PyThreadState* tstate,
std::string_view name,
microsecond_t wall_time_us,
int64_t wall_time_us,
uintptr_t thread_id,
unsigned long native_id)
{
Expand Down Expand Up @@ -47,7 +47,7 @@ StackRenderer::render_thread_begin(PyThreadState* tstate,
thread_state.native_id = native_id;
thread_state.name = std::string(name);
thread_state.now_time_ns = now_ns;
thread_state.wall_time_ns = 1000LL * wall_time_us;
thread_state.wall_time_ns = 1000 * wall_time_us;
thread_state.cpu_time_ns = 0; // Walltime samples are guaranteed, but CPU times are not. Initialize to 0
// since we don't know if we'll get a CPU time here.

Expand Down Expand Up @@ -215,7 +215,7 @@ StackRenderer::render_frame(Frame& frame)
}

void
StackRenderer::render_cpu_time(uint64_t cpu_time_us)
StackRenderer::render_cpu_time(microsecond_t cpu_time_us)
{
if (sample == nullptr) {
std::cerr << "Received a CPU time without sample storage. Some profiling data has been lost." << std::endl;
Expand All @@ -224,7 +224,7 @@ StackRenderer::render_cpu_time(uint64_t cpu_time_us)

// TODO - it's absolutely false that thread-level CPU time is task time. This needs to be normalized
// to the task level, but for now just keep it because this is how the v1 sampler works
thread_state.cpu_time_ns = 1000LL * cpu_time_us;
thread_state.cpu_time_ns = 1000 * cpu_time_us;
sample->push_cputime(thread_state.cpu_time_ns, 1);
}

Expand Down
Loading