Skip to content

Commit 37b7767

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

65 files changed

Lines changed: 7331 additions & 37 deletions

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: 5 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,10 @@ jobs:
8485
libvpx-dev
8586
llvm-dev
8687
ninja-build
87-
pkg-config
88+
pkg-config &&
89+
curl -L -o ftxui.deb https://github.com/ArthurSonzogni/FTXUI/releases/download/v6.1.9/ftxui-6.1.9-Linux.deb &&
90+
apt-get install -y ./ftxui.deb &&
91+
rm ftxui.deb
8892
- run:
8993
apt-get install -y --no-install-recommends
9094
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/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/netprof/BUILD.bazel

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
2+
3+
cc_library(
4+
name = "constants",
5+
hdrs = ["constants.hh"],
6+
visibility = ["//c-toxcore/testing/netprof:__subpackages__"],
7+
)
8+
9+
cc_library(
10+
name = "layout_engine",
11+
srcs = ["layout_engine.cc"],
12+
hdrs = ["layout_engine.hh"],
13+
deps = [":constants"],
14+
)
15+
16+
cc_library(
17+
name = "model",
18+
hdrs = ["model.hh"],
19+
visibility = ["//c-toxcore/testing/netprof:__subpackages__"],
20+
deps = [
21+
"//c-toxcore/toxcore:tox",
22+
],
23+
)
24+
25+
cc_library(
26+
name = "model_utils",
27+
srcs = ["model_utils.cc"],
28+
hdrs = ["model_utils.hh"],
29+
visibility = ["//c-toxcore/testing/netprof:__subpackages__"],
30+
deps = [
31+
":model",
32+
],
33+
)
34+
35+
cc_library(
36+
name = "packet_utils",
37+
srcs = ["packet_utils.cc"],
38+
hdrs = ["packet_utils.hh"],
39+
deps = [
40+
"//c-toxcore/toxcore:tox",
41+
],
42+
)
43+
44+
cc_library(
45+
name = "node_wrapper",
46+
srcs = ["node_wrapper.cc"],
47+
hdrs = ["node_wrapper.hh"],
48+
deps = [
49+
":constants",
50+
":model",
51+
"//c-toxcore/testing/support",
52+
"//c-toxcore/toxcore:tox",
53+
"//c-toxcore/toxcore:tox_events",
54+
],
55+
)
56+
57+
cc_library(
58+
name = "simulation_manager",
59+
srcs = ["simulation_manager.cc"],
60+
hdrs = ["simulation_manager.hh"],
61+
deps = [
62+
":constants",
63+
":model_utils",
64+
":node_wrapper",
65+
"//c-toxcore/testing/support",
66+
"//c-toxcore/toxcore:tox",
67+
"//c-toxcore/toxcore:tox_events",
68+
"@json",
69+
],
70+
)
71+
72+
cc_library(
73+
name = "ui",
74+
srcs = [
75+
"command_registry.cc",
76+
"ui.cc",
77+
],
78+
hdrs = [
79+
"command_registry.hh",
80+
"ui.hh",
81+
],
82+
deps = [
83+
":constants",
84+
":layout_engine",
85+
":model",
86+
":model_utils",
87+
"//c-toxcore/testing/netprof/views",
88+
"//c-toxcore/toxcore:tox",
89+
"//c-toxcore/toxcore:tox_events",
90+
"@ftxui//:component",
91+
"@ftxui//:dom",
92+
"@ftxui//:screen",
93+
],
94+
)
95+
96+
cc_library(
97+
name = "app",
98+
srcs = ["app.cc"],
99+
hdrs = ["app.hh"],
100+
deps = [
101+
":constants",
102+
":model",
103+
":model_utils",
104+
":packet_utils",
105+
":simulation_manager",
106+
":ui",
107+
"//c-toxcore/toxcore:tox",
108+
],
109+
)
110+
111+
cc_binary(
112+
name = "netprof",
113+
srcs = [
114+
"main.cc",
115+
],
116+
deps = [
117+
":app",
118+
":packet_utils",
119+
":simulation_manager",
120+
":ui",
121+
"//c-toxcore/testing/support",
122+
"//c-toxcore/toxcore:tox",
123+
"//c-toxcore/toxcore:tox_events",
124+
"@ftxui//:component",
125+
"@ftxui//:dom",
126+
"@ftxui//:screen",
127+
"@json",
128+
],
129+
)
130+
131+
cc_test(
132+
name = "app_test",
133+
srcs = ["app_test.cc"],
134+
deps = [
135+
":app",
136+
"@com_google_googletest//:gtest_main",
137+
],
138+
)
139+
140+
cc_test(
141+
name = "ui_test",
142+
srcs = ["ui_test.cc"],
143+
deps = [
144+
":ui",
145+
"@com_google_googletest//:gtest",
146+
"@com_google_googletest//:gtest_main",
147+
],
148+
)
149+
150+
cc_test(
151+
name = "model_utils_test",
152+
srcs = ["model_utils_test.cc"],
153+
deps = [
154+
":model_utils",
155+
"@com_google_googletest//:gtest_main",
156+
],
157+
)
158+
159+
cc_test(
160+
name = "simulation_manager_test",
161+
srcs = ["simulation_manager_test.cc"],
162+
deps = [
163+
":simulation_manager",
164+
"@com_google_googletest//:gtest_main",
165+
],
166+
)
167+
168+
cc_test(
169+
name = "node_wrapper_test",
170+
srcs = ["node_wrapper_test.cc"],
171+
deps = [
172+
":node_wrapper",
173+
"@com_google_googletest//:gtest_main",
174+
],
175+
)
176+
177+
cc_test(
178+
name = "layout_engine_test",
179+
srcs = ["layout_engine_test.cc"],
180+
deps = [
181+
":layout_engine",
182+
"@com_google_googletest//:gtest_main",
183+
],
184+
)

