Skip to content

Commit cffbc27

Browse files
committed
feat: Add a network profiling TUI.
1 parent b6f5b9f commit cffbc27

110 files changed

Lines changed: 7207 additions & 142 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
ca-certificates
7575
clang
7676
cmake
77+
curl
7778
git
7879
libbenchmark-dev
7980
libconfig-dev
@@ -84,7 +85,11 @@ jobs:
8485
libvpx-dev
8586
llvm-dev
8687
ninja-build
87-
pkg-config
88+
nlohmann-json3-dev
89+
pkg-config &&
90+
curl -L -o ftxui.deb https://github.com/ArthurSonzogni/FTXUI/releases/download/v6.1.9/ftxui-6.1.9-Linux.deb &&
91+
apt-get install -y ./ftxui.deb &&
92+
rm ftxui.deb
8893
- run:
8994
apt-get install -y --no-install-recommends
9095
ca-certificates

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ if(BOOTSTRAP_DAEMON AND WIN32)
166166
endif()
167167

168168
option(BUILD_FUZZ_TESTS "Build fuzzing harnesses" OFF)
169+
option(BUILD_NETPROF "Build netprof utility" OFF)
169170

170171
if(MSVC)
171172
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
@@ -665,6 +666,17 @@ if(BOOTSTRAP_DAEMON)
665666
endif()
666667
endif()
667668

669+
if(BUILD_NETPROF)
670+
if(NOT FTXUI_FOUND)
671+
message(WARNING "Option BUILD_NETPROF is enabled but required library FTXUI was not found.")
672+
set(BUILD_NETPROF OFF CACHE BOOL "" FORCE)
673+
endif()
674+
if(NOT NLOHMANN_JSON_FOUND)
675+
message(WARNING "Option BUILD_NETPROF is enabled but required library NLOHMANN_JSON was not found.")
676+
set(BUILD_NETPROF OFF CACHE BOOL "" FORCE)
677+
endif()
678+
endif()
679+
668680
if(BUILD_FUN_UTILS)
669681
add_subdirectory(other/fun)
670682
endif()

cmake/Dependencies.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,34 @@ endif()
5353

5454
# For tox-bootstrapd.
5555
pkg_search_module(LIBCONFIG libconfig IMPORTED_TARGET)
56+
57+
# For netprof.
58+
if(BUILD_NETPROF)
59+
pkg_search_module(FTXUI ftxui IMPORTED_TARGET)
60+
if(FTXUI_FOUND)
61+
string(REGEX MATCH "^([0-9]+)" FTXUI_VERSION_MAJOR "${FTXUI_VERSION}")
62+
else()
63+
pkg_search_module(FTXUI_SCREEN ftxui-screen IMPORTED_TARGET)
64+
pkg_search_module(FTXUI_DOM ftxui-dom IMPORTED_TARGET)
65+
pkg_search_module(FTXUI_COMPONENT ftxui-component IMPORTED_TARGET)
66+
if(FTXUI_SCREEN_FOUND AND FTXUI_DOM_FOUND AND FTXUI_COMPONENT_FOUND)
67+
set(FTXUI_FOUND TRUE)
68+
string(REGEX MATCH "^([0-9]+)" FTXUI_VERSION_MAJOR "${FTXUI_SCREEN_VERSION}")
69+
endif()
70+
endif()
71+
72+
if(NOT FTXUI_FOUND)
73+
find_package(ftxui QUIET)
74+
if(TARGET ftxui::screen AND TARGET ftxui::dom AND TARGET ftxui::component)
75+
set(FTXUI_FOUND TRUE)
76+
endif()
77+
endif()
78+
79+
pkg_search_module(NLOHMANN_JSON nlohmann_json IMPORTED_TARGET)
80+
if(NOT NLOHMANN_JSON_FOUND)
81+
find_package(nlohmann_json QUIET)
82+
if(TARGET nlohmann_json::nlohmann_json)
83+
set(NLOHMANN_JSON_FOUND TRUE)
84+
endif()
85+
endif()
86+
endif()

other/analysis/gen-file.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CPPFLAGS+=("-Iother")
1010
CPPFLAGS+=("-Iother/bootstrap_daemon/src")
1111
CPPFLAGS+=("-Iother/fun")
1212
CPPFLAGS+=("-Itesting")
13+
CPPFLAGS+=("-Itesting/netprof")
14+
CPPFLAGS+=("-Itesting/netprof/views")
1315
CPPFLAGS+=("-Itesting/fuzzing")
1416
CPPFLAGS+=("-Itesting/support")
1517
CPPFLAGS+=("-Itesting/support/doubles")
@@ -61,6 +63,7 @@ COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './_build/*'"
6163
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './other/docker/*'"
6264
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './super_donators/*'"
6365
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './testing/fuzzing/*'"
66+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './testing/netprof/*'"
6467
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './third_party/cmp/examples/*'"
6568
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './third_party/cmp/test/*'"
6669

