/* 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 */ #pragma once #include #include #include #include #include #include #include using std::string, std::vector, std::deque, robin_hood::unordered_flat_map, std::atomic, std::array; void clean_quit(const int sig=-1); void term_resize(bool force=false); void banner_gen(); namespace Global { extern const string Version; extern string exit_error_msg; extern atomic thread_exception; extern string banner; extern atomic resized; extern string overlay; extern string clock; } namespace Runner { extern atomic active; extern atomic reading; extern atomic stopping; void run(const string& box="", const bool no_update=false, const bool force_redraw=false); void stop(); } namespace Tools { //* Platform specific function for system_uptime (seconds since last restart) double system_uptime(); } namespace Shared { //* Initialize platform specific needed variables and check for errors void init(); extern long coreCount, page_size, clk_tck; extern uint64_t totalMem; } namespace Cpu { extern string box; extern int x, y, width, height; extern bool shown, redraw, got_sensors; extern string cpuName, cpuHz; struct cpu_info { unordered_flat_map> cpu_percent = { {"total", {}}, {"user", {}}, {"nice", {}}, {"system", {}}, {"idle", {}}, {"iowait", {}}, {"irq", {}}, {"softirq", {}}, {"steal", {}}, {"guest", {}}, {"guest_nice", {}} }; vector> core_percent; vector> temp; array load_avg; }; //* Collect cpu stats and temperatures cpu_info collect(const bool no_update=false); //* Draw contents of cpu box using as source string draw(const cpu_info& cpu, const bool force_redraw=false, const bool data_same=false); //* Try to get name of cpu string get_cpuName(); //* Try to get current cpu clock speed string get_cpuHz(); } namespace Mem { extern string box; extern int x, y, width, height; extern bool has_swap, shown, redraw; 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> percent; unordered_flat_map> disks_io; unordered_flat_map disks; }; //* Collect mem & disks stats mem_info collect(const bool no_update=false); //* Draw contents of mem box using as source string draw(const mem_info& mem, const bool force_redraw=false, const bool data_same=false); } namespace Net { extern string box; extern int x, y, width, height; extern bool shown, redraw; struct net_stat { uint64_t speed = 0, top = 0, total = 0; }; struct net_info { unordered_flat_map> bandwidth; unordered_flat_map stat; string ip_addr; }; //* Collect net upload/download stats net_info collect(const bool no_update=false); //* Draw contents of net box using as source string draw(const net_info& net, const bool force_redraw=false, const bool data_same=false); } namespace Proc { extern atomic numpids; extern string box; extern int x, y, width, height; extern bool shown, redraw; extern int select_max; extern atomic detailed_pid; extern int selected_pid, start, selected, collapse, expand; //? Contains the valid sorting options for processes extern vector sort_vector; //? Translation from process state char to explanative string extern unordered_flat_map proc_states; //* Container for process information struct proc_info { size_t pid = 0; 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'; uint64_t cpu_n = 0, p_nice = 0, ppid = 0; string prefix = ""; }; //* Container for process info box struct detail_container { proc_info entry; string elapsed, parent, status, io_read, io_write, memory; long long first_mem = -1; size_t last_pid = 0; bool skip_smaps = false; deque cpu_percent; deque mem_bytes; }; //? Contains all info for proc detailed box extern detail_container detailed; //* Collect and sort process information from /proc vector collect(const bool no_update=false); //* Update current selection and view, returns -1 if no change otherwise the current selection int selection(const string& cmd_key); //* Draw contents of proc box using as data source string draw(const vector& plist, const bool force_redraw=false, const bool data_same=false); }