testing/netprof/CMakeLists.txt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
set(netprof_lib_SOURCES
2+
app.cc
3+
command_registry.cc
4+
layout_engine.cc
5+
model_utils.cc
6+
node_wrapper.cc
7+
packet_utils.cc
8+
simulation_manager.cc
9+
ui.cc
10+
views/bottom_bar.cc
11+
views/command_log.cc
12+
views/command_palette.cc
13+
views/dht_filter.cc
14+
views/dht_topology.cc
15+
views/event_log.cc
16+
views/focusable.cc
17+
views/hud.cc
18+
views/inspector.cc
19+
views/topology.cc
20+
)
21+
22+
add_library(netprof_core STATIC ${netprof_lib_SOURCES})
23+
24+
target_include_directories(netprof_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
25+
26+
target_link_libraries(netprof_core PUBLIC support)
27+
28+
if(TARGET nlohmann_json::nlohmann_json)
29+
target_link_libraries(netprof_core PUBLIC nlohmann_json::nlohmann_json)
30+
else()
31+
target_link_libraries(netprof_core PUBLIC PkgConfig::NLOHMANN_JSON)
32+
endif()
33+
34+
if(TARGET ftxui::component)
35+
target_link_libraries(netprof_core PUBLIC ftxui::component ftxui::dom ftxui::screen)
36+
elseif(TARGET PkgConfig::FTXUI)
37+
target_link_libraries(netprof_core PUBLIC PkgConfig::FTXUI)
38+
else()
39+
target_link_libraries(netprof_core PUBLIC PkgConfig::FTXUI_COMPONENT PkgConfig::FTXUI_DOM PkgConfig::FTXUI_SCREEN)
40+
endif()
41+
42+
if(TARGET pthreads4w::pthreads4w)
43+
target_link_libraries(netprof_core PUBLIC pthreads4w::pthreads4w)
44+
elseif(TARGET PThreads4W::PThreads4W)
45+
target_link_libraries(netprof_core PUBLIC PThreads4W::PThreads4W)
46+
elseif(TARGET Threads::Threads)
47+
target_link_libraries(netprof_core PUBLIC Threads::Threads)
48+
endif()
49+
50+
if(TARGET toxcore_static)
51+
target_link_libraries(netprof_core PRIVATE toxcore_static)
52+
else()
53+
target_link_libraries(netprof_core PRIVATE toxcore_shared)
54+
endif()
55+
56+
if(FTXUI_VERSION_MAJOR)
57+
target_compile_definitions(netprof_core PUBLIC FTXUI_VERSION_MAJOR=${FTXUI_VERSION_MAJOR})
58+
endif()
59+
60+
add_executable(netprof main.cc)
61+
target_link_libraries(netprof PRIVATE netprof_core)
62+
63+
# Tests
64+
if(UNITTEST AND TARGET GTest::gtest_main)
65+
function(netprof_test target source)
66+
add_executable(${target} ${source})
67+
target_link_libraries(${target} PRIVATE netprof_core GTest::gtest_main GTest::gmock)
68+
if(TARGET toxcore_static)
69+
target_link_libraries(${target} PRIVATE toxcore_static)
70+
else()
71+
target_link_libraries(${target} PRIVATE toxcore_shared)
72+
endif()
73+
add_test(NAME ${target} COMMAND ${target})
74+
endfunction()
75+
76+
netprof_test(netprof_layout_engine_test layout_engine_test.cc)
77+
netprof_test(netprof_node_wrapper_test node_wrapper_test.cc)
78+
netprof_test(netprof_simulation_manager_test simulation_manager_test.cc)
79+
netprof_test(netprof_ui_test ui_test.cc)
80+
netprof_test(netprof_model_utils_test model_utils_test.cc)
81+
netprof_test(netprof_app_test app_test.cc)
82+
endif()

0 commit comments

Comments
 (0)