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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ if(MSVC)
endif()
endif()

option(ENABLE_PROFILING "Use libprofiler for profiling tests" OFF)

include(Dependencies)

if(MUST_BUILD_TOXAV)
Expand Down
4 changes: 4 additions & 0 deletions auto_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function(auto_test target)
elseif(TARGET Threads::Threads)
target_link_libraries(auto_${target}_test PRIVATE Threads::Threads)
endif()
if(ENABLE_PROFILING)
target_link_libraries(auto_${target}_test PRIVATE PkgConfig::LIBPROFILER)
target_compile_definitions(auto_${target}_test PRIVATE "ENABLE_PROFILING")
endif()
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
# add the source dir as environment variable, so the testdata can be found
Expand Down
12 changes: 12 additions & 0 deletions auto_tests/send_message_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <stdint.h>
#include <string.h>

#ifdef ENABLE_PROFILING
#include <gperftools/profiler.h>
#endif

typedef struct State {
bool message_received;
} State;
Expand Down Expand Up @@ -63,6 +67,10 @@ int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

#ifdef ENABLE_PROFILING
ProfilerStart("send_message_test.prof");
#endif

struct Tox_Options *tox_options = tox_options_new(nullptr);
ck_assert(tox_options != nullptr);

Expand All @@ -76,5 +84,9 @@ int main(void)

tox_options_free(tox_options);

#ifdef ENABLE_PROFILING
ProfilerStop();
#endif

return 0;
}
5 changes: 5 additions & 0 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ endif()

# For tox-bootstrapd.
pkg_search_module(LIBCONFIG libconfig IMPORTED_TARGET)

# For profiling.
if(ENABLE_PROFILING)
pkg_search_module(LIBPROFILER libprofiler IMPORTED_TARGET REQUIRED)
endif()
34 changes: 34 additions & 0 deletions other/docker/prof/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM toxchat/c-toxcore:sources AS src
FROM golang:1.18-alpine AS build

ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8 \
LC_CTYPE=en_US.UTF-8 \
LC_ALL=en_US.UTF-8

RUN ["go", "install", "github.com/google/pprof@latest"]
RUN ["apk", "add", "--no-cache", \
"--repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/", \
"binutils", \
"clang", \
"cmake", \
"gcc", \
"gperftools-dev", \
"graphviz", \
"libsodium-dev", \
"libvpx-dev", \
"linux-headers", \
"musl-dev", \
"opus-dev", \
"pkgconfig", \
"samurai"]
WORKDIR /work
COPY --from=src /src/ /work/
RUN cmake -B_build -H. -GNinja -DAUTOTEST=ON -DENABLE_SHARED=OFF -DENABLE_PROFILING=ON -DCMAKE_EXE_LINKER_FLAGS="-dynamic"
RUN cmake --build _build
RUN CPUPROFILE_FREQUENCY=4000 \
CPUPROFILE=auto_test.prof \
_build/auto_tests/auto_send_message_test

ENV PPROF_BINARY_PATH=/work/_build/auto_tests
CMD ["pprof", "-http", "0.0.0.0:80", "_build/auto_tests/auto_send_message_test", "auto_test.prof"]
7 changes: 7 additions & 0 deletions other/docker/prof/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -eux

docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
docker build -t toxchat/c-toxcore:prof -f other/docker/prof/Dockerfile .
docker run --name toxcore-prof --rm -it -p "28192:80" toxchat/c-toxcore:prof
Loading