mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-29 08:41:19 +13:00
small
This commit is contained in:
parent
342f0af6a8
commit
e7cbc28960
5 changed files with 37 additions and 19 deletions
8
Makefile
8
Makefile
|
@ -1,12 +1,14 @@
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
DOCDIR ?= $(PREFIX)/share/btop/doc
|
DOCDIR ?= $(PREFIX)/share/btop/doc
|
||||||
CXX = g++
|
CPP = g++
|
||||||
override CXXFLAGS += -std=c++20 -O3 -pthread -Wall -Wextra -pedantic
|
CPPFLAGS = -std=c++20 -pthread
|
||||||
|
OPTFLAG = -O3
|
||||||
|
INFOFLAGS += -Wall -Wextra -Wno-stringop-overread -pedantic
|
||||||
INCLUDES = -I./src
|
INCLUDES = -I./src
|
||||||
|
|
||||||
btop: btop.cpp
|
btop: btop.cpp
|
||||||
@mkdir -p bin
|
@mkdir -p bin
|
||||||
$(CXX) $(CXXFLAGS) $(INCLUDES) -o bin/btop btop.cpp
|
$(CPP) $(CPPFLAGS) $(INCLUDES) $(OPTFLAG) $(INFOFLAGS) -o bin/btop btop.cpp
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@mkdir -p $(DESTDIR)$(PREFIX)/bin
|
@mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||||
|
|
8
btop.cpp
8
btop.cpp
|
@ -329,7 +329,7 @@ int main(int argc, char **argv){
|
||||||
greyscale.push_back(Theme::dec_to_color(xc, xc, xc));
|
greyscale.push_back(Theme::dec_to_color(xc, xc, xc));
|
||||||
}
|
}
|
||||||
|
|
||||||
string pbox = Box::draw(Box::Conf(0, 10, Term::width, Term::height - 16, Theme::c("proc_box"), "testbox", "below", true, 7));
|
string pbox = Draw::createBox({.x = 0, .y = 10, .width = Term::width, .height = Term::height - 16, .line_color = Theme::c("proc_box"), .title = "testbox", .title2 = "below", .num = 7});
|
||||||
pbox += rjust("Pid:", 8) + " " + ljust("Program:", 16) + " " + ljust("Command:", Term::width - 69) + " Threads: " +
|
pbox += rjust("Pid:", 8) + " " + ljust("Program:", 16) + " " + ljust("Command:", Term::width - 69) + " Threads: " +
|
||||||
ljust("User:", 10) + " " + rjust("MemB", 5) + " " + rjust("Cpu%", 14) + "\n";
|
ljust("User:", 10) + " " + rjust("MemB", 5) + " " + rjust("Cpu%", 14) + "\n";
|
||||||
|
|
||||||
|
@ -356,8 +356,10 @@ int main(int argc, char **argv){
|
||||||
avgtimes.push_front(timestamp);
|
avgtimes.push_front(timestamp);
|
||||||
if (avgtimes.size() > 100) avgtimes.pop_back();
|
if (avgtimes.size() > 100) avgtimes.pop_back();
|
||||||
cout << pbox << ostring << Fx::reset << "\n" << endl;
|
cout << pbox << ostring << Fx::reset << "\n" << endl;
|
||||||
cout << Mv::to(Term::height - 4, 1) << "Processes call took: " << rjust(to_string(timestamp), 4) << "ms. Average: " << rjust(to_string(accumulate(avgtimes.begin(), avgtimes.end(), 0) / avgtimes.size()), 3) <<
|
cout << Mv::to(Term::height - 4, 1) << "Processes call took: " << rjust(to_string(timestamp), 4) << "ms. Average: " <<
|
||||||
"ms of " << avgtimes.size() << " samples. Drawing took: " << time_ms() - timestamp2 << "ms. Number of processes: " << Proc::numpids << ". Run count: " << ++rcount << ". Time: " << strf_time("%X ") << endl;
|
rjust(to_string(accumulate(avgtimes.begin(), avgtimes.end(), 0) / avgtimes.size()), 3) << "ms of " << avgtimes.size() <<
|
||||||
|
" samples. Drawing took: " << time_ms() - timestamp2 << "ms.\nNumber of processes: " << Proc::numpids << ". Run count: " <<
|
||||||
|
++rcount << ". Time: " << strf_time("%X ") << endl;
|
||||||
|
|
||||||
while (time_ms() < tsl) {
|
while (time_ms() < tsl) {
|
||||||
if (Input::poll(tsl - time_ms())) key = Input::get();
|
if (Input::poll(tsl - time_ms())) key = Input::get();
|
||||||
|
|
|
@ -31,9 +31,9 @@ tab-size = 4
|
||||||
|
|
||||||
using std::string, std::vector, std::map, std::round, std::views::iota;
|
using std::string, std::vector, std::map, std::round, std::views::iota;
|
||||||
|
|
||||||
namespace Box {
|
namespace Draw {
|
||||||
|
|
||||||
struct Conf {
|
struct BoxConf {
|
||||||
uint x=0, y=0;
|
uint x=0, y=0;
|
||||||
uint width=0, height=0;
|
uint width=0, height=0;
|
||||||
string line_color = "", title = "", title2 = "";
|
string line_color = "", title = "", title2 = "";
|
||||||
|
@ -41,8 +41,7 @@ namespace Box {
|
||||||
uint num=0;
|
uint num=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
string createBox(BoxConf c){
|
||||||
string draw(Conf c){
|
|
||||||
string out;
|
string out;
|
||||||
string lcolor = (c.line_color.empty()) ? Theme::c("div_line") : c.line_color;
|
string lcolor = (c.line_color.empty()) ? Theme::c("div_line") : c.line_color;
|
||||||
string numbering = (c.num == 0) ? "" : Theme::c("hi_fg") + Symbols::superscript[c.num];
|
string numbering = (c.num == 0) ? "" : Theme::c("hi_fg") + Symbols::superscript[c.num];
|
||||||
|
@ -80,11 +79,23 @@ namespace Box {
|
||||||
return out + Fx::reset + Mv::to(c.y + 1, c.x + 2);
|
return out + Fx::reset + Mv::to(c.y + 1, c.x + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Meter {
|
||||||
|
string out, color_gradient, color_inactive;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Box {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Proc {
|
namespace Proc {
|
||||||
|
|
||||||
// Box::Conf box;
|
// Draw::BoxConf box;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,13 @@ tab-size = 4
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <future>
|
||||||
|
#include <thread>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <streambuf>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -37,7 +41,7 @@ tab-size = 4
|
||||||
#include <btop_tools.h>
|
#include <btop_tools.h>
|
||||||
|
|
||||||
|
|
||||||
using std::string, std::vector, std::array, std::ifstream, std::atomic, std::numeric_limits, std::streamsize, std::unordered_map, std::deque, std::list;
|
using std::string, std::vector, std::array, std::ifstream, std::atomic, std::numeric_limits, std::streamsize, std::map, std::unordered_map, std::deque, std::list;
|
||||||
using std::cout, std::flush, std::endl;
|
using std::cout, std::flush, std::endl;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using namespace Tools;
|
using namespace Tools;
|
||||||
|
@ -200,7 +204,7 @@ namespace Proc {
|
||||||
user = (!uid.empty() && uid_user.contains(uid)) ? uid_user.at(uid) : uid;
|
user = (!uid.empty() && uid_user.contains(uid)) ? uid_user.at(uid) : uid;
|
||||||
}
|
}
|
||||||
else continue;
|
else continue;
|
||||||
cache[pid] = p_cache(name, cmd, user);
|
cache[pid] = {name, cmd, user};
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Match filter if defined
|
//* Match filter if defined
|
||||||
|
@ -221,6 +225,7 @@ namespace Proc {
|
||||||
|
|
||||||
//? Skip pid and comm field and find comm fields closing ')'
|
//? Skip pid and comm field and find comm fields closing ')'
|
||||||
s_pos = instr.find_last_of(')') + 2;
|
s_pos = instr.find_last_of(')') + 2;
|
||||||
|
if (s_pos == string::npos) continue;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
c_pos = instr.find(' ', s_pos);
|
c_pos = instr.find(' ', s_pos);
|
||||||
|
@ -266,7 +271,7 @@ namespace Proc {
|
||||||
s_pos = c_pos + 1;
|
s_pos = c_pos + 1;
|
||||||
} while (s_count++ < 36);
|
} while (s_count++ < 36);
|
||||||
|
|
||||||
if (s_count < 20) continue;
|
if (s_count < 19) continue;
|
||||||
|
|
||||||
//? Process cpu usage since last update, 100'000 because (100 percent * 1000 milliseconds) for correct conversion
|
//? Process cpu usage since last update, 100'000 because (100 percent * 1000 milliseconds) for correct conversion
|
||||||
cpu = static_cast<double>(100000 * (cpu_t - cache[pid].cpu_t) / since_last) / clk_tck;
|
cpu = static_cast<double>(100000 * (cpu_t - cache[pid].cpu_t) / since_last) / clk_tck;
|
||||||
|
@ -289,7 +294,7 @@ namespace Proc {
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Create proc_info
|
//* Create proc_info
|
||||||
procs.push_back(proc_info(pid, cache[pid].name, cache[pid].cmd, threads, cache[pid].user, rss_mem, cpu, cpu_s, state, cpu_n, p_nice, ppid));
|
procs.push_back({pid, cache[pid].name, cache[pid].cmd, threads, cache[pid].user, rss_mem, cpu, cpu_s, state, cpu_n, p_nice, ppid});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +336,6 @@ namespace Proc {
|
||||||
}
|
}
|
||||||
else cache.clear();
|
else cache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
tstamp = time_ms();
|
tstamp = time_ms();
|
||||||
running.store(false);
|
running.store(false);
|
||||||
return procs;
|
return procs;
|
||||||
|
|
|
@ -470,8 +470,7 @@ namespace Logger {
|
||||||
|
|
||||||
void log_write(uint level, string& msg){
|
void log_write(uint level, string& msg){
|
||||||
if (logfile.empty() || loglevel < level) return;
|
if (logfile.empty() || loglevel < level) return;
|
||||||
while (busy.load()) Tools::sleep_ms(1);
|
busy.wait(true); busy.store(true);
|
||||||
busy.store(true);
|
|
||||||
if (fs::exists(logfile) && fs::file_size(logfile) > 1024 << 10) {
|
if (fs::exists(logfile) && fs::file_size(logfile) > 1024 << 10) {
|
||||||
auto old_log = logfile;
|
auto old_log = logfile;
|
||||||
old_log += ".1";
|
old_log += ".1";
|
||||||
|
@ -479,7 +478,7 @@ namespace Logger {
|
||||||
fs::rename(logfile, old_log);
|
fs::rename(logfile, old_log);
|
||||||
}
|
}
|
||||||
std::ofstream lwrite(logfile, std::ios::app);
|
std::ofstream lwrite(logfile, std::ios::app);
|
||||||
if (first) { first = false; lwrite << "\n" << Tools::strf_time(tdf) << "----> btop++ v." << Global::Version << "\n";}
|
if (first) { first = false; lwrite << "\n" << Tools::strf_time(tdf) << "===> btop++ v." << Global::Version << "\n";}
|
||||||
lwrite << Tools::strf_time(tdf) << log_levels[level] << ": " << msg << "\n";
|
lwrite << Tools::strf_time(tdf) << log_levels[level] << ": " << msg << "\n";
|
||||||
lwrite.close();
|
lwrite.close();
|
||||||
busy.store(false);
|
busy.store(false);
|
||||||
|
|
Loading…
Reference in a new issue