Moved to correct version of the code

This commit is contained in:
0xJoeMama 2022-05-20 23:35:41 +03:00
parent c257938d46
commit e1341a17cb
No known key found for this signature in database
GPG Key ID: 6E0A65853073294E
2 changed files with 27 additions and 3 deletions

View File

@ -1,3 +1,4 @@
// clang-format off
/* Copyright 2021 Aristocratos (jakob@qvantnet.com)
Licensed under the Apache License, Version 2.0 (the "License");
@ -96,6 +97,8 @@ namespace Config {
{"proc_left", "#* Show proc box on left side of screen instead of right."},
{"proc_filter_kernel", "#* Filter processes tied to the Linux kernel(similar behavior to htop)."},
{"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."},
@ -222,6 +225,7 @@ namespace Config {
{"proc_mem_bytes", true},
{"proc_info_smaps", false},
{"proc_left", false},
{"proc_filter_kernel", false},
{"cpu_invert_lower", true},
{"cpu_single_graph", false},
{"cpu_bottom", false},

View File

@ -4,7 +4,7 @@
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@ -15,6 +15,7 @@
indent = tab
tab-size = 4
*/
// clang-format off
#include <fstream>
#include <ranges>
@ -1258,6 +1259,19 @@ namespace Proc {
int filter_found = 0;
detail_container detailed;
uint64_t kthreadd_pid{};
static void filter_kernel(const bool& should_filter) {
if (!should_filter) {
return;
}
// Filter out kernel processes
auto keraser = rng::remove_if(current_procs, [](const proc_info& curr) {
return curr.pid == kthreadd_pid || curr.ppid == kthreadd_pid;
});
current_procs.erase(keraser.begin(), keraser.end());
}
//* Generate process tree list
void _tree_gen(proc_info& cur_proc, vector<proc_info>& in_procs, vector<std::reference_wrapper<proc_info>>& out_procs, int cur_depth, const bool collapsed, const string& filter, bool found=false, const bool no_update=false, const bool should_filter=false) {
@ -1425,6 +1439,7 @@ namespace Proc {
const auto& reverse = Config::getB("proc_reversed");
const auto& filter = Config::getS("proc_filter");
const auto& per_core = Config::getB("proc_per_core");
const auto& should_filter_kernel = Config::getB("proc_filter_kernel");
const auto& tree = Config::getB("proc_tree");
const auto& show_detailed = Config::getB("show_detailed");
const size_t detailed_pid = Config::getI("detailed_pid");
@ -1489,8 +1504,8 @@ namespace Proc {
//? Iterate over all pids in /proc
vector<size_t> found;
for (const auto& d: fs::directory_iterator(Shared::procPath)) {
if (Runner::stopping)
return current_procs;
if (Runner::stopping)
return current_procs;
if (pread.is_open()) pread.close();
const string pid_str = d.path().filename();
@ -1515,6 +1530,9 @@ namespace Proc {
pread.open(d.path() / "comm");
if (not pread.good()) continue;
getline(pread, new_proc.name);
if (new_proc.name == "kthreadd") {
kthreadd_pid = new_proc.pid;
}
pread.close();
//? Check for whitespace characters in name and set offset to get correct fields from stat file
new_proc.name_offset = rng::count(new_proc.name, ' ');
@ -1671,6 +1689,8 @@ namespace Proc {
old_cputimes = cputimes;
}
filter_kernel(should_filter_kernel); // Filter here to make sorting faster.
//* ---------------------------------------------Collection done-----------------------------------------------
//* Sort processes