Skip to content

Commit ee491d7

Browse files
committed
feat: Add a network profiling TUI.
1 parent ea597ed commit ee491d7

76 files changed

Lines changed: 7120 additions & 39 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: 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
@@ -180,6 +180,7 @@ if(BOOTSTRAP_DAEMON AND WIN32)
180180
endif()
181181

182182
option(BUILD_FUZZ_TESTS "Build fuzzing harnesses" OFF)
183+
option(BUILD_NETPROF "Build netprof utility" OFF)
183184

184185
if(MSVC)
185186
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
@@ -693,6 +694,17 @@ if(BOOTSTRAP_DAEMON)
693694
endif()
694695
endif()
695696

697+
if(BUILD_NETPROF)
698+
if(NOT FTXUI_FOUND)
699+
message(WARNING "Option BUILD_NETPROF is enabled but required library FTXUI was not found.")
700+
set(BUILD_NETPROF OFF CACHE BOOL "" FORCE)
701+
endif()
702+
if(NOT NLOHMANN_JSON_FOUND)
703+
message(WARNING "Option BUILD_NETPROF is enabled but required library NLOHMANN_JSON was not found.")
704+
set(BUILD_NETPROF OFF CACHE BOOL "" FORCE)
705+
endif()
706+
endif()
707+
696708
if(BUILD_FUN_UTILS)
697709
add_subdirectory(other/fun)
698710
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
@@ -721,6 +721,7 @@ int main(int argc, char** argv) {
721721
{
722722
"Dht_Nodes_Response",
723723
{
724+
EventTypeByteArray{"responder_public_key", "TOX_PUBLIC_KEY_SIZE"},
724725
EventTypeByteArray{"public_key", "TOX_PUBLIC_KEY_SIZE"},
725726
EventTypeByteRange{"ip", "ip_length", "ip_length", "char", "uint32_t", true},
726727
EventTypeTrivial{"uint16_t", "port"},

testing/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ endif()
3939
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/support")
4040
add_subdirectory(support)
4141
endif()
42+
43+
if(BUILD_NETPROF)
44+
add_subdirectory(netprof)
45+
endif()

testing/netprof/BUILD.bazel

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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+
":constants",
22+
"//c-toxcore/toxcore:tox",
23+
],
24+
)
25+
26+
cc_library(
27+
name = "model_utils",
28+
srcs = ["model_utils.cc"],
29+
hdrs = ["model_utils.hh"],
30+
visibility = ["//c-toxcore/testing/netprof:__subpackages__"],
31+
deps = [
32+
":model",
33+
"//c-toxcore/toxcore:tox",
34+
],
35+
)
36+
37+
cc_library(
38+
name = "packet_utils",
39+
srcs = ["packet_utils.cc"],
40+
hdrs = ["packet_utils.hh"],
41+
visibility = ["//c-toxcore/testing/netprof:__subpackages__"],
42+
deps = [
43+
"//c-toxcore/toxcore:tox",
44+
],
45+
)
46+
47+
cc_library(
48+
name = "node_wrapper",
49+
srcs = ["node_wrapper.cc"],
50+
hdrs = ["node_wrapper.hh"],
51+
deps = [
52+
":constants",
53+
":model",
54+
"//c-toxcore/testing/support",
55+
"//c-toxcore/toxcore:tox",
56+
"//c-toxcore/toxcore:tox_events",
57+
"//c-toxcore/toxcore:tox_options",
58+
],
59+
)
60+
61+
cc_library(
62+
name = "simulation_manager",
63+
srcs = ["simulation_manager.cc"],
64+
hdrs = ["simulation_manager.hh"],
65+
deps = [
66+
":constants",
67+
":model_utils",
68+
":node_wrapper",
69+
"//c-toxcore/testing/support",
70+
"//c-toxcore/toxcore:tox",
71+
"//c-toxcore/toxcore:tox_events",
72+
"//c-toxcore/toxcore:tox_options",
73+
"@json",
74+
],
75+
)
76+
77+
cc_library(
78+
name = "ui",
79+
srcs = [
80+
"command_registry.cc",
81+
"ui.cc",
82+
],
83+
hdrs = [
84+
"command_registry.hh",
85+
"ui.hh",
86+
],
87+
deps = [
88+
":constants",
89+
":layout_engine",
90+
":model",
91+
":model_utils",
92+
"//c-toxcore/testing/netprof/views",
93+
"//c-toxcore/toxcore:tox",
94+
"//c-toxcore/toxcore:tox_events",
95+
"@ftxui//:component",
96+
"@ftxui//:dom",
97+
"@ftxui//:screen",
98+
],
99+
)
100+
101+
cc_library(
102+
name = "ui_test_support",
103+
testonly = True,
104+
srcs = ["ui_test_support.cc"],
105+
hdrs = ["ui_test_support.hh"],
106+
visibility = ["//c-toxcore/testing/netprof:__subpackages__"],
107+
deps = [
108+
":ui",
109+
"@com_google_googletest//:gtest",
110+
"@ftxui//:dom",
111+
"@ftxui//:screen",
112+
],
113+
)
114+
115+
cc_library(
116+
name = "app",
117+
srcs = ["app.cc"],
118+
hdrs = ["app.hh"],
119+
deps = [
120+
":constants",
121+
":model",
122+
":model_utils",
123+
":packet_utils",
124+
":simulation_manager",
125+
":ui",
126+
"//c-toxcore/toxcore:tox",
127+
],
128+
)
129+
130+
cc_binary(
131+
name = "netprof",
132+
srcs = [
133+
"main.cc",
134+
],
135+
deps = [
136+
":app",
137+
":packet_utils",
138+
":simulation_manager",
139+
":ui",
140+
"//c-toxcore/testing/support",
141+
"//c-toxcore/toxcore:tox",
142+
"//c-toxcore/toxcore:tox_events",
143+
"@ftxui//:component",
144+
"@ftxui//:dom",
145+
"@ftxui//:screen",
146+
"@json",
147+
],
148+
)
149+
150+
cc_test(
151+
name = "app_test",
152+
srcs = ["app_test.cc"],
153+
deps = [
154+
":app",
155+
"@com_google_googletest//:gtest",
156+
"@com_google_googletest//:gtest_main",
157+
],
158+
)
159+
160+
cc_test(
161+
name = "ui_test",
162+
srcs = ["ui_test.cc"],
163+
deps = [
164+
":ui",
165+
":ui_test_support",
166+
"@com_google_googletest//:gtest",
167+
"@com_google_googletest//:gtest_main",
168+
],
169+
)
170+
171+
cc_test(
172+
name = "model_utils_test",
173+
srcs = ["model_utils_test.cc"],
174+
deps = [
175+
":model_utils",
176+
"@com_google_googletest//:gtest",
177+
"@com_google_googletest//:gtest_main",
178+
],
179+
)
180+
181+
cc_test(
182+
name = "simulation_manager_test",
183+
srcs = ["simulation_manager_test.cc"],
184+
deps = [
185+
":simulation_manager",
186+
"//c-toxcore/testing/support",
187+
"@com_google_googletest//:gtest",
188+
"@com_google_googletest//:gtest_main",
189+
],
190+
)
191+
192+
cc_test(
193+
name = "node_wrapper_test",
194+
srcs = ["node_wrapper_test.cc"],
195+
deps = [
196+
":node_wrapper",
197+
"//c-toxcore/testing/support",
198+
"@com_google_googletest//:gtest",
199+
"@com_google_googletest//:gtest_main",
200+
],
201+
)
202+
203+
cc_test(
204+
name = "layout_engine_test",
205+
srcs = ["layout_engine_test.cc"],
206+
deps = [
207+
":layout_engine",
208+
"@com_google_googletest//:gtest",
209+
"@com_google_googletest//:gtest_main",
210+
],
211+
)

0 commit comments

Comments
 (0)