other/event_tooling/generate_event_c.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ int main(int argc, char** argv) {
649649
{
650650
"Dht_Nodes_Response",
651651
{
652+
EventTypeByteArray{"responder_public_key", "TOX_PUBLIC_KEY_SIZE"},
652653
EventTypeByteArray{"public_key", "TOX_PUBLIC_KEY_SIZE"},
653654
EventTypeByteRange{"ip", "ip_length", "ip_length", "char", "uint32_t", true},
654655
EventTypeTrivial{"uint16_t", "port"},

testing/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ endif()
4141

4242
add_subdirectory(bench)
4343
add_subdirectory(support)
44+
45+
if(BUILD_NETPROF)
46+
add_subdirectory(netprof)
47+
endif()

testing/bench/tox_friends_scaling_bench.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ToxIterateScalingFixture : public benchmark::Fixture {
4141
sim.reset();
4242

4343
int num_friends = state.range(0);
44-
sim = std::make_unique<Simulation>();
44+
sim = std::make_unique<Simulation>(12345);
4545
main_node = sim->create_node();
4646
main_tox = main_node->create_tox();
4747

@@ -85,7 +85,7 @@ class ToxOnlineDisconnectedScalingFixture : public benchmark::Fixture {
8585
sim.reset();
8686

8787
int num_friends = state.range(0);
88-
sim = std::make_unique<Simulation>();
88+
sim = std::make_unique<Simulation>(12345);
8989
sim->net().set_latency(1); // Low latency to encourage traffic
9090
sim->net().set_verbose(kVerbose);
9191

@@ -211,7 +211,7 @@ struct ConnectedContext {
211211
main_node.reset();
212212
sim.reset();
213213

214-
sim = std::make_unique<Simulation>();
214+
sim = std::make_unique<Simulation>(12345);
215215
sim->net().set_latency(5);
216216
main_node = sim->create_node();
217217
main_tox = main_node->create_tox();
@@ -249,7 +249,7 @@ struct GroupScalingContext {
249249
main_node.reset();
250250
sim.reset();
251251

252-
sim = std::make_unique<Simulation>();
252+
sim = std::make_unique<Simulation>(12345);
253253
sim->net().set_latency(5);
254254
main_node = sim->create_node();
255255

testing/bench/tox_messenger_bench.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Context {
2020

2121
void BM_ToxMessengerThroughput(benchmark::State &state)
2222
{
23-
Simulation sim;
23+
Simulation sim{12345};
2424
sim.net().set_latency(5);
2525
auto node1 = sim.create_node();
2626
auto node2 = sim.create_node();
@@ -116,7 +116,7 @@ BENCHMARK(BM_ToxMessengerThroughput);
116116

117117
void BM_ToxMessengerBidirectional(benchmark::State &state)
118118
{
119-
Simulation sim;
119+
Simulation sim{12345};
120120
sim.net().set_latency(5);
121121
auto node1 = sim.create_node();
122122
auto node2 = sim.create_node();

testing/fuzzing/bootstrap_fuzz_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ void setup_callbacks(Tox_Dispatch *dispatch)
109109

110110
void TestBootstrap(Fuzz_Data &input)
111111
{
112-
SimulatedEnvironment env;
112+
SimulatedEnvironment env{12345};
113113
env.fake_clock().advance(1000000000); // Match legacy behavior
114114
auto node = env.create_node(33445);
115115
configure_fuzz_memory_source(env.fake_memory(), input);
116116
configure_fuzz_packet_source(*node->endpoint, input);
117117

118118
// Create a second null system for tox_events_equal check
119-
SimulatedEnvironment null_env;
119+
SimulatedEnvironment null_env{12345};
120120
auto null_node = null_env.create_node(0); // Port 0 (unbound/irrelevant)
121121

122122
Ptr<Tox_Options> opts(tox_options_new(nullptr), tox_options_free);

testing/fuzzing/e2e_fuzz_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ void setup_callbacks(Tox_Dispatch *dispatch)
143143

144144
void TestEndToEnd(Fuzz_Data &input)
145145
{
146-
SimulatedEnvironment env;
146+
SimulatedEnvironment env{12345};
147147
env.fake_clock().advance(1000000000); // Match legacy behavior
148148
auto node = env.create_node(33445);
149149
configure_fuzz_memory_source(env.fake_memory(), input);
150150
configure_fuzz_packet_source(*node->endpoint, input);
151151
configure_fuzz_random_source(env.fake_random(), input);
152152

153153
// Null system replacement for event comparison
154-
SimulatedEnvironment null_env;
154+
SimulatedEnvironment null_env{12345};
155155
auto null_node = null_env.create_node(0);
156156

157157
Ptr<Tox_Options> opts(tox_options_new(nullptr), tox_options_free);

0 commit comments

Comments
 (0)