diff options
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | src/btop.cpp | 31 | ||||
-rw-r--r-- | src/btop_config.cpp | 18 | ||||
-rw-r--r-- | src/btop_config.hpp | 10 | ||||
-rw-r--r-- | src/btop_draw.cpp | 82 | ||||
-rw-r--r-- | src/btop_input.cpp | 9 | ||||
-rw-r--r-- | src/btop_menu.cpp | 34 | ||||
-rw-r--r-- | src/btop_shared.cpp | 2 | ||||
-rw-r--r-- | src/btop_shared.hpp | 8 | ||||
-rw-r--r-- | src/btop_tools.cpp | 8 | ||||
-rw-r--r-- | src/linux/btop_collect.cpp | 16 |
11 files changed, 198 insertions, 34 deletions
@@ -36,6 +36,17 @@ endif override PLATFORM_LC := $(shell echo $(PLATFORM) | tr '[:upper:]' '[:lower:]') +#? GPU Support +ifeq ($(PLATFORM_LC)$(ARCH),linuxx86_64) + GPU_SUPPORT := true +else + GPU_SUPPORT := false +endif + +ifeq ($(GPU_SUPPORT),true) + override ADDFLAGS += -DGPU_SUPPORT +endif + #? Compiler and Linker ifeq ($(shell $(CXX) --version | grep clang >/dev/null 2>&1; echo $$?),0) override CXX_IS_CLANG := true @@ -218,6 +229,7 @@ info: @printf " $(BANNER)\n" @printf "\033[1;92mPLATFORM \033[1;93m?| \033[0m$(PLATFORM)\n" @printf "\033[1;96mARCH \033[1;93m?| \033[0m$(ARCH)\n" + @printf "\033[1;95mGPU_SUPPORT \033[1;94m:| \033[0m$(GPU_SUPPORT)\n" @printf "\033[1;93mCXX \033[1;93m?| \033[0m$(CXX) \033[1;93m(\033[97m$(CXX_VERSION)\033[93m)\n" @printf "\033[1;94mTHREADS \033[1;94m:| \033[0m$(THREADS)\n" @printf "\033[1;92mREQFLAGS \033[1;91m!| \033[0m$(REQFLAGS)\n" @@ -310,7 +322,7 @@ uninstall: -include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT)) #? Compile rocm_smi -ifeq ($(RSMI_STATIC)$(PLATFORM_LC),truelinux) +ifeq ($(GPU_SUPPORT)$(RSMI_STATIC),truetrue) .ONESHELL: rocm_smi: @printf "\n\033[1;92mBuilding ROCm SMI static library\033[37m...\033[0m\n" diff --git a/src/btop.cpp b/src/btop.cpp index 2f755d0..b58127c 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -183,8 +183,11 @@ void term_resize(bool force) { if (force and refreshed) force = false; } else return; - +#ifdef GPU_SUPPORT static const array<string, 10> all_boxes = {"gpu5", "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4"}; +#else + static const array<string, 5> all_boxes = {"", "cpu", "mem", "net", "proc"}; +#endif Global::resized = true; if (Runner::active) Runner::stop(); Term::refresh(); @@ -224,8 +227,12 @@ void term_resize(bool force) { clean_quit(0); else if (key.size() == 1 and isint(key)) { auto intKey = stoi(key); - auto box = all_boxes.at(intKey); - if (not box.starts_with("gpu") or (intKey == 0 and Gpu::gpu_names.size() >= 5) or (intKey >= 5 and std::cmp_greater_equal(Gpu::gpu_names.size(), intKey - 4))) { + #ifdef GPU_SUPPORT + if ((intKey == 0 and Gpu::gpu_names.size() >= 5) or (intKey >= 5 and std::cmp_greater_equal(Gpu::gpu_names.size(), intKey - 4))) { + #else + if (intKey > 0 and intKey < 5) { + #endif + auto box = all_boxes.at(intKey); Config::current_preset = -1; Config::toggle_box(box); boxes = Config::getS("shown_boxes"); @@ -262,7 +269,7 @@ void clean_quit(int sig) { #endif } -#ifdef __linux__ +#ifdef GPU_SUPPORT Gpu::Nvml::shutdown(); Gpu::Rsmi::shutdown(); #endif @@ -499,7 +506,13 @@ namespace Runner { //! DEBUG stats if (Global::debug) { if (debug_bg.empty() or redraw) - Runner::debug_bg = Draw::createBox(2, 2, 33, 9, "", true, "μs"); + Runner::debug_bg = Draw::createBox(2, 2, 33, + #ifdef GPU_SUPPORT + 9, + #else + 8, + #endif + "", true, "μs"); debug_times.clear(); debug_times["total"] = {0, 0}; @@ -509,7 +522,7 @@ namespace Runner { //* Run collection and draw functions for all boxes try { - #ifdef __linux__ + #ifdef GPU_SUPPORT //? GPU data collection const bool gpu_in_cpu_panel = Gpu::gpu_names.size() > 0 and ( Config::getS("cpu_graph_lower").starts_with("gpu-") or Config::getS("cpu_graph_upper").starts_with("gpu-") @@ -559,7 +572,7 @@ namespace Runner { throw std::runtime_error("Cpu:: -> " + string{e.what()}); } } - #ifdef __linux__ + #ifdef GPU_SUPPORT //? GPU if (not gpu_panels.empty() and not gpus_ref.empty()) { try { @@ -693,7 +706,11 @@ namespace Runner { "post"_a = Theme::c("main_fg") + Fx::ub ); static auto loc = std::locale(std::locale::classic(), new MyNumPunct); + #ifdef GPU_SUPPORT for (const string name : {"cpu", "mem", "net", "proc", "gpu", "total"}) { + #else + for (const string name : {"cpu", "mem", "net", "proc", "total"}) { + #endif if (not debug_times.contains(name)) debug_times[name] = {0,0}; const auto& [time_collect, time_draw] = debug_times.at(name); if (name == "total") output += Fx::b; diff --git a/src/btop_config.cpp b/src/btop_config.cpp index a2864f1..4189c64 100644 --- a/src/btop_config.cpp +++ b/src/btop_config.cpp @@ -73,9 +73,9 @@ namespace Config { "#* Note that \"tty\" only has half the horizontal resolution of the other two, so will show a shorter historical view."}, {"graph_symbol_cpu", "# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."}, - +#ifdef GPU_SUPPORT {"graph_symbol_gpu", "# Graph symbol to use for graphs in gpu box, \"default\", \"braille\", \"block\" or \"tty\"."}, - +#endif {"graph_symbol_mem", "# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."}, {"graph_symbol_net", "# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."}, @@ -114,9 +114,9 @@ namespace Config { {"cpu_graph_lower", "#* Sets the CPU stat shown in lower half of the CPU graph, \"total\" is always available.\n" "#* Select from a list of detected attributes from the options menu."}, - + #ifdef GPU_SUPPORT {"show_gpu_info", "#* If gpu info should be shown in the cpu box. Available values = \"Auto\", \"On\" and \"Off\"."}, - + #endif {"cpu_invert_lower", "#* Toggles if the lower CPU graph should be inverted."}, {"cpu_single_graph", "#* Set to True to completely disable the lower CPU graph."}, @@ -197,6 +197,7 @@ namespace Config { {"log_level", "#* Set loglevel for \"~/.config/btop/btop.log\" levels are: \"ERROR\" \"WARNING\" \"INFO\" \"DEBUG\".\n" "#* The level set includes all lower levels, i.e. \"DEBUG\" will show all logging info."}, + #ifdef GPU_SUPPORT {"nvml_measure_pcie_speeds", "#* Measure PCIe throughput on NVIDIA cards, may impact performance on certain cards."}, @@ -209,6 +210,7 @@ namespace Config { {"custom_gpu_name3", "#* Custom gpu3 model name, empty string to disable."}, {"custom_gpu_name4", "#* Custom gpu4 model name, empty string to disable."}, {"custom_gpu_name5", "#* Custom gpu5 model name, empty string to disable."}, + #endif }; unordered_flat_map<std::string_view, string> strings = { @@ -237,6 +239,7 @@ namespace Config { {"proc_filter", ""}, {"proc_command", ""}, {"selected_name", ""}, + #ifdef GPU_SUPPORT {"custom_gpu_name0", ""}, {"custom_gpu_name1", ""}, {"custom_gpu_name2", ""}, @@ -244,6 +247,7 @@ namespace Config { {"custom_gpu_name4", ""}, {"custom_gpu_name5", ""}, {"show_gpu_info", "Auto"} + #endif }; unordered_flat_map<std::string_view, string> stringsTmp; @@ -292,8 +296,10 @@ namespace Config { {"lowcolor", false}, {"show_detailed", false}, {"proc_filtering", false}, + #ifdef GPU_SUPPORT {"nvml_measure_pcie_speeds", true}, {"gpu_mirror_graph", true}, + #endif }; unordered_flat_map<std::string_view, bool> boolsTmp; @@ -440,8 +446,10 @@ namespace Config { else if (name == "shown_boxes" and not value.empty() and not check_boxes(value)) validError = "Invalid box name(s) in shown_boxes!"; + #ifdef GPU_SUPPORT else if (name == "show_gpu_info" and not v_contains(show_gpu_values, value)) validError = "Invalid value for show_gpu_info: " + value; + #endif else if (name == "presets" and not presetsValid(value)) return false; @@ -545,11 +553,13 @@ namespace Config { auto new_boxes = ssplit(boxes); for (auto& box : new_boxes) { if (not v_contains(valid_boxes, box)) return false; + #ifdef GPU_SUPPORT if (box.starts_with("gpu")) { size_t gpu_num = stoi(box.substr(3)); if (gpu_num == 0) gpu_num = 5; if (std::cmp_greater(gpu_num, Gpu::gpu_names.size())) return false; } + #endif } current_boxes = std::move(new_boxes); return true; diff --git a/src/btop_config.hpp b/src/btop_config.hpp index 82b232d..c71d29c 100644 --- a/src/btop_config.hpp +++ b/src/btop_config.hpp @@ -43,10 +43,16 @@ namespace Config { const vector<string> valid_graph_symbols = { "braille", "block", "tty" }; const vector<string> valid_graph_symbols_def = { "default", "braille", "block", "tty" }; - const vector<string> valid_boxes = { "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4", "gpu5" }; + const vector<string> valid_boxes = { + "cpu", "mem", "net", "proc" +#ifdef GPU_SUPPORT + ,"gpu0", "gpu1", "gpu2", "gpu3", "gpu4", "gpu5" +#endif + }; const vector<string> temp_scales = { "celsius", "fahrenheit", "kelvin", "rankine" }; +#ifdef GPU_SUPPORT const vector<string> show_gpu_values = { "Auto", "On", "Off" }; - +#endif extern vector<string> current_boxes; extern vector<string> preset_list; extern vector<string> available_batteries; diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index a5c6776..1327562 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -533,15 +533,23 @@ namespace Cpu { auto single_graph = Config::getB("cpu_single_graph"); bool hide_cores = show_temps and (cpu_temp_only or not Config::getB("show_coretemp")); const int extra_width = (hide_cores ? max(6, 6 * b_column_size) : 0); + #ifdef GPU_SUPPORT const auto& show_gpu_info = Config::getS("show_gpu_info"); const bool gpu_always = show_gpu_info == "On"; bool show_gpu = (gpus.size() > 0 and (gpu_always or (show_gpu_info == "Auto" and Gpu::shown == 0))); + #else + (void)gpus; + #endif auto graph_up_field = Config::getS("cpu_graph_upper"); if (graph_up_field == "Auto" or not v_contains(Cpu::available_fields, graph_up_field)) graph_up_field = "total"; auto graph_lo_field = Config::getS("cpu_graph_lower"); if (graph_lo_field == "Auto" or not v_contains(Cpu::available_fields, graph_lo_field)) { + #ifdef GPU_SUPPORT graph_lo_field = show_gpu ? "gpu-totals" : graph_up_field; + #else + graph_lo_field = graph_up_field; + #endif } auto tty_mode = Config::getB("tty_mode"); auto& graph_symbol = (tty_mode ? "tty" : Config::getS("graph_symbol_cpu")); @@ -585,6 +593,7 @@ namespace Cpu { const int graph_default_width = x + width - b_width - 3; auto init_graphs = [&](vector<Draw::Graph>& graphs, const int graph_height, int& graph_width, const string& graph_field, bool invert) { + #ifdef GPU_SUPPORT if (graph_field.starts_with("gpu")) { if (graph_field.find("totals") != string::npos) { graphs.resize(gpus.size()); @@ -637,9 +646,11 @@ namespace Cpu { } } } else { + #endif graphs.resize(1); graph_width = graph_default_width; graphs[0] = Draw::Graph{ graph_width, graph_height, "cpu", cpu.cpu_percent.at(graph_field), graph_symbol, invert, true }; + #ifdef GPU_SUPPORT if (std::cmp_less(Gpu::shown, gpus.size())) { gpu_temp_graphs.resize(gpus.size()); gpu_mem_graphs.resize(gpus.size()); @@ -656,6 +667,7 @@ namespace Cpu { } } } + #endif }; init_graphs(graphs_upper, graph_up_height, graph_up_width, graph_up_field, false); @@ -733,6 +745,7 @@ namespace Cpu { //? Cpu/Gpu graphs out += Fx::ub + Mv::to(y + 1, x + 1); auto draw_graphs = [&](vector<Draw::Graph>& graphs, const int graph_height, const int graph_width, const string& graph_field) { + #ifdef GPU_SUPPORT if (graph_field.starts_with("gpu")) if (graph_field.find("totals") != string::npos) for (unsigned long i = 0;;) { @@ -747,8 +760,14 @@ namespace Cpu { out += Theme::c("div_line") + (Symbols::v_line + Mv::l(1) + Mv::u(1))*graph_height + Mv::r(1) + Mv::d(1); else break; } - else out += graphs[0](Gpu::shared_gpu_percent.at(graph_field), (data_same or redraw)); - else out += graphs[0](cpu.cpu_percent.at(graph_field), (data_same or redraw)); + else + out += graphs[0](Gpu::shared_gpu_percent.at(graph_field), (data_same or redraw)); + else + #else + (void)graph_height; + (void)graph_width; + #endif + out += graphs[0](cpu.cpu_percent.at(graph_field), (data_same or redraw)); }; draw_graphs(graphs_upper, graph_up_height, graph_up_width, graph_up_field); @@ -843,10 +862,15 @@ namespace Cpu { } else { lavg_str_len = lavg_str.length(); } + #ifdef GPU_SUPPORT cy = b_height - 2 - (show_gpu ? (gpus.size() - (gpu_always ? 0 : Gpu::shown)) : 0); + #else + cy = b_height - 2; + #endif out += Mv::to(b_y + cy, b_x + cx + 1) + Theme::c("main_fg") + lavg_str; } + #ifdef GPU_SUPPORT //? Gpu brief info if (show_gpu) { for (unsigned long i = 0; i < gpus.size(); ++i) { @@ -883,6 +907,7 @@ namespace Cpu { if (cy < b_height - 1) break; } } + #endif redraw = false; return out + Fx::reset; @@ -890,6 +915,7 @@ namespace Cpu { } +#ifdef GPU_SUPPORT namespace Gpu { int width_p = 100, height_p = 32; int min_width = 41, min_height = 11; @@ -1059,6 +1085,7 @@ namespace Gpu { } } +#endif namespace Mem { int width_p = 45, height_p = 36; @@ -1919,7 +1946,7 @@ namespace Draw { auto proc_left = Config::getB("proc_left"); Cpu::box.clear(); - Gpu::box.clear(); + Mem::box.clear(); Net::box.clear(); Proc::box.clear(); @@ -1935,11 +1962,14 @@ namespace Draw { Cpu::x = Mem::x = Net::x = Proc::x = 1; Cpu::y = Mem::y = Net::y = Proc::y = 1; - Cpu::width = Gpu::width = Mem::width = Net::width = Proc::width = 0; + Cpu::width = Mem::width = Net::width = Proc::width = 0; Cpu::height = Mem::height = Net::height = Proc::height = 0; Cpu::redraw = Mem::redraw = Net::redraw = Proc::redraw = true; Cpu::shown = s_contains(boxes, "cpu"); + #ifdef GPU_SUPPORT + Gpu::box.clear(); + Gpu::width = 0; Gpu::shown_panels.clear(); if (not Gpu::gpu_names.empty()) { std::istringstream iss(boxes, std::istringstream::in); @@ -1954,6 +1984,7 @@ namespace Draw { ) Gpu::shown_panels.push_back(current.back()-'0'); } Gpu::shown = Gpu::shown_panels.size(); + #endif Mem::shown = s_contains(boxes, "mem"); Net::shown = s_contains(boxes, "net"); Proc::shown = s_contains(boxes, "proc"); @@ -1961,14 +1992,17 @@ namespace Draw { //* Calculate and draw cpu box outlines if (Cpu::shown) { using namespace Cpu; + #ifdef GPU_SUPPORT const bool show_gpu_on = Config::getS("show_gpu_info") == "On"; const bool gpus_shown_in_cpu_panel = Gpu::gpu_names.size() > 0 and ( show_gpu_on or (Config::getS("cpu_graph_lower") == "Auto" and Gpu::shown == 0) ); const int gpus_height_offset = (Gpu::gpu_names.size() - Gpu::shown)*gpus_shown_in_cpu_panel; int gpus_extra_height = gpus_shown_in_cpu_panel ? Gpu::gpu_names.size() - (show_gpu_on ? 0 : Gpu::shown) : 0; + #endif const bool show_temp = (Config::getB("check_temp") and got_sensors); width = round((double)Term::width * width_p / 100); + #ifdef GPU_SUPPORT if (Gpu::shown != 0 and not (Mem::shown or Net::shown or Proc::shown)) { height = Term::height - Gpu::min_height*Gpu::shown - gpus_height_offset; } else { @@ -1976,11 +2010,17 @@ namespace Draw { } if (height <= Term::height-gpus_height_offset) height += gpus_height_offset; if (height - gpus_extra_height < 7) gpus_extra_height = height - 7; - + #else + height = max(8, (int)ceil((double)Term::height * (trim(boxes) == "cpu" ? 100 : height_p) / 100)); + #endif x = 1; y = cpu_bottom ? Term::height - height + 1 : 1; + #ifdef GPU_SUPPORT b_columns = max(1, (int)ceil((double)(Shared::coreCount + 1) / (height - gpus_extra_height - 5))); + #else + b_columns = max(1, (int)ceil((double)(Shared::coreCount + 1) / (height - 5))); + #endif if (b_columns * (21 + 12 * show_temp) < width - (width / 3)) { b_column_size = 2; b_width = (21 + 12 * show_temp) * b_columns - (b_columns - 1); @@ -1998,7 +2038,11 @@ namespace Draw { } if (b_column_size == 0) b_width = (8 + 6 * show_temp) * b_columns + 1; + #ifdef GPU_SUPPORT b_height = min(height - 2, (int)ceil((double)Shared::coreCount / b_columns) + 4 + gpus_extra_height); + #else + b_height = min(height - 2, (int)ceil((double)Shared::coreCount / b_columns) + 4); + #endif b_x = x + width - b_width - 1; b_y = y + ceil((double)(height - 2) / 2) - ceil((double)b_height / 2) + 1; @@ -2010,6 +2054,7 @@ namespace Draw { box += createBox(b_x, b_y, b_width, b_height, "", false, cpu_title); } + #ifdef GPU_SUPPORT //* Calculate and draw gpu box outlines if (Gpu::shown != 0) { using namespace Gpu; @@ -2054,6 +2099,7 @@ namespace Draw { box[i] += createBox(b_x_vec[i], b_y_vec[i], b_width, b_height_vec[i], "", false, name.substr(0, b_width-5)); } } + #endif //* Calculate and draw mem box outlines if (Mem::shown) { @@ -2063,12 +2109,22 @@ namespace Draw { auto mem_graphs = Config::getB("mem_graphs"); width = round((double)Term::width * (Proc::shown ? width_p : 100) / 100); + #ifdef GPU_SUPPORT height = ceil((double)Term::height * (100 - Net::height_p * Net::shown*4 / ((Gpu::shown != 0 and Cpu::shown) + 4)) / 100) - Cpu::height - Gpu::height*Gpu::shown; + #else + height = ceil((double)Term::height * (100 - Cpu::height_p * Cpu::shown - Net::height_p * Net::shown) / 100) + 1; + #endif x = (proc_left and Proc::shown) ? Term::width - width + 1: 1; if (mem_below_net and Net::shown) + #ifdef GPU_SUPPORT y = Term::height - height + 1 - (cpu_bottom ? Cpu::height + Gpu::height*Gpu::shown : 0); else y = cpu_bottom ? 1 : Cpu::height + Gpu::height*Gpu::shown + 1; + #else + y = Term::height - height + 1 - (cpu_bottom ? Cpu::height : 0); + else + y = cpu_bottom ? 1 : Cpu::height + 1; + #endif if (show_disks) { mem_width = ceil((double)(width - 3) / 2); @@ -2117,10 +2173,18 @@ namespace Draw { if (Net::shown) { using namespace Net; width = round((double)Term::width * (Proc::shown ? width_p : 100) / 100); + #ifdef GPU_SUPPORT height = Term::height - Cpu::height - Gpu::height*Gpu::shown - Mem::height; + #else + height = Term::height - Cpu::height - Mem::height; + #endif x = (proc_left and Proc::shown) ? Term::width - width + 1 : 1; if (mem_below_net and Mem::shown) + #ifdef GPU_SUPPORT y = cpu_bottom ? 1 : Cpu::height + Gpu::height*Gpu::shown + 1; + #else + y = cpu_bottom ? 1 : Cpu::height + 1; + #endif else y = Term::height - height + 1 - (cpu_bottom ? Cpu::height : 0); @@ -2139,9 +2203,17 @@ namespace Draw { if (Proc::shown) { using namespace Proc; width = Term::width - (Mem::shown ? Mem::width : (Net::shown ? Net::width : 0)); + #ifdef GPU_SUPPORT height = Term::height - Cpu::height - Gpu::height*Gpu::shown; + #else + height = Term::height - Cpu::height; + #endif x = proc_left ? 1 : Term::width - width + 1; + #ifdef GPU_SUPPORT y = (cpu_bottom and Cpu::shown) ? 1 : Cpu::height + Gpu::height*Gpu::shown + 1; + #else + y = (cpu_bottom and Cpu::shown) ? 1 : Cpu::height + 1; + #endif select_max = height - 3; box = createBox(x, y, width, height, Theme::c("proc_box"), true, "proc", "", 4); } diff --git a/src/btop_input.cpp b/src/btop_input.cpp index 583582c..ce3ac48 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -271,11 +271,18 @@ namespace Input { } else if (key.size() == 1 and isint(key)) { auto intKey = stoi(key); + #ifdef GPU_SUPPORT + static const array<string, 10> boxes = {"gpu5", "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4"}; if ((intKey == 0 and Gpu::gpu_names.size() < 5) or (intKey >= 5 and std::cmp_less(Gpu::gpu_names.size(), intKey - 4))) return; + #else + static const array<string, 10> boxes = {"", "cpu", "mem", "net", "proc"}; + if (intKey == 0 or intKey > 4) + return; + #endif atomic_wait(Runner::active); Config::current_preset = -1; - static const array<string, 10> boxes = {"gpu5", "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4"}; + Config::toggle_box(boxes.at(intKey)); Draw::calcSizes(); Runner::run("all", false, true); diff --git a/src/btop_menu.cpp b/src/btop_menu.cpp index b217cd1..9b11f21 100644 --- a/src/btop_menu.cpp +++ b/src/btop_menu.cpp @@ -212,8 +212,10 @@ namespace Menu { {"shown_boxes", "Manually set which boxes to show.", "", - "Available values are \"cpu mem net proc\",", - "or \"gpu0\" through \"gpu5\" for GPU boxes.", + "Available values are \"cpu mem net proc\".", + #ifdef GPU_SUPPORT + "Or \"gpu0\" through \"gpu5\" for GPU boxes.", + #endif "Separate values with whitespace.", "", "Toggle between presets with key \"p\"."}, @@ -324,6 +326,7 @@ namespace Menu { "\"user\" = User mode cpu usage.", "\"system\" = Kernel mode cpu usage.", "+ more depending on kernel.", + #ifdef GPU_SUPPORT "", "GPU:", "\"gpu-totals\" = GPU usage split by device.", @@ -332,7 +335,9 @@ namespace Menu { "\"gpu-average\" = Avg usage of all GPUs.", "\"gpu-vram-total\" = VRAM usage of all GPUs.", "\"gpu-pwr-total\" = Power usage of all GPUs.", - "Not all stats are supported on all devices."}, + "Not all stats are supported on all devices." + #endif + }, {"cpu_graph_lower", "Cpu lower graph.", "", @@ -344,6 +349,7 @@ namespace Menu { "\"user\" = User mode cpu usage.", "\"system\" = Kernel mode cpu usage.", "+ more depending on kernel.", + #ifdef GPU_SUPPORT "", "GPU:", "\"gpu-totals\" = GPU usage split/device. (Auto)", @@ -352,7 +358,9 @@ namespace Menu { "\"gpu-average\" = Avg usage of all GPUs.", "\"gpu-vram-total\" = VRAM usage of all GPUs.", "\"gpu-pwr-total\" = Power usage of all GPUs.", - "Not all stats are supported on all devices."}, + "Not all stats are supported on all devices." + #endif + }, {"cpu_invert_lower", "Toggles orientation of the lower CPU graph.", "", @@ -364,6 +372,7 @@ namespace Menu { "to fit to box height.", "", "True or False."}, + #ifdef GPU_SUPPORT {"show_gpu_info", "Show gpu info in cpu box.", "", @@ -374,6 +383,7 @@ namespace Menu { "\"Auto\" to show when no gpu box is shown.", "\"On\" to always show.", "\"Off\" to never show."}, + #endif {"check_temp", "Enable cpu temperature reporting.", "", @@ -435,6 +445,7 @@ namespace Menu { "", "True or False."}, }, + #ifdef GPU_SUPPORT { {"nvml_measure_pcie_speeds", "Measure PCIe throughput on NVIDIA cards.", @@ -477,6 +488,7 @@ namespace Menu { "", "Empty string to disable."}, }, + #endif { {"mem_below_net", "Mem box location.", @@ -1096,7 +1108,6 @@ namespace Menu { {"proc_sorting", std::cref(Proc::sort_vector)}, {"graph_symbol", std::cref(Config::valid_graph_symbols)}, {"graph_symbol_cpu", std::cref(Config::valid_graph_symbols_def)}, - {"graph_symbol_gpu", std::cref(Config::valid_graph_symbols_def)}, {"graph_symbol_mem", std::cref(Config::valid_graph_symbols_def)}, {"graph_symbol_net", std::cref(Config::valid_graph_symbols_def)}, {"graph_symbol_proc", std::cref(Config::valid_graph_symbols_def)}, @@ -1104,7 +1115,10 @@ namespace Menu { {"cpu_graph_lower", std::cref(Cpu::available_fields)}, {"cpu_sensor", std::cref(Cpu::available_sensors)}, {"selected_battery", std::cref(Config::available_batteries)}, - {"show_gpu_info", std::cref(Config::show_gpu_values)} + #ifdef GPU_SUPPORT + {"show_gpu_info", std::cref(Config::show_gpu_values)}, + {"graph_symbol_gpu", std::cref(Config::valid_graph_symbols_def)}, + #endif }; auto tty_mode = Config::getB("tty_mode"); auto vim_keys = Config::getB("vim_keys"); @@ -1336,11 +1350,19 @@ namespace Menu { //? Category buttons out += Mv::to(y+7, x+4); + #ifdef GPU_SUPPORT for (int i = 0; const auto& m : {"general", "cpu", "gpu", "mem", "net", "proc"}) { + #else + for (int i = 0; const auto& m : {"general", "cpu", "mem", "net", "proc"}) { + #endif out += Fx::b + (i == selected_cat ? Theme::c("hi_fg") + '[' + Theme::c("title") + m + Theme::c("hi_fg") + ']' : Theme::c("hi_fg") + to_string(i + 1) + Theme::c("title") + m + ' ') + #ifdef GPU_SUPPORT + Mv::r(7); + #else + + Mv::r(10); + #endif if (string button_name = "select_cat_" + to_string(i + 1); not editing and not mouse_mappings.contains(button_name)) mouse_mappings[button_name] = {y+6, x+2 + 15*i, 3, 15}; i++; diff --git a/src/btop_shared.cpp b/src/btop_shared.cpp index bb7a9f6..b2f70a8 100644 --- a/src/btop_shared.cpp +++ b/src/btop_shared.cpp @@ -24,6 +24,7 @@ tab-size = 4 namespace rng = std::ranges; using namespace Tools; +#ifdef GPU_SUPPORT namespace Gpu { vector<string> gpu_names; vector<int> gpu_b_height_offsets; @@ -34,6 +35,7 @@ namespace Gpu { }; long long gpu_pwr_total_max; } +#endif namespace Proc { void proc_sorter(vector<proc_info>& proc_vec, const string& sorting, bool reverse, bool tree) { diff --git a/src/btop_shared.hpp b/src/btop_shared.hpp index 1d1c71c..383e189 100644 --- a/src/btop_shared.hpp +++ b/src/btop_shared.hpp @@ -87,6 +87,7 @@ namespace Shared { namespace Gpu { +#ifdef GPU_SUPPORT extern vector<string> box; extern int width, height, min_width, min_height; extern vector<int> x_vec, y_vec; @@ -151,20 +152,23 @@ namespace Gpu { // vector<proc_info> compute_processes = {}; }; -#ifdef __linux__ namespace Nvml { extern bool shutdown(); } namespace Rsmi { extern bool shutdown(); } -#endif //* Collect gpu stats and temperatures auto collect(bool no_update = false) -> vector<gpu_info>&; //* Draw contents of gpu box using <gpus> as source string draw(const gpu_info& gpu, unsigned long index, bool force_redraw, bool data_same); +#else + struct gpu_info { + bool supported = false; + }; +#endif } namespace Cpu { diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp index 648cf64..75adae9 100644 --- a/src/btop_tools.cpp +++ b/src/btop_tools.cpp @@ -103,21 +103,27 @@ namespace Term { bool mem = boxes.find("mem") != string::npos; bool net = boxes.find("net") != string::npos; bool proc = boxes.find("proc") != string::npos; - int gpu = 0; + #ifdef GPU_SUPPORT + int gpu = 0; if (not Gpu::gpu_names.empty()) for (char i = '0'; i <= '5'; ++i) gpu += (boxes.find(std::string("gpu") + i) != string::npos); + #endif int width = 0; if (mem) width = Mem::min_width; else if (net) width = Mem::min_width; width += (proc ? Proc::min_width : 0); if (cpu and width < Cpu::min_width) width = Cpu::min_width; + #ifdef GPU_SUPPORT if (gpu != 0 and width < Gpu::min_width) width = Gpu::min_width; + #endif int height = (cpu ? Cpu::min_height : 0); if (proc) height += Proc::min_height; else height += (mem ? Mem::min_height : 0) + (net ? Net::min_height : 0); + #ifdef GPU_SUPPORT height += Gpu::min_height*gpu; + #endif return { width, height }; } diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 8ed9fa3..9899224 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -96,6 +96,7 @@ namespace Cpu { namespace Gpu { vector<gpu_info> gpus; +#ifdef GPU_SUPPORT //? NVIDIA data collection namespace Nvml { //? NVML defines, structs & typedefs @@ -190,6 +191,7 @@ namespace Gpu { template <bool is_init> bool collect(gpu_info* gpus_slice); uint32_t device_count = 0; } +#endif } namespace Mem { @@ -252,6 +254,7 @@ namespace Shared { Cpu::core_mapping = Cpu::get_core_mapping(); //? Init for namespace Gpu + #ifdef GPU_SUPPORT Gpu::Nvml::init(); Gpu::Rsmi::init(); if (not Gpu::gpu_names.empty()) { @@ -268,6 +271,7 @@ namespace Shared { + (gpus[i].supported_functions.mem_total or gpus[i].supported_functions.mem_used) * (1 + 2*(gpus[i].supported_functions.mem_total and gpus[i].supported_functions.mem_used) + 2*gpus[i].supported_functions.mem_utilization); } + #endif //? Init for namespace Mem Mem::old_uptime = system_uptime(); @@ -928,6 +932,7 @@ namespace Cpu { } } +#ifdef GPU_SUPPORT namespace Gpu { //? NVIDIA namespace Nvml { @@ -973,7 +978,7 @@ namespace Gpu { //? Function calls nvmlReturn_t result = nvmlInit(); if (result != NVML_SUCCESS) { - Logger::warning(std::string("Failed to initialize NVML, NVIDIA GPUs will not be detected: ") + nvmlErrorString(result)); + Logger::debug(std::string("Failed to initialize NVML, NVIDIA GPUs will not be detected: ") + nvmlErrorString(result)); return false; } @@ -1203,10 +1208,10 @@ namespace Gpu { rsmi_dl_handle = dlopen("/opt/rocm/lib/librocm_smi64.so", RTLD_LAZY); // first try /lib and /usr/lib, then /opt/rocm/lib if that fails if (dlerror() != NULL) { rsmi_dl_handle = dlopen("librocm_smi64.so", RTLD_LAZY); - if (!rsmi_dl_handle) { - Logger::info(std::string("Failed to load librocm_smi64.so, AMD GPUs will not be detected: ") + dlerror()); - return false; - } + } + if (!rsmi_dl_handle) { + Logger::debug(std::string("Failed to load librocm_smi64.so, AMD GPUs will not be detected: ") + dlerror()); + return false; } auto load_rsmi_sym = [&](const char sym_name[]) { @@ -1468,6 +1473,7 @@ namespace Gpu { return gpus; } } +#endif namespace Mem { bool has_swap{}; // defaults to false |