Skip to content

Commit 04662fd

Browse files
committed
Merge branch 'testing'
2 parents 1a8e299 + bb745b7 commit 04662fd

File tree

9 files changed

+246
-63
lines changed

9 files changed

+246
-63
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ add_custom_target(uninstall
9191
# TESTING #
9292
#///////////////////////////////////////////////////////////////////#
9393

94+
95+
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
96+
option(BUILD_TESTING "Build tests" OFF)
97+
endif()
9498
include(CTest)
9599
add_subdirectory(tests)
96100

include/nvtop/interface_layout_selection.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ struct window_position {
1111
};
1212

1313
// Should be fine
14-
#define MAX_CHARTS 30
14+
#define MAX_CHARTS 64
1515

16-
void compute_sizes_from_layout(
17-
unsigned devices_count, unsigned device_header_rows,
18-
unsigned device_header_cols, unsigned rows, unsigned cols,
19-
const plot_info_to_draw to_draw[devices_count],
20-
process_field_displayed process_field_displayed,
21-
struct window_position device_positions[devices_count], unsigned *num_plots,
22-
struct window_position plot_positions[MAX_CHARTS],
23-
unsigned map_device_to_plot[devices_count],
24-
struct window_position *process_position,
25-
struct window_position *setup_position);
16+
void compute_sizes_from_layout(unsigned devices_count, unsigned device_header_rows, unsigned device_header_cols,
17+
unsigned rows, unsigned cols, const plot_info_to_draw *to_draw,
18+
process_field_displayed process_field_displayed,
19+
struct window_position *device_positions, unsigned *num_plots,
20+
struct window_position plot_positions[MAX_CHARTS], unsigned *map_device_to_plot,
21+
struct window_position *process_position, struct window_position *setup_position);
2622

2723
#endif // INTERFACE_LAYOUT_SELECTION_H__

src/extract_gpuinfo_amdgpu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static bool gpuinfo_amdgpu_get_device_handles(
326326

327327
int fd = -1;
328328

329-
for (unsigned int j = DRM_NODE_MAX - 1; j >= 0; j--) {
329+
for (unsigned int j = DRM_NODE_MAX - 1;; j--) {
330330
if (!(1 << j & devs[i]->available_nodes))
331331
continue;
332332

@@ -641,7 +641,8 @@ static void gpuinfo_amdgpu_populate_static_info(struct gpu_info *_gpu_info) {
641641
float maxLinkSpeedf;
642642
NreadPatterns = readValueFromFileAt(gpu_info->sysfsFD, "max_link_speed", "%f GT/s PCIe", &maxLinkSpeedf);
643643
if (NreadPatterns == 1 && IS_VALID(gpuinfo_max_link_width_valid, static_info->valid)) {
644-
unsigned maxLinkSpeed = (unsigned)(floorf(maxLinkSpeedf));
644+
maxLinkSpeedf = floorf(maxLinkSpeedf);
645+
unsigned maxLinkSpeed = (unsigned)maxLinkSpeedf;
645646
unsigned pcieGen = pcieGenFromLinkSpeedAndWidth(maxLinkSpeed);
646647
if (pcieGen) {
647648
static_info->max_pcie_gen = pcieGen;
@@ -836,7 +837,7 @@ static bool is_drm_fd(int fd_dir_fd, const char *name) {
836837
}
837838

838839
static ssize_t read_whole_file(int dirfd, const char *pathname, char **data) {
839-
ssize_t read_size = 0;
840+
size_t read_size = 0;
840841
size_t buf_size = 0;
841842
char *buf = NULL;
842843
int fd;

src/interface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ print_processes_on_screen(all_processes all_procs,
12751275
&process_print_buffer[process->offset_column]);
12761276
unsigned row, col;
12771277
getyx(win, row, col);
1278+
(void)col;
12781279
if (row == write_at)
12791280
wclrtoeol(win);
12801281
last_line_printed = write_at;

src/interface_layout_selection.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static bool who_to_merge(unsigned max_merge_size, unsigned plot_count, unsigned
4747
merge_ids[1] = notEmptyPlotIdx;
4848
}
4949
}
50-
return smallest_merge != UCHAR_MAX;
50+
return smallest_merge != UINT_MAX;
5151
}
5252

5353
static bool move_plot_to_stack(unsigned stack_max_cols, unsigned plot_id,
@@ -243,21 +243,16 @@ static void balance_info_on_stacks_preserving_plot_order(
243243
}
244244
}
245245

246-
void compute_sizes_from_layout(
247-
unsigned devices_count, unsigned device_header_rows,
248-
unsigned device_header_cols, unsigned rows, unsigned cols,
249-
const plot_info_to_draw to_draw[devices_count],
250-
process_field_displayed process_displayed,
251-
struct window_position device_positions[devices_count], unsigned *num_plots,
252-
struct window_position plot_positions[MAX_CHARTS],
253-
unsigned map_device_to_plot[devices_count],
254-
struct window_position *process_position,
255-
struct window_position *setup_position) {
246+
void compute_sizes_from_layout(unsigned devices_count, unsigned device_header_rows, unsigned device_header_cols,
247+
unsigned rows, unsigned cols, const plot_info_to_draw *to_draw,
248+
process_field_displayed process_displayed, struct window_position *device_positions,
249+
unsigned *num_plots, struct window_position plot_positions[MAX_CHARTS],
250+
unsigned *map_device_to_plot, struct window_position *process_position,
251+
struct window_position *setup_position) {
256252

257253
unsigned min_rows_for_header = 0, header_stacks = 0, num_device_per_row = 0;
258254
num_device_per_row = max(1, cols / device_header_cols);
259-
header_stacks = devices_count / num_device_per_row +
260-
((devices_count % num_device_per_row) > 0);
255+
header_stacks = max(1, devices_count / num_device_per_row + ((devices_count % num_device_per_row) > 0));
261256
if (devices_count % header_stacks == 0)
262257
num_device_per_row = devices_count / header_stacks;
263258
min_rows_for_header = header_stacks * device_header_rows;
@@ -393,7 +388,7 @@ void compute_sizes_from_layout(
393388
rows_left_for_process = rows_for_plots - rows_per_stack * num_plot_stacks;
394389
} else {
395390
// No plot displayed, allocate the leftover space to the processes
396-
if (process_field_displayed_count(process_displayed) > 0)
391+
if (process_field_displayed_count(process_displayed) > 0 && rows_for_plots > 0)
397392
rows_for_process += rows_for_plots - 1;
398393
}
399394

src/interface_options.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ini.h"
2424
#include "nvtop/interface_common.h"
2525

26+
#include <assert.h>
2627
#include <errno.h>
2728
#include <libgen.h>
2829
#include <limits.h>
@@ -216,7 +217,8 @@ static int nvtop_option_ini_handler(void *user, const char *section,
216217
}
217218
}
218219
// Per-Device Sections
219-
for (unsigned i = 0; i < ini_data->num_devices; ++i) {
220+
assert(ini_data->num_devices < 1000 && "Not enough room for 1000 devices");
221+
for (unsigned i = 0; i < ini_data->num_devices && i < 1000; ++i) {
220222
char gpu_section_name[sizeof(device_section) + 4];
221223
snprintf(gpu_section_name, sizeof(device_section) + 3, "%s%u",
222224
device_section, i);

src/plot.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static inline int data_level(double rows, double data, double increment) {
3232
}
3333

3434
void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
35-
unsigned num_plots, bool legend_left,
35+
unsigned num_lines, bool legend_left,
3636
char legend[MAX_LINES_PER_PLOT][PLOT_MAX_LEGEND_SIZE]) {
3737
if (num_data == 0)
3838
return;
@@ -41,13 +41,13 @@ void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
4141
rows -= 1;
4242
double increment = 100. / (double)(rows);
4343

44-
assert(num_plots <= MAX_LINES_PER_PLOT && "Cannot plot more than " EXPAND_AND_QUOTE(MAX_LINES_PER_PLOT) " lines");
44+
assert(num_lines <= MAX_LINES_PER_PLOT && "Cannot plot more than " EXPAND_AND_QUOTE(MAX_LINES_PER_PLOT) " lines");
4545
unsigned lvl_before[MAX_LINES_PER_PLOT];
46-
for (size_t k = 0; k < num_plots; ++k)
46+
for (size_t k = 0; k < num_lines; ++k)
4747
lvl_before[k] = data_level(rows, data[k], increment);
4848

49-
for (size_t i = 0; i < num_data || i < (size_t)cols; i += num_plots) {
50-
for (unsigned k = 0; k < num_plots; ++k) {
49+
for (size_t i = 0; i < num_data || i < (size_t)cols; i += num_lines) {
50+
for (unsigned k = 0; k < num_lines; ++k) {
5151
unsigned lvl_now_k = data_level(rows, data[i + k], increment);
5252
wcolor_set(win, k + 1, NULL);
5353
// Three cases: has increased, has decreased and remained level
@@ -69,7 +69,7 @@ void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
6969
}
7070

7171
// Draw the continuation of the other metrics
72-
for (unsigned j = 0; j < num_plots; ++j) {
72+
for (unsigned j = 0; j < num_lines; ++j) {
7373
if (j != k) {
7474
if (lvl_before[j] == top)
7575
// The continuation is at the same level as the bottom corner
@@ -92,7 +92,7 @@ void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
9292
} else {
9393
// Case 3: stayed level
9494
mvwhline(win, lvl_now_k, i + k, 0, 1);
95-
for (unsigned j = 0; j < num_plots; ++j) {
95+
for (unsigned j = 0; j < num_lines; ++j) {
9696
if (j != k) {
9797
if (lvl_before[j] != lvl_now_k) {
9898
// Add the continuation of other metric lines
@@ -107,21 +107,19 @@ void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data,
107107
}
108108
}
109109
int plot_y_position = 0;
110-
for (unsigned i = 0; i < num_plots && plot_y_position < rows; ++i) {
111-
if (legend[i]) {
112-
wcolor_set(win, i + 1, NULL);
113-
if (legend_left) {
114-
mvwprintw(win, plot_y_position, 0, "%.*s", cols, legend[i]);
110+
for (unsigned i = 0; i < num_lines && plot_y_position < rows; ++i) {
111+
wcolor_set(win, i + 1, NULL);
112+
if (legend_left) {
113+
mvwprintw(win, plot_y_position, 0, "%.*s", cols, legend[i]);
114+
} else {
115+
size_t length = strlen(legend[i]);
116+
if (length <= (size_t)cols) {
117+
mvwprintw(win, plot_y_position, cols - length, "%s", legend[i]);
115118
} else {
116-
size_t length = strlen(legend[i]);
117-
if (length <= (size_t)cols) {
118-
mvwprintw(win, plot_y_position, cols - length, "%s", legend[i]);
119-
} else {
120-
mvwprintw(win, plot_y_position, 0, "%.*s", length - cols, legend[i]);
121-
}
119+
mvwprintw(win, plot_y_position, 0, "%.*s", length - cols, legend[i]);
122120
}
123-
plot_y_position++;
124121
}
122+
plot_y_position++;
125123
}
126124
}
127125

tests/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
find_package(GTest)
22
if (BUILD_TESTING AND GTest_FOUND)
3+
4+
option(THOROUGH_TESTING "Enable extensive testing (takes hours, e.g., use once per release)" OFF)
5+
36
# Create a library for testing
47
add_library(testLib
58
${PROJECT_SOURCE_DIR}/src/interface_layout_selection.c
@@ -18,4 +21,9 @@ if (BUILD_TESTING AND GTest_FOUND)
1821
target_link_libraries(interfaceTests PRIVATE testLib GTest::gtest_main)
1922
gtest_discover_tests(interfaceTests)
2023

24+
if (THOROUGH_TESTING)
25+
target_compile_definitions(interfaceTests PRIVATE THOROUGH_TESTING)
26+
endif()
27+
28+
2129
endif()

0 commit comments

Comments
 (0)