2021-05-10 23:46:41 +02:00
|
|
|
/* Copyright 2021 Aristocratos (jakob@qvantnet.com)
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
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
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
indent = tab
|
|
|
|
tab-size = 4
|
|
|
|
*/
|
|
|
|
|
2021-06-19 14:57:27 +02:00
|
|
|
#pragma once
|
2021-05-10 23:46:41 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <filesystem>
|
2021-06-20 00:49:13 +02:00
|
|
|
#include <atomic>
|
2021-07-04 01:18:48 +02:00
|
|
|
#include <deque>
|
|
|
|
#include <robin_hood.h>
|
2021-07-18 15:44:32 +02:00
|
|
|
#include <array>
|
2021-05-19 23:21:56 +02:00
|
|
|
|
2021-07-18 15:44:32 +02:00
|
|
|
using std::string, std::vector, std::deque, robin_hood::unordered_flat_map, std::atomic, std::array;
|
|
|
|
|
2021-07-21 03:17:34 +02:00
|
|
|
void clean_quit(const int sig=-1);
|
|
|
|
void banner_gen();
|
2021-05-10 23:46:41 +02:00
|
|
|
|
2021-06-19 14:57:27 +02:00
|
|
|
namespace Global {
|
2021-06-20 22:07:04 +02:00
|
|
|
extern const string Version;
|
2021-07-18 15:44:32 +02:00
|
|
|
extern string exit_error_msg;
|
|
|
|
extern atomic<bool> thread_exception;
|
2021-06-20 22:07:04 +02:00
|
|
|
extern string banner;
|
2021-07-18 18:04:49 +02:00
|
|
|
extern atomic<bool> resized;
|
2021-07-21 03:17:34 +02:00
|
|
|
extern string overlay;
|
2021-06-19 14:57:27 +02:00
|
|
|
}
|
2021-05-15 13:24:24 +02:00
|
|
|
|
2021-07-04 22:02:31 +02:00
|
|
|
namespace Runner {
|
|
|
|
|
2021-07-15 23:49:16 +02:00
|
|
|
extern atomic<bool> active;
|
2021-07-21 03:17:34 +02:00
|
|
|
extern atomic<bool> reading;
|
2021-07-18 15:44:32 +02:00
|
|
|
extern atomic<bool> stopping;
|
|
|
|
|
2021-07-23 01:41:00 +02:00
|
|
|
void run(const string& box="", const bool no_update=false, const bool force_redraw=false);
|
2021-07-18 15:44:32 +02:00
|
|
|
void stop();
|
2021-07-04 22:02:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-05 01:41:24 +02:00
|
|
|
namespace Tools {
|
2021-06-30 22:28:12 +02:00
|
|
|
//* Platform specific function for system_uptime (seconds since last restart)
|
2021-06-19 14:57:27 +02:00
|
|
|
double system_uptime();
|
2021-05-15 13:24:24 +02:00
|
|
|
}
|
|
|
|
|
2021-06-25 23:58:19 +02:00
|
|
|
namespace Shared {
|
|
|
|
//* Initialize platform specific needed variables and check for errors
|
|
|
|
void init();
|
2021-07-26 01:06:34 +02:00
|
|
|
|
|
|
|
extern long coreCount, page_size, clk_tck;
|
|
|
|
extern uint64_t totalMem;
|
2021-06-25 23:58:19 +02:00
|
|
|
}
|
|
|
|
|
2021-07-24 02:13:26 +02:00
|
|
|
|
2021-07-04 22:02:31 +02:00
|
|
|
namespace Cpu {
|
|
|
|
extern string box, cpuName;
|
2021-07-23 01:41:00 +02:00
|
|
|
extern int x, y, width, height;
|
2021-07-04 22:02:31 +02:00
|
|
|
extern bool shown, redraw, got_sensors;
|
2021-07-18 15:44:32 +02:00
|
|
|
|
|
|
|
struct cpu_info {
|
|
|
|
vector<deque<long long>> percent;
|
|
|
|
vector<deque<long long>> temp;
|
|
|
|
array<float, 3> load_avg;
|
|
|
|
};
|
|
|
|
|
|
|
|
//* Collect cpu stats and temperatures
|
2021-07-26 01:06:34 +02:00
|
|
|
cpu_info collect(const bool no_update=false);
|
2021-07-18 15:44:32 +02:00
|
|
|
|
|
|
|
//* Draw contents of cpu box using <cpu> as source
|
2021-07-23 01:41:00 +02:00
|
|
|
string draw(const cpu_info& cpu, const bool force_redraw=false, const bool data_same=false);
|
2021-07-04 22:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Mem {
|
|
|
|
extern string box;
|
2021-07-23 01:41:00 +02:00
|
|
|
extern int x, y, width, height;
|
2021-07-04 22:02:31 +02:00
|
|
|
extern bool has_swap, shown, redraw;
|
2021-07-18 15:44:32 +02:00
|
|
|
|
|
|
|
struct disk_info {
|
|
|
|
uint64_t total = 0, used = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mem_info {
|
|
|
|
uint64_t total = 0, available = 0, cached = 0, free = 0;
|
|
|
|
unordered_flat_map<string, deque<long long>> percent;
|
|
|
|
unordered_flat_map<string, deque<long long>> disks_io;
|
|
|
|
unordered_flat_map<string, disk_info> disks;
|
|
|
|
};
|
|
|
|
|
|
|
|
//* Collect mem & disks stats
|
2021-07-26 01:06:34 +02:00
|
|
|
mem_info collect(const bool no_update=false);
|
2021-07-18 15:44:32 +02:00
|
|
|
|
|
|
|
//* Draw contents of mem box using <mem> as source
|
2021-07-23 01:41:00 +02:00
|
|
|
string draw(const mem_info& mem, const bool force_redraw=false, const bool data_same=false);
|
2021-07-04 22:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Net {
|
|
|
|
extern string box;
|
2021-07-23 01:41:00 +02:00
|
|
|
extern int x, y, width, height;
|
2021-07-04 22:02:31 +02:00
|
|
|
extern bool shown, redraw;
|
2021-07-18 15:44:32 +02:00
|
|
|
|
|
|
|
struct net_stat {
|
|
|
|
uint64_t speed = 0, top = 0, total = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct net_info {
|
|
|
|
unordered_flat_map<string, deque<long long>> bandwidth;
|
|
|
|
unordered_flat_map<string, net_stat> stat;
|
|
|
|
string ip_addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
//* Collect net upload/download stats
|
2021-07-26 01:06:34 +02:00
|
|
|
net_info collect(const bool no_update=false);
|
2021-07-18 15:44:32 +02:00
|
|
|
|
|
|
|
//* Draw contents of net box using <net> as source
|
2021-07-23 01:41:00 +02:00
|
|
|
string draw(const net_info& net, const bool force_redraw=false, const bool data_same=false);
|
2021-07-04 22:02:31 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:54:37 +02:00
|
|
|
namespace Proc {
|
2021-07-18 15:44:32 +02:00
|
|
|
extern atomic<int> numpids;
|
2021-06-30 22:28:12 +02:00
|
|
|
|
2021-07-04 22:02:31 +02:00
|
|
|
extern string box;
|
2021-07-23 01:41:00 +02:00
|
|
|
extern int x, y, width, height;
|
2021-07-04 22:02:31 +02:00
|
|
|
extern bool shown, redraw;
|
2021-07-23 01:41:00 +02:00
|
|
|
extern int select_max;
|
2021-07-15 23:49:16 +02:00
|
|
|
extern atomic<int> detailed_pid;
|
|
|
|
extern int selected_pid, start, selected;
|
2021-07-04 22:02:31 +02:00
|
|
|
|
2021-06-30 22:28:12 +02:00
|
|
|
//? Contains the valid sorting options for processes
|
2021-06-19 14:57:27 +02:00
|
|
|
extern vector<string> sort_vector;
|
2021-05-14 18:54:37 +02:00
|
|
|
|
2021-07-04 01:18:48 +02:00
|
|
|
//? Translation from process state char to explanative string
|
|
|
|
extern unordered_flat_map<char, string> proc_states;
|
|
|
|
|
2021-06-12 18:49:27 +02:00
|
|
|
//* Container for process information
|
2021-05-15 02:56:04 +02:00
|
|
|
struct proc_info {
|
2021-07-26 01:06:34 +02:00
|
|
|
size_t pid = 0;
|
2021-06-05 01:41:24 +02:00
|
|
|
string name = "", cmd = "";
|
|
|
|
size_t threads = 0;
|
|
|
|
string user = "";
|
|
|
|
uint64_t mem = 0;
|
|
|
|
double cpu_p = 0.0, cpu_c = 0.0;
|
|
|
|
char state = '0';
|
2021-06-19 22:48:31 +02:00
|
|
|
uint64_t cpu_n = 0, p_nice = 0, ppid = 0;
|
2021-06-12 18:49:27 +02:00
|
|
|
string prefix = "";
|
2021-05-15 02:56:04 +02:00
|
|
|
};
|
2021-05-14 18:54:37 +02:00
|
|
|
|
2021-06-30 22:28:12 +02:00
|
|
|
//* Container for process info box
|
|
|
|
struct detail_container {
|
|
|
|
proc_info entry;
|
2021-07-04 01:18:48 +02:00
|
|
|
string elapsed, parent, status, io_read, io_write, memory;
|
2021-07-26 01:06:34 +02:00
|
|
|
long long first_mem = -1;
|
2021-07-04 01:18:48 +02:00
|
|
|
size_t last_pid = 0;
|
|
|
|
bool skip_smaps = false;
|
|
|
|
deque<long long> cpu_percent;
|
2021-07-26 01:06:34 +02:00
|
|
|
deque<long long> mem_bytes;
|
2021-06-30 22:28:12 +02:00
|
|
|
};
|
|
|
|
|
2021-07-26 01:06:34 +02:00
|
|
|
//? Contains all info for proc detailed box
|
2021-06-30 22:28:12 +02:00
|
|
|
extern detail_container detailed;
|
|
|
|
|
2021-07-18 15:44:32 +02:00
|
|
|
//* Collect and sort process information from /proc
|
2021-07-26 01:06:34 +02:00
|
|
|
vector<proc_info> collect(const bool no_update=false);
|
2021-07-04 22:02:31 +02:00
|
|
|
|
2021-07-26 01:06:34 +02:00
|
|
|
//* Update current selection and view, returns -1 if no change otherwise the current selection
|
|
|
|
int selection(const string& cmd_key);
|
2021-07-15 23:49:16 +02:00
|
|
|
|
|
|
|
//* Draw contents of proc box using <plist> as data source
|
2021-07-23 01:41:00 +02:00
|
|
|
string draw(const vector<proc_info>& plist, const bool force_redraw=false, const bool data_same=false);
|
2021-07-04 22:02:31 +02:00
|
|
|
}
|