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
3 changes: 0 additions & 3 deletions CppCheckSuppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@
// config of cpp checks needs more includes
missingInclude

// Ignore warnings from third parties
*:*/third_party/*

// Ignore Lex and Yacc defects
*:*/event_parser/*
18 changes: 9 additions & 9 deletions app/base-env-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.17.2
FROM alpine:3.18.0
ARG COMPILER="gcc"
ENV CC=gcc
ENV CXX=g++
Expand Down Expand Up @@ -56,11 +56,11 @@ SHELL ["/bin/bash", "-c"]
# Provides the llvm-symbolizer (better debug information in case of sanitizer issue)
ENV PATH="/usr/lib/llvm-${CLANG_VERSION}/bin/:$PATH"

### Alpine has cmake 3.23
### Alpine has newer cmake

# Ninja build 1.10.2
RUN VERSION="1.10.2" \
&& SHA256="ce35865411f0490368a8fc383f29071de6690cbadc27704734978221f25e2bed" \
# Ninja build 1.11.1
RUN VERSION="1.11.1" \
&& SHA256="31747ae633213f1eda3842686f83c2aa1412e0f5691d1c14dbbcc67fe7400cea" \
&& curl -LO https://github.com/ninja-build/ninja/archive/refs/tags/v${VERSION}.tar.gz \
&& (printf "${SHA256} v${VERSION}.tar.gz" | sha256sum -c) \
&& tar xvfz v${VERSION}.tar.gz \
Expand All @@ -73,9 +73,9 @@ RUN VERSION="1.10.2" \
## Alpine has cppcheck 2.8.1-r0

# C++ json library (used for test purpose)
RUN VERSION="3.10.5" \
RUN VERSION="3.11.2" \
&& curl -LO https://github.com/nlohmann/json/releases/download/v${VERSION}/json.tar.xz \
&& SHA256="344be97b757a36c5b180f1c8162f6c5f6ebd760b117f6e64b77866e97b217280" \
&& SHA256="8c4b26bf4b422252e13f332bc5e388ec0ab5c3443d24399acb675e68278d341f" \
&& (printf "${SHA256} json.tar.xz" | sha256sum -c) \
&& tar xf json.tar.xz \
&& cd json \
Expand All @@ -86,9 +86,9 @@ RUN VERSION="3.10.5" \
&& rm -rf json json.tar.xz

# Google benchmark
RUN VERSION="1.6.1" \
RUN VERSION="1.8.2" \
&& curl -LO "https://github.com/google/benchmark/archive/refs/tags/v${VERSION}.tar.gz" \
&& SHA256="6132883bc8c9b0df5375b16ab520fac1a85dc9e4cf5be59480448ece74b278d4" \
&& SHA256="2aab2980d0376137f969d92848fbb68216abb07633034534fc8c65cc4e7a0e93" \
&& (printf "${SHA256} v${VERSION}.tar.gz" | sha256sum -c) \
&& tar xf v${VERSION}.tar.gz \
&& cd benchmark-${VERSION} \
Expand Down
39 changes: 16 additions & 23 deletions app/base-env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ FROM ubuntu:${UBUNTU_VERSION}.04 as base
ARG UBUNTU_VERSION
ENV OS_IDENTIFIER="UB${UBUNTU_VERSION}"

FROM base AS base-23
ENV GCC_VERSION=13
ENV CLANG_VERSION=16

FROM base AS base-22
ENV GCC_VERSION=12
ENV CLANG_VERSION=15
Expand Down Expand Up @@ -62,6 +66,7 @@ RUN apt-get update \
ssh-client \
subversion \
unzip \
valgrind \
wget \
zlib1g-dev

Expand Down Expand Up @@ -91,11 +96,11 @@ RUN VERSION="3.22.2" \
&& tar --no-same-owner -C /usr/local --strip-components=1 -xf ${TAR_NAME} \
&& rm ${TAR_NAME}

# Ninja build 1.10.2
RUN VERSION="1.10.2" \
&& SHA256="ce35865411f0490368a8fc383f29071de6690cbadc27704734978221f25e2bed" \
# Ninja build 1.11.1
RUN VERSION="1.11.1" \
&& SHA256="31747ae633213f1eda3842686f83c2aa1412e0f5691d1c14dbbcc67fe7400cea" \
&& curl -LO https://github.com/ninja-build/ninja/archive/refs/tags/v${VERSION}.tar.gz \
&& (printf "${SHA256} v${VERSION}.tar.gz" | sha256sum --check --strict --status) \
&& (printf "${SHA256} v${VERSION}.tar.gz" | sha256sum -c) \
&& tar xvfz v${VERSION}.tar.gz \
&& cd ninja-${VERSION} \
&& cmake -Bbuild-cmake \
Expand Down Expand Up @@ -146,36 +151,24 @@ RUN VERSION="3.10.5" \
# Command line includes a change
# - in python which is missing on ubuntu 20.04, use python 3 instead
# - in options_test.cc to fix a clang build issue (fixed after 1.7.1)
RUN VERSION="1.7.1" \
RUN VERSION="1.8.2" \
&& curl -LO "https://github.com/google/benchmark/archive/refs/tags/v${VERSION}.tar.gz" \
&& SHA256="6430e4092653380d9dc4ccb45a1e2dc9259d581f4866dc0759713126056bc1d7" \
&& SHA256="2aab2980d0376137f969d92848fbb68216abb07633034534fc8c65cc4e7a0e93" \
&& (printf "${SHA256} v${VERSION}.tar.gz" | sha256sum --check --strict --status) \
&& tar xf v${VERSION}.tar.gz \
&& pushd benchmark-${VERSION} \
&& { command -v python > /dev/null || { ln -s /usr/bin/python3 python && export PATH=$PWD:$PATH; }; } \
&& sed -i 's/^\s*size_t actual_iterations = 0;\s*$/ for (auto _ : state) {}/' ./test/options_test.cc \
&& sed -i 's/^\s*for (auto _ : state) ++actual_iterations;\s*$//' ./test/options_test.cc \
&& cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_USE_BUNDLED_GTEST=OFF -GNinja -S . -B "build" \
&& cmake --build "build" --target install \
&& popd \
&& rm -rf benchmark-${VERSION} v${VERSION}.tar.gz

# Valgrind with dwarf 5 support
RUN VERSION="3.21.0" \
&& curl -LO "https://sourceware.org/pub/valgrind/valgrind-${VERSION}.tar.bz2" \
&& SHA1="817d769743d278b5d07526e85115082054e9bf9c" \
&& (printf "${SHA1} valgrind-${VERSION}.tar.bz2" | sha1sum --check --strict --status) \
&& tar xvf valgrind-${VERSION}.tar.bz2 \
&& pushd valgrind-${VERSION} \
&& ./configure --prefix /usr/local \
&& make -j 4 \
&& make install \
&& valgrind --version \
&& popd \
&& rm -Rf valgrind-${VERSION} valgrind-${VERSION}.tar.bz2

# Install cmake_format
RUN pip3 install cmake_format
RUN if [ "$UBUNTU_VERSION" -eq 23 ]; then \
pip3 install --break-system-packages cmake-format; \
else \
pip3 install cmake-format; \
fi

# A specific user is required to get access to perf event ressources.
# This enables unit testing using perf-event ressources
Expand Down
2 changes: 1 addition & 1 deletion include/lib/allocation_tracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct TrackerThreadLocalState {
int64_t remaining_bytes; // remaining allocation bytes until next sample
bool remaining_bytes_initialized; // false if remaining_bytes is not
// initialized
ddprof::span<const byte> stack_bounds;
ddprof::span<const std::byte> stack_bounds;
pid_t tid; // cache of tid

bool reentry_guard; // prevent reentry in AllocationTracker (eg. when
Expand Down
4 changes: 3 additions & 1 deletion include/lib/saveregisters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "perf_archmap.hpp"
#include "span.hpp"

#include <cstdint>

#if defined(__x86_64__)

DDPROF_NOINLINE __attribute__((naked)) void
save_registers(ddprof::span<uint64_t, PERF_REGS_COUNT>);
save_registers(ddprof::span<std::uint64_t, PERF_REGS_COUNT>);

#elif defined(__aarch64__)

Expand Down
2 changes: 1 addition & 1 deletion include/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#if __cpp_lib_span
#if __cplusplus >= 202002L

# include <span>

Expand Down
7 changes: 3 additions & 4 deletions include/tempfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

namespace ddprof {
DDRes get_or_create_temp_file(std::string_view prefix,
ddprof::span<const std::byte> data, mode_t mode,
span<const std::byte> data, mode_t mode,
std::string &path);

DDRes create_temp_file(std::string_view prefix,
ddprof::span<const std::byte> data, mode_t mode,
std::string &path);
DDRes create_temp_file(std::string_view prefix, span<const std::byte> data,
mode_t mode, std::string &path);
} // namespace ddprof
7 changes: 7 additions & 0 deletions src/ddprof_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
// developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present
// Datadog, Inc.

// gcc 13 issue - remove FORTIFY_SOURCE
//clang-format off
// /usr/include/fortify/stdio.h:73:28: error: inlining failed in call to 'always_inline' 'vsnprintf': function body can be overwritten at link time
// 73 | _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
//clang-format on
#undef _FORTIFY_SOURCE

#include "ddprof_cli.hpp"

#include "CLI/CLI11.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/ddprof_cpumask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "ddprof_cpumask.hpp"

#include <cstdint>
#include <dirent.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
Expand Down
7 changes: 3 additions & 4 deletions src/exe/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ static DDRes get_library_path(TempFileHolder &libdd_profiling_path,
}

if (profiling_path.empty()) {
DDRES_CHECK_FWD(get_or_create_temp_file(
DDRES_CHECK_FWD(ddprof::get_or_create_temp_file(
k_libdd_profiling_embedded_name,
ddprof::as_bytes(ddprof::span{_binary_libdd_profiling_embedded_so_start,
_binary_libdd_profiling_embedded_so_end}),
0644, profiling_path));
mode_t(0644), profiling_path));
libdd_profiling_path = TempFileHolder{profiling_path, false};
} else {
libdd_profiling_path = TempFileHolder{profiling_path, false};
}

#ifdef DDPROF_USE_LOADER
if (loader_path.empty()) {
DDRES_CHECK_FWD(get_or_create_temp_file(
DDRES_CHECK_FWD(ddprof::get_or_create_temp_file(
k_libdd_loader_name,
ddprof::as_bytes(ddprof::span{_binary_libdd_loader_so_start,
_binary_libdd_loader_so_end}),
Expand All @@ -151,7 +151,6 @@ static DDRes get_library_path(TempFileHolder &libdd_profiling_path,
#else
(void)libdd_loader_path;
#endif

return {};
}

Expand Down
7 changes: 4 additions & 3 deletions src/lib/savecontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ DDPROF_NOINLINE ddprof::span<const std::byte> retrieve_stack_bounds() {
static DDPROF_NO_SANITIZER_ADDRESS size_t
save_stack(ddprof::span<const std::byte> stack_bounds,
const std::byte *stack_ptr, ddprof::span<std::byte> buffer) {
const std::byte *stack_ptr_end = (stack_bounds.data() + stack_bounds.size());
// Safety check to ensure we are not in a fiber using a different stack
if (!(stack_ptr >= stack_bounds.begin() && stack_ptr < stack_bounds.end())) {
if (!(stack_ptr >= stack_bounds.data() && stack_ptr < stack_ptr_end)) {
return 0;
}
// take the min of current stack size and requested stack sample size~
int64_t saved_stack_size = std::min(static_cast<intptr_t>(buffer.size()),
stack_bounds.end() - stack_ptr);
int64_t saved_stack_size =
std::min(static_cast<intptr_t>(buffer.size()), stack_ptr_end - stack_ptr);

if (saved_stack_size <= 0) {
return 0;
Expand Down
7 changes: 3 additions & 4 deletions src/tempfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace ddprof {

DDRes get_or_create_temp_file(std::string_view prefix,
ddprof::span<const std::byte> data, mode_t mode,
span<const std::byte> data, mode_t mode,
std::string &path) {
unsigned char digest[20];
char str_digest[41];
Expand All @@ -45,9 +45,8 @@ DDRes get_or_create_temp_file(std::string_view prefix,
return {};
}

DDRes create_temp_file(std::string_view prefix,
ddprof::span<const std::byte> data, mode_t mode,
std::string &path) {
DDRes create_temp_file(std::string_view prefix, span<const std::byte> data,
mode_t mode, std::string &path) {
std::error_code ec;
auto template_str =
std::string{std::filesystem::temp_directory_path(ec) / prefix} +
Expand Down