summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob P. Liljenberg <admin@qvantnet.com>2023-09-28 18:20:42 +0200
committerGitHub <noreply@github.com>2023-09-28 18:20:42 +0200
commitd16adc9fd03322d46f1b84e5ebe7d426f726a5cc (patch)
tree3f19f3da64802a6e3a2623d6e040774a0d079f26
parent2c3ac4855de49563edd4ef199b0be74babc7ce32 (diff)
parentf34b40892fef31f657cbe8066c8b0d41ed37c0fc (diff)
Merge pull request #618 from nobounce/aggregate-child-processes
Add option to accumulate a child's resources in parent in tree-view
-rw-r--r--src/btop_config.cpp3
-rw-r--r--src/btop_draw.cpp12
-rw-r--r--src/btop_menu.cpp5
-rw-r--r--src/btop_shared.cpp7
4 files changed, 26 insertions, 1 deletions
diff --git a/src/btop_config.cpp b/src/btop_config.cpp
index 6010189..fc71e41 100644
--- a/src/btop_config.cpp
+++ b/src/btop_config.cpp
@@ -107,6 +107,8 @@ namespace Config {
{"proc_filter_kernel", "#* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop)."},
+ {"proc_aggregate", "#* In tree-view, always accumulate child process resources in the parent process."},
+
{"cpu_graph_upper", "#* Sets the CPU stat shown in upper half of the CPU graph, \"total\" is always available.\n"
"#* Select from a list of detected attributes from the options menu."},
@@ -268,6 +270,7 @@ namespace Config {
{"lowcolor", false},
{"show_detailed", false},
{"proc_filtering", false},
+ {"proc_aggregate", false},
};
unordered_flat_map<std::string_view, bool> boolsTmp;
diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp
index a4cbb95..57edda8 100644
--- a/src/btop_draw.cpp
+++ b/src/btop_draw.cpp
@@ -20,6 +20,7 @@ tab-size = 4
#include <algorithm>
#include <cmath>
#include <ranges>
+#include <string>
#include "btop_draw.hpp"
#include "btop_config.hpp"
@@ -1529,7 +1530,16 @@ namespace Proc {
else mem_str.resize((mem_p < 10 or mem_p >= 100 ? 3 : 4));
mem_str += '%';
}
- out += (thread_size > 0 ? t_color + rjust(to_string(min(p.threads, (size_t)9999)), thread_size) + ' ' + end : "" )
+
+ // Shorten process thread representation when larger than 5 digits: 10000 -> 10K ...
+ std::string proc_threads_string;
+ if (p.threads > 9999) {
+ proc_threads_string = std::to_string(p.threads / 1000) + 'K';
+ } else {
+ proc_threads_string = std::to_string(p.threads);
+ }
+
+ out += (thread_size > 0 ? t_color + rjust(proc_threads_string, thread_size) + ' ' + end : "" )
+ g_color + ljust((cmp_greater(p.user.size(), user_size) ? p.user.substr(0, user_size - 1) + '+' : p.user), user_size) + ' '
+ m_color + rjust(mem_str, 5) + end + ' '
+ (is_selected ? "" : Theme::c("inactive_fg")) + (show_graphs ? graph_bg * 5: "")
diff --git a/src/btop_menu.cpp b/src/btop_menu.cpp
index c9dfbdc..663ac4f 100644
--- a/src/btop_menu.cpp
+++ b/src/btop_menu.cpp
@@ -589,6 +589,11 @@ namespace Menu {
"Set true to show processes grouped by",
"parents with lines drawn between parent",
"and child process."},
+ {"proc_aggregate",
+ "Aggregate child's resources in parent.",
+ "",
+ "In tree-view, include all child resources",
+ "with the parent even while expanded."},
{"proc_colors",
"Enable colors in process view.",
"",
diff --git a/src/btop_shared.cpp b/src/btop_shared.cpp
index e5c9027..98c24ce 100644
--- a/src/btop_shared.cpp
+++ b/src/btop_shared.cpp
@@ -18,6 +18,7 @@ tab-size = 4
#include <ranges>
+#include "btop_config.hpp"
#include "btop_shared.hpp"
#include "btop_tools.hpp"
@@ -156,6 +157,12 @@ namespace Proc {
filter_found++;
p.filtered = true;
}
+ else if (Config::getB("proc_aggregate")) {
+ cur_proc.cpu_p += p.cpu_p;
+ cur_proc.cpu_c += p.cpu_c;
+ cur_proc.mem += p.mem;
+ cur_proc.threads += p.threads;
+ }
}
if (collapsed or filtering) {
return;