Perfetto tracing in load tester

This commit is contained in:
2025-08-20 11:36:02 -04:00
parent dac3e5dc59
commit 0e885f1ff1
2 changed files with 29 additions and 1 deletions

View File

@@ -13,6 +13,8 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra")
set(CMAKE_CXX_FLAGS_RELEASE
"-g -O3 -Wall -Wextra -DNDEBUG -fno-omit-frame-pointer")
add_subdirectory(third_party)
find_package(Threads REQUIRED)
include(FetchContent)
@@ -202,7 +204,7 @@ target_include_directories(debug_arena PRIVATE src)
# Load tester
add_executable(load_tester tools/load_tester.cpp)
target_link_libraries(load_tester Threads::Threads llhttp_static)
target_link_libraries(load_tester Threads::Threads llhttp_static perfetto)
add_test(NAME arena_allocator_tests COMMAND test_arena_allocator)
add_test(NAME commit_request_tests COMMAND test_commit_request)

View File

@@ -27,6 +27,21 @@
#define __has_feature(x) 0
#endif
#define ENABLE_PERFETTO 1
#if ENABLE_PERFETTO
#include <perfetto.h>
#else
#define PERFETTO_DEFINE_CATEGORIES(...)
#define PERFETTO_TRACK_EVENT_STATIC_STORAGE(...)
#define TRACE_EVENT(...)
#endif
PERFETTO_DEFINE_CATEGORIES(
perfetto::Category("network").SetDescription("Network"));
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
namespace {
double now() {
@@ -249,6 +264,8 @@ struct Connection {
request = request.substr(w, request.size() - w);
if (request.empty()) {
++requestsSent;
TRACE_EVENT("network", "send request",
perfetto::Flow::Global(currentRequestId));
if (requestsSent == g_config.requests_per_connection) {
return true;
}
@@ -290,6 +307,8 @@ private:
}
int on_message_complete() {
TRACE_EVENT("network", "receive response",
perfetto::Flow::Global(responseId));
responseId = 0;
++responsesReceived;
initRequest();
@@ -455,6 +474,13 @@ void parse_args(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
#if ENABLE_PERFETTO
perfetto::TracingInitArgs args;
args.backends |= perfetto::kSystemBackend;
perfetto::Tracing::Initialize(args);
perfetto::TrackEvent::Register();
#endif
parse_args(argc, argv);
// Print configuration