Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ namespace Runner {

//* Run collection and draw functions for all boxes
try {
#ifdef GPU_SUPPORT
#if defined(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-")
Expand All @@ -555,9 +555,7 @@ namespace Runner {
if (Global::debug) debug_timer("gpu", collect_done);
}
auto& gpus_ref = gpus;
#else
vector<Gpu::gpu_info> gpus_ref{};
#endif
#endif // GPU_SUPPORT

//? CPU
if (v_contains(conf.boxes, "cpu")) {
Expand All @@ -578,7 +576,16 @@ namespace Runner {
if (Global::debug) debug_timer("cpu", draw_begin);

//? Draw box
if (not pause_output) output += Cpu::draw(cpu, gpus_ref, conf.force_redraw, conf.no_update);
if (not pause_output) {
output += Cpu::draw(
cpu,
#if defined(GPU_SUPPORT)
gpus_ref,
#endif // GPU_SUPPORT
conf.force_redraw,
conf.no_update
);
}

if (Global::debug) debug_timer("cpu", draw_done);
}
Expand Down
15 changes: 10 additions & 5 deletions src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,22 +537,27 @@ namespace Cpu {
vector<Draw::Graph> gpu_temp_graphs;
vector<Draw::Graph> gpu_mem_graphs;

string draw(const cpu_info& cpu, const vector<Gpu::gpu_info>& gpus, bool force_redraw, bool data_same) {
string draw(
const cpu_info& cpu,
#if defined(GPU_SUPPORT)
const vector<Gpu::gpu_info>& gpus,
#endif // GPU_SUPPORT
bool force_redraw,
bool data_same
) {
if (Runner::stopping) return "";
if (force_redraw) redraw = true;
bool show_temps = (Config::getB("check_temp") and got_sensors);
bool show_watts = (Config::getB("show_cpu_watts") and supports_watts);
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) : (b_columns == 1 && !show_temps) ? 8 : 0);
#ifdef GPU_SUPPORT
#if defined(GPU_SUPPORT)
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
#endif // GPU_SUPPORT
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";
Expand Down
18 changes: 11 additions & 7 deletions src/btop_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ namespace Shared {
#endif
}

#if defined(GPU_SUPPORT)

namespace Gpu {
#ifdef GPU_SUPPORT
extern vector<string> box;
extern int width, total_height, min_width, min_height;
extern vector<int> x_vec, y_vec;
Expand Down Expand Up @@ -189,13 +189,10 @@ namespace Gpu {

//* 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
}

#endif // GPU_SUPPORT

namespace Cpu {
extern string box;
extern int x, y, width, height, min_width, min_height;
Expand Down Expand Up @@ -232,7 +229,14 @@ namespace Cpu {
auto collect(bool no_update = false) -> cpu_info&;

//* Draw contents of cpu box using <cpu> as source
string draw(const cpu_info& cpu, const vector<Gpu::gpu_info>& gpu, bool force_redraw = false, bool data_same = false);
string draw(
const cpu_info& cpu,
#if defined(GPU_SUPPORT)
const vector<Gpu::gpu_info>& gpu,
#endif
bool force_redraw = false,
bool data_same = false
);

//* Parse /proc/cpu info for mapping of core ids
auto get_core_mapping() -> std::unordered_map<int, int>;
Expand Down
6 changes: 4 additions & 2 deletions src/linux/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ namespace Cpu {
std::unordered_map<int, int> core_mapping;
}

#if defined(GPU_SUPPORT)

namespace Gpu {
vector<gpu_info> gpus;
#ifdef GPU_SUPPORT
//? NVIDIA data collection
namespace Nvml {
//? NVML defines, structs & typedefs
Expand Down Expand Up @@ -254,9 +255,10 @@ namespace Gpu {
template <bool is_init> bool collect(gpu_info* gpus_slice);
uint32_t device_count = 0;
}
#endif
}

#endif // GPU_SUPPORT

namespace Mem {
double old_uptime;
}
Expand Down
Loading