From f5a7b6038bbc869b474d6ab8cbab936295bbd41c Mon Sep 17 00:00:00 2001 From: Brett Jia Date: Thu, 16 Jan 2025 21:49:58 -0500 Subject: [PATCH] enable GPU by default --- CMakeLists.txt | 4 +- src/cosmotop.cpp | 30 ++------------ src/cosmotop_config.cpp | 18 ++------ src/cosmotop_config.hpp | 10 ++--- src/cosmotop_draw.cpp | 76 +++------------------------------- src/cosmotop_input.cpp | 6 --- src/cosmotop_menu.cpp | 24 ----------- src/cosmotop_plugin.cpp | 8 ---- src/cosmotop_shared.hpp | 12 ------ src/cosmotop_tools_host.cpp | 8 +--- src/linux/cosmotop_collect.cpp | 6 --- 11 files changed, 19 insertions(+), 183 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38770b0..348d52e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,7 +83,7 @@ if(${TARGET} STREQUAL "host") find_package(Threads REQUIRED) target_link_libraries(cosmotop.com Threads::Threads) - target_compile_definitions(cosmotop.com PRIVATE GPU_SUPPORT FMT_HEADER_ONLY _FILE_OFFSET_BITS=64) + target_compile_definitions(cosmotop.com PRIVATE FMT_HEADER_ONLY _FILE_OFFSET_BITS=64) elseif(${TARGET} STREQUAL "plugin") @@ -179,7 +179,7 @@ elseif(${TARGET} STREQUAL "plugin") endif() target_include_directories(${BINARY_NAME} PRIVATE ${THIRD_PARTY_INCLUDES}) - target_compile_definitions(${BINARY_NAME} PRIVATE GPU_SUPPORT FMT_HEADER_ONLY _FILE_OFFSET_BITS=64) + target_compile_definitions(${BINARY_NAME} PRIVATE FMT_HEADER_ONLY _FILE_OFFSET_BITS=64) if(CMAKE_SYSTEM MATCHES "Windows") target_compile_options(${BINARY_NAME} PRIVATE /utf-8) target_compile_definitions(${BINARY_NAME} PRIVATE UNICODE _UNICODE) diff --git a/src/cosmotop.cpp b/src/cosmotop.cpp index 57ae038..6d534b3 100644 --- a/src/cosmotop.cpp +++ b/src/cosmotop.cpp @@ -265,11 +265,7 @@ void term_resize(bool force) { if (force and refreshed) force = false; } else return; -#ifdef GPU_SUPPORT static const array all_boxes = {"gpu5", "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4"}; -#else - static const array all_boxes = {"", "cpu", "mem", "net", "proc"}; -#endif Global::resized = true; if (Runner::active) Runner::stop(); Term::refresh(); @@ -309,12 +305,8 @@ void term_resize(bool force) { clean_quit(0); else if (key.size() == 1 and isint(key)) { auto intKey = stoi(key); - #ifdef GPU_SUPPORT auto gpu_count = Gpu::get_count(); if ((intKey == 0 and gpu_count >= 5) or (intKey >= 5 and intKey - 4 <= gpu_count)) { - #else - if (intKey > 0 and intKey < 5) { - #endif auto box = all_boxes.at(intKey); Config::current_preset = -1; Config::toggle_box(box); @@ -353,10 +345,8 @@ void clean_quit(int sig) { #endif } -#ifdef GPU_SUPPORT Gpu::Nvml::shutdown(); Gpu::Rsmi::shutdown(); -#endif Config::write(); @@ -620,13 +610,7 @@ namespace Runner { //! DEBUG stats if (Global::debug) { if (debug_bg.empty() or redraw) - Runner::debug_bg = Draw::createBox(2, 2, 33, - #ifdef GPU_SUPPORT - 9, - #else - 8, - #endif - "", true, "μs"); + Runner::debug_bg = Draw::createBox(2, 2, 33, 9, "", true, "μs"); debug_times.clear(); debug_times["total"] = {0, 0}; @@ -636,7 +620,6 @@ namespace Runner { //* Run collection and draw functions for all boxes try { - #ifdef GPU_SUPPORT //? GPU data collection const bool gpu_in_cpu_panel = Gpu::get_gpu_names().size() > 0 and ( Config::getS("cpu_graph_lower").starts_with("gpu-") or Config::getS("cpu_graph_upper").starts_with("gpu-") @@ -655,9 +638,6 @@ namespace Runner { if (Global::debug) debug_timer("gpu", collect_done); } auto& gpus_ref = gpus; - #else - vector gpus_ref{}; - #endif //? CPU if (v_contains(conf.boxes, "cpu")) { @@ -686,7 +666,7 @@ namespace Runner { throw std::runtime_error("Cpu:: -> " + string{e.what()}); } } - #ifdef GPU_SUPPORT + //? GPU if (not gpu_panels.empty() and not gpus_ref.empty()) { try { @@ -703,7 +683,7 @@ namespace Runner { throw std::runtime_error("Gpu:: -> " + string{e.what()}); } } - #endif + //? MEM if (v_contains(conf.boxes, "mem")) { try { @@ -820,11 +800,7 @@ 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/cosmotop_config.cpp b/src/cosmotop_config.cpp index a925a7e..39fab80 100644 --- a/src/cosmotop_config.cpp +++ b/src/cosmotop_config.cpp @@ -76,9 +76,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\"."}, @@ -124,9 +124,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."}, @@ -209,7 +209,6 @@ namespace Config { {"log_level", "#* Set loglevel for \"~/.config/cosmotop/cosmotop.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."}, @@ -225,7 +224,6 @@ namespace Config { {"intel_gpu_exporter", "#* HTTP endpoint to pull Intel GPU metrics from, if Intel PMU is not available.\n" "#* Use with https://github.com/bjia56/intel-gpu-exporter"}, - #endif }; std::unordered_map strings = { @@ -256,7 +254,6 @@ namespace Config { {"proc_command", ""}, {"selected_name", ""}, {"detailed_name", ""}, - #ifdef GPU_SUPPORT {"custom_gpu_name0", ""}, {"custom_gpu_name1", ""}, {"custom_gpu_name2", ""}, @@ -265,7 +262,6 @@ namespace Config { {"custom_gpu_name5", ""}, {"show_gpu_info", "Auto"}, {"intel_gpu_exporter", ""} - #endif }; std::unordered_map stringsTmp; @@ -317,11 +313,9 @@ namespace Config { {"show_detailed", false}, {"proc_filtering", false}, {"proc_aggregate", false}, - #ifdef GPU_SUPPORT {"nvml_measure_pcie_speeds", true}, {"rsmi_measure_pcie_speeds", true}, {"gpu_mirror_graph", true} - #endif }; std::unordered_map boolsTmp; @@ -556,10 +550,8 @@ namespace Config { return true; } - #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; @@ -663,12 +655,10 @@ 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")) { int gpu_num = stoi(box.substr(3)) + 1; if (gpu_num > Gpu::get_count()) return false; } - #endif } current_boxes = std::move(new_boxes); return true; diff --git a/src/cosmotop_config.hpp b/src/cosmotop_config.hpp index 665dd95..cb51b39 100644 --- a/src/cosmotop_config.hpp +++ b/src/cosmotop_config.hpp @@ -45,15 +45,11 @@ namespace Config { const vector valid_graph_symbols = { "braille", "block", "tty" }; const vector valid_graph_symbols_def = { "default", "braille", "block", "tty" }; const vector valid_boxes = { - "cpu", "mem", "net", "proc" -#ifdef GPU_SUPPORT - ,"gpu0", "gpu1", "gpu2", "gpu3", "gpu4", "gpu5" -#endif - }; + "cpu", "mem", "net", "proc", + "gpu0", "gpu1", "gpu2", "gpu3", "gpu4", "gpu5" + }; const vector temp_scales = { "celsius", "fahrenheit", "kelvin", "rankine" }; -#ifdef GPU_SUPPORT const vector show_gpu_values = { "Auto", "On", "Off" }; -#endif extern vector current_boxes; extern vector preset_list; extern vector available_batteries; diff --git a/src/cosmotop_draw.cpp b/src/cosmotop_draw.cpp index 35a8b32..3ae2d88 100644 --- a/src/cosmotop_draw.cpp +++ b/src/cosmotop_draw.cpp @@ -536,26 +536,20 @@ namespace Cpu { auto single_graph = Config::getB("cpu_single_graph"); bool hide_cores = show_temps and (get_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 + auto gpu_count = Gpu::get_count(); const auto& show_gpu_info = Config::getS("show_gpu_info"); const bool gpu_always = show_gpu_info == "On"; const bool gpu_auto = show_gpu_info == "Auto"; const bool show_gpu = (gpus.size() > 0 and (gpu_always or (gpu_auto and Gpu::shown < gpu_count))); - #else - (void)gpus; - #endif + auto available_fields = Cpu::get_available_fields(); auto graph_up_field = Config::getS("cpu_graph_upper"); if (graph_up_field == "Auto" or not v_contains(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(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")); @@ -603,7 +597,6 @@ namespace Cpu { const int graph_default_width = x + width - b_width - 3; auto init_graphs = [&](vector& 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,20 +630,16 @@ namespace Cpu { } } else { - #endif graphs.resize(1); graph_width = graph_default_width; graphs[0] = Draw::Graph{ graph_width, graph_height, "cpu", safeVal(cpu.cpu_percent, graph_field), graph_symbol, invert, true }; - #ifdef GPU_SUPPORT } - #endif }; init_graphs(graphs_upper, graph_up_height, graph_up_width, graph_up_field, false); if (not single_graph) init_graphs(graphs_lower, graph_low_height, graph_low_width, graph_lo_field, Config::getB("cpu_invert_lower")); - #ifdef GPU_SUPPORT if (show_gpu and b_columns > 1) { gpu_temp_graphs.resize(gpus.size()); gpu_mem_graphs.resize(gpus.size()); @@ -679,7 +668,6 @@ namespace Cpu { } } } - #endif cpu_meter = Draw::Meter{b_width - (show_temps ? 23 - (b_column_size <= 1 and b_columns == 1 ? 6 : 0) : 11), "cpu"}; @@ -755,7 +743,6 @@ namespace Cpu { //? Cpu/Gpu graphs out += Fx::ub + Mv::to(y + 1, x + 1); auto draw_graphs = [&](vector& 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.ends_with("totals")) { int gpu_drawn = 0; @@ -776,10 +763,6 @@ namespace Cpu { else out += graphs[0](safeVal(Gpu::get_shared_gpu_percent(), graph_field), (data_same or redraw)); else - #else - (void)graph_height; - (void)graph_width; - #endif out += graphs[0](safeVal(cpu.cpu_percent, graph_field), (data_same or redraw)); }; @@ -867,15 +850,10 @@ 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) { @@ -921,7 +899,6 @@ namespace Cpu { if (cy > b_height - 1) break; } } - #endif redraw = false; return out + Fx::reset; @@ -929,7 +906,6 @@ namespace Cpu { } -#ifdef GPU_SUPPORT namespace Gpu { int width_p = 100, height_p = 32; int min_width = 41, min_height = 11; @@ -1100,7 +1076,6 @@ namespace Gpu { } } -#endif namespace Mem { int width_p = 45, height_p = 36; @@ -2001,7 +1976,6 @@ namespace Draw { Cpu::redraw = Mem::redraw = Net::redraw = Proc::redraw = true; Cpu::shown = s_contains(boxes, "cpu"); - #ifdef GPU_SUPPORT auto gpu_count = Gpu::get_count(); Gpu::box.clear(); Gpu::width = 0; @@ -2016,7 +1990,6 @@ namespace Draw { } 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"); @@ -2027,32 +2000,24 @@ namespace Draw { auto coreCount = Shared::get_coreCount(); auto got_sensors = get_got_sensors(); - #ifdef GPU_SUPPORT int gpus_extra_height = Config::getS("show_gpu_info") == "On" ? gpu_count : Config::getS("show_gpu_info") == "Auto" ? gpu_count - 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_extra_height; } else { height = max(8, (int)ceil((double)Term::height * (trim(boxes) == "cpu" ? 100 : height_p/(Gpu::shown+1) + (Gpu::shown != 0)*5) / 100)); } if (height <= Term::height-gpus_extra_height) height += gpus_extra_height; - #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(2, (int)ceil((double)(coreCount + 1) / (height - gpus_extra_height - 5))); - #else - b_columns = max(1, (int)ceil((double)(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); @@ -2070,12 +2035,9 @@ namespace Draw { } if (b_column_size == 0) b_width = (8 + 6 * show_temp) * b_columns + 1; - #ifdef GPU_SUPPORT + //gpus_extra_height = max(0, gpus_extra_height - 1); b_height = min(height - 2, (int)ceil((double)coreCount / b_columns) + 4 + gpus_extra_height); - #else - b_height = min(height - 2, (int)ceil((double)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; @@ -2091,7 +2053,6 @@ 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; @@ -2138,7 +2099,6 @@ 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) { @@ -2149,22 +2109,12 @@ namespace Draw { auto has_swap = get_has_swap(); 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); @@ -2213,18 +2163,10 @@ 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); @@ -2243,17 +2185,9 @@ 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/cosmotop_input.cpp b/src/cosmotop_input.cpp index ba0ca67..a12e78e 100644 --- a/src/cosmotop_input.cpp +++ b/src/cosmotop_input.cpp @@ -232,16 +232,10 @@ namespace Input { } else if (key.size() == 1 and isint(key)) { auto intKey = stoi(key); - #ifdef GPU_SUPPORT static const array boxes = {"gpu5", "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4"}; auto gpu_count = Gpu::get_count(); if ((intKey == 0 and gpu_count < 5) or (intKey >= 5 and intKey - 4 > gpu_count)) return; - #else - static const array boxes = {"", "cpu", "mem", "net", "proc"}; - if (intKey == 0 or intKey > 4) - return; - #endif atomic_wait(Runner::active); if (not Config::toggle_box(boxes.at(intKey))) { diff --git a/src/cosmotop_menu.cpp b/src/cosmotop_menu.cpp index ec85e72..e57a3ce 100644 --- a/src/cosmotop_menu.cpp +++ b/src/cosmotop_menu.cpp @@ -272,9 +272,7 @@ namespace Menu { "Manually set which boxes to show.", "", "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\"."}, @@ -390,7 +388,6 @@ 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.", @@ -400,7 +397,6 @@ namespace Menu { "\"gpu-vram-total\" = VRAM usage of all GPUs.", "\"gpu-pwr-total\" = Power usage of all GPUs.", "Not all stats are supported on all devices." - #endif }, {"cpu_graph_lower", "Cpu lower graph.", @@ -413,7 +409,6 @@ 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)", @@ -423,7 +418,6 @@ namespace Menu { "\"gpu-vram-total\" = VRAM usage of all GPUs.", "\"gpu-pwr-total\" = Power usage of all GPUs.", "Not all stats are supported on all devices." - #endif }, {"cpu_invert_lower", "Toggles orientation of the lower CPU graph.", @@ -436,7 +430,6 @@ namespace Menu { "to fit to box height.", "", "True or False."}, - #ifdef GPU_SUPPORT {"show_gpu_info", "Show gpu info in cpu box.", "", @@ -447,7 +440,6 @@ 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.", "", @@ -509,7 +501,6 @@ namespace Menu { "", "True or False."}, }, - #ifdef GPU_SUPPORT { {"nvml_measure_pcie_speeds", "Measure PCIe throughput on NVIDIA cards.", @@ -568,7 +559,6 @@ namespace Menu { "", "Empty string to disable."}, }, - #endif { {"mem_below_net", "Mem box location.", @@ -1200,10 +1190,8 @@ namespace Menu { {"cpu_graph_lower", std::cref(Cpu::get_available_fields())}, {"cpu_sensor", std::cref(Cpu::get_available_sensors())}, {"selected_battery", std::cref(Config::available_batteries)}, - #ifdef GPU_SUPPORT {"show_gpu_info", std::cref(Config::show_gpu_values)}, {"graph_symbol_gpu", std::cref(Config::valid_graph_symbols_def)}, - #endif }; // ensure the following fields are updated from the plugin @@ -1342,11 +1330,7 @@ namespace Menu { if (--selected_cat < 0) selected_cat = (int)categories.size() - 1; page = selected = 0; } -#ifdef GPU_SUPPORT else if (is_in(key, "1", "2", "3", "4", "5", "6") or key.starts_with("select_cat_")) { -#else - else if (is_in(key, "1", "2", "3", "4", "5") or key.starts_with("select_cat_")) { -#endif selected_cat = key.back() - '0' - 1; page = selected = 0; } @@ -1444,19 +1428,11 @@ 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/cosmotop_plugin.cpp b/src/cosmotop_plugin.cpp index be5be79..d0dd24b 100644 --- a/src/cosmotop_plugin.cpp +++ b/src/cosmotop_plugin.cpp @@ -41,7 +41,6 @@ void plugin_initializer(Plugin* plugin) { return ss.str(); })); -#ifdef GPU_SUPPORT plugin->registerHandler("Gpu::Nvml::shutdown", std::function([]() { #ifdef __linux__ return Gpu::Nvml::shutdown(); @@ -91,7 +90,6 @@ void plugin_initializer(Plugin* plugin) { return unordered_map>(); #endif })); -#endif plugin->registerHandler("Cpu::collect", std::function([](bool no_update) { return Cpu::collect(no_update); @@ -262,13 +260,11 @@ namespace Cpu { } } -#ifdef GPU_SUPPORT namespace Gpu { int get_width() { return plugin->call("Gpu::get_width"); } } -#endif namespace Net{ int get_width() { @@ -474,11 +470,9 @@ void create_plugin_host() { return Cpu::width; })); -#ifdef GPU_SUPPORT pluginHost->registerHandler("Gpu::get_width", std::function([]() { return Gpu::width; })); -#endif pluginHost->registerHandler("Net::get_width", std::function([]() { return Net::width; @@ -525,7 +519,6 @@ string plugin_build_info() { return pluginHost->call("build_info"); } -#ifdef GPU_SUPPORT namespace Gpu { bool Nvml::shutdown() { return pluginHost->call("Gpu::Nvml::shutdown"); @@ -557,7 +550,6 @@ namespace Gpu { return result; } } -#endif namespace Cpu { cpu_info& collect(bool no_update) { diff --git a/src/cosmotop_shared.hpp b/src/cosmotop_shared.hpp index b879972..ebd0924 100644 --- a/src/cosmotop_shared.hpp +++ b/src/cosmotop_shared.hpp @@ -127,7 +127,6 @@ namespace Shared { namespace Gpu { -#ifdef GPU_SUPPORT extern vector box; extern int width, height, min_width, min_height; extern vector x_vec, y_vec; @@ -151,12 +150,6 @@ namespace Gpu { const array mem_names { "used"s, "free"s }; - //* Container for process information // TODO - /*struct proc_info { - unsigned int pid; - unsigned long long mem; - };*/ - //* Container for supported Gpu::*::collect() functions struct gpu_info_supported { bool gpu_utilization = true, @@ -213,11 +206,6 @@ namespace Gpu { //* Draw contents of gpu box using 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/cosmotop_tools_host.cpp b/src/cosmotop_tools_host.cpp index da390c9..3601608 100644 --- a/src/cosmotop_tools_host.cpp +++ b/src/cosmotop_tools_host.cpp @@ -122,27 +122,23 @@ namespace Term { bool mem = boxes.find("mem") != string::npos; bool net = boxes.find("net") != string::npos; bool proc = boxes.find("proc") != string::npos; - #ifdef GPU_SUPPORT + int gpu = 0; if (Gpu::get_count() > 0) for (char i = '0'; i <= '5'; i++) gpu += (Tools::s_contains(boxes, "gpu"s + i) ? 1 : 0); - #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/cosmotop_collect.cpp b/src/linux/cosmotop_collect.cpp index c235b9a..986ca6b 100644 --- a/src/linux/cosmotop_collect.cpp +++ b/src/linux/cosmotop_collect.cpp @@ -117,7 +117,6 @@ namespace Cpu { namespace Gpu { vector gpus; -#ifdef GPU_SUPPORT vector gpu_names; vector gpu_b_height_offsets; std::unordered_map> shared_gpu_percent = { @@ -247,7 +246,6 @@ namespace Gpu { template bool collect(gpu_info* gpus_slice); uint32_t device_count = 0; } -#endif } namespace Mem { @@ -310,7 +308,6 @@ namespace Shared { Cpu::core_mapping = Cpu::get_core_mapping(); //? Init for namespace Gpu - #ifdef GPU_SUPPORT Gpu::Nvml::init(); Gpu::Rsmi::init(); Gpu::Intel::init(); @@ -329,7 +326,6 @@ 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(); @@ -1037,7 +1033,6 @@ namespace Cpu { } } -#ifdef GPU_SUPPORT namespace Gpu { //? NVIDIA namespace Nvml { @@ -1869,7 +1864,6 @@ namespace Gpu { return gpus; } } -#endif namespace Mem { bool has_swap{};