Compare commits
41 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
60f95a1a74 | |
![]() |
4bf71e6816 | |
![]() |
e7648ffdad | |
![]() |
9a0e464188 | |
![]() |
2725b77917 | |
![]() |
9f8a133493 | |
![]() |
d2eb76ea5b | |
![]() |
89bf185f6b | |
![]() |
ae8d7a9266 | |
![]() |
071cde4a9c | |
![]() |
c76573ac7d | |
![]() |
faaf3ca047 | |
![]() |
b8cb8d34b1 | |
![]() |
4f7b332b15 | |
![]() |
70e844aa26 | |
![]() |
69232ceb0d | |
![]() |
497041d748 | |
![]() |
236e0f7dbb | |
![]() |
e91e0c7905 | |
![]() |
d8f1541afa | |
![]() |
c323816ec2 | |
![]() |
e775a09279 | |
![]() |
d89735c7a4 | |
![]() |
b71ae67eab | |
![]() |
196745fd9d | |
![]() |
30960326cf | |
![]() |
900cdc0a71 | |
![]() |
a21fac6b84 | |
![]() |
190814200c | |
![]() |
d90c456238 | |
![]() |
bb7643d43c | |
![]() |
91fbc4f89d | |
![]() |
6c2cfe70e4 | |
![]() |
f0f302db90 | |
![]() |
90ecb50bbb | |
![]() |
0438470cff | |
![]() |
b7f13c4556 | |
![]() |
4ccd8b9252 | |
![]() |
659a0a8d82 | |
![]() |
139bb88c29 | |
![]() |
0e9511945e |
|
@ -27,11 +27,12 @@ assignees: aristocratos
|
|||
- Bashtop version:
|
||||
- (Linux) Linux distribution and version:
|
||||
- (Linux) Data collection type (/proc or psutil):
|
||||
- Psutil version: `python3 -c "import psutil; print(psutil.version_info)"` (version 5.7.0 or above is required):
|
||||
- (OSX/FreeBSD) Os release version:
|
||||
- Terminal used:
|
||||
- Font used:
|
||||
- Bash version, "bash --version" (version 4.4 or above is required):
|
||||
- Locales: output of "locale -v"
|
||||
- Bash version, `bash --version` (version 4.4 or above is required):
|
||||
- Locales: output of `locale -v`
|
||||
|
||||
**Additional context**
|
||||
|
||||
|
|
46
CHANGELOG.md
46
CHANGELOG.md
|
@ -1,5 +1,51 @@
|
|||
# Changelog
|
||||
|
||||
## v0.9.25
|
||||
|
||||
* Fixed: Crash when using "/proc" data collection and filesystem type is 9p, by @bolapara
|
||||
|
||||
## v0.9.24
|
||||
|
||||
* Fixed: Psutil script crash on OSX
|
||||
* Fixed: Error handling for malformed osx-cpu-temp output
|
||||
|
||||
## v0.9.23
|
||||
|
||||
* Fixed: kill/terminate/interrupt process not working in OsX and FreeBSD
|
||||
|
||||
## v0.9.22
|
||||
|
||||
* Added: Added handler for mktemp failure for psutil script
|
||||
* Removed: Secondary mktemp command for psutil script
|
||||
* Fixed: Insecure test import of psutil changed
|
||||
|
||||
## v0.9.21
|
||||
|
||||
* Changed: Config file comments for theme locations
|
||||
* Added: Check for correct theme file path prefix
|
||||
* Added: Support for application cursor mode input
|
||||
* Fixed: Incorrect value calculation for reversed proc gradient
|
||||
|
||||
## v0.9.20
|
||||
|
||||
* Fixed: Psutil script security issue when placed directly in temp folder
|
||||
|
||||
## v0.9.19
|
||||
|
||||
* Added: Option for timestamps with python on bash < 5
|
||||
* Changed: Reverted "date" command timestamps to not using fifo
|
||||
* Added missing # from hex value in monokai theme
|
||||
|
||||
## v0.9.18
|
||||
|
||||
* Fixed: Errors caused by process scroll change
|
||||
* Fixed: Process graph creation ignored for process below 0.5%
|
||||
|
||||
## v0.9.17
|
||||
|
||||
* Changed: Process list now scrolls instead of "page jump" and shows number of processes instead of number of pages
|
||||
* Fixed: Inverted gradient on dark text in processes box
|
||||
|
||||
## v0.9.16
|
||||
|
||||
* Fixed: Errors in v0.9.15 psutil disk collection fix
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
* Is it a requested change or feature?
|
||||
* If not, open a feature request to get feedback before making a pull request.
|
||||
|
||||
* If it's a fix for a unreported bug, make a bug report and link the pull request.
|
||||
|
||||
* Split up multiple unrelated changes in multiple pull requests.
|
||||
|
||||
* [Shellcheck](https://github.com/koalaman/shellcheck) your work. Current shellsheck exceptions at the beginning of [bashtop](bashtop).
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
echo -e "[\033[1;33m removing packet from the system \033[0m]"
|
||||
echo -e "[\033[1;33m removing packet from the system \033[0m]"
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
118
README.md
118
README.md
|
@ -12,22 +12,34 @@
|
|||
[](https://github.com/sponsors/aristocratos)
|
||||
[](https://ko-fi.com/aristocratos)
|
||||
|
||||
### C++ Version
|
||||
|
||||
##### 18 September 2021
|
||||
|
||||

|
||||
|
||||
The C++ version of bashtop - btop++ is available.
|
||||
|
||||
Get it at https://github.com/aristocratos/btop
|
||||
|
||||
#
|
||||
|
||||
## Index
|
||||
|
||||
* [Documents](#documents)
|
||||
* [Description](#description)
|
||||
* [Features](#features)
|
||||
* [Themes](#themes) (Updated)
|
||||
* [Upcoming](#upcoming) (Python port)
|
||||
* [Themes](#themes)
|
||||
* [Support and funding](#support-and-funding)
|
||||
* [Compatibility](#compatibility) (OSX and FreeBSD Support)
|
||||
* [Dependencies](#dependencies) (Updated)
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Dependencies](#dependencies)
|
||||
* [Screenshots](#screenshots)
|
||||
* [Installation](#installation) (Updated)
|
||||
* [Configurability](#configurability) (Updated)
|
||||
* [TODO](#todo) (Updated)
|
||||
* [Installation](#installation)
|
||||
* [Configurability](#configurability)
|
||||
* [TODO](#todo)
|
||||
* [License](#license)
|
||||
|
||||
|
||||
## Documents
|
||||
|
||||
#### [CHANGELOG.md](CHANGELOG.md)
|
||||
|
@ -65,21 +77,6 @@ User created themes should be placed in `$HOME/.config/bashtop/user_themes` to b
|
|||
|
||||
Let me know if you want to contribute with new themes.
|
||||
|
||||
## Upcoming
|
||||
|
||||
~~Currently rewriting to use python3 [psutil](https://github.com/giampaolo/psutil) for data collection instead of linux specific tools.
|
||||
This will add python 3 and psutil as dependencies, but will make bashtop cross platform compatible.~~
|
||||
|
||||
~~This will be integrated in to main version when done and add the possibility to switch between psutil and linux tools for users running linux.~~
|
||||
|
||||
Bashtop is now Mac OS X and FreeBSD compatible!
|
||||
|
||||
#### Python port
|
||||
|
||||
Work on a complete python port ~~will begin this summer~~ has begun. My aim is to keep it compatible with pypy3 for a lot of added efficiency.
|
||||
|
||||
PyPyTop?
|
||||
|
||||
## Support and funding
|
||||
|
||||
Bug fixes and updates might be slow during normal workdays since I work full time as an industrial worker and don't have much time or energy left during the week.
|
||||
|
@ -95,21 +92,21 @@ Also added donation links for [paypal](https://paypal.me/aristocratos) and [ko-f
|
|||
|
||||
Any support is greatly appreciated!
|
||||
|
||||
## Compatibility
|
||||
## Prerequisites
|
||||
|
||||
Should work on most modern linux distributions, on Mac OS X and on FreeBSD.
|
||||
#### Mac Os X
|
||||
|
||||
Will not display correctly on the standard terminal on OSX!
|
||||
Will not display correctly in the standard terminal!
|
||||
Recommended alternative [iTerm2](https://www.iterm2.com/)
|
||||
|
||||
Will also need to be run as superuser on OSX to display stats for processes not owned by user.
|
||||
Will also need to be run as superuser to display stats for processes not owned by user.
|
||||
|
||||
The disk io stats on OSX and FreeBSD shows iostats for all disks at the top instead of per disk.
|
||||
#### Linux, Mac Os X and FreeBSD
|
||||
|
||||
For correct display, a terminal with support for:
|
||||
|
||||
* 24-bit truecolor
|
||||
* Wide characters
|
||||
* 24-bit truecolor ([See list of terminals with truecolor support](https://gist.github.com/XVilka/8346728))
|
||||
* Wide characters (Are sometimes problematic in web-based terminals)
|
||||
|
||||
Also needs a UTF8 locale and a font that covers:
|
||||
|
||||
|
@ -144,7 +141,7 @@ Bash version 5 is highly recommended to make use of $EPOCHREALTIME variable inst
|
|||
|
||||
**[Python3](https://www.python.org/downloads/)** (v3.6 or later)
|
||||
|
||||
**[psutil python module](https://github.com/giampaolo/psutil)**
|
||||
**[psutil python module](https://github.com/giampaolo/psutil)** (v5.7.0 or later)
|
||||
|
||||
## Optionals for additional stats
|
||||
|
||||
|
@ -177,11 +174,27 @@ Options menu.
|
|||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
|
||||
```
|
||||
|
||||
>Install dependencies
|
||||
|
||||
|
||||
>If you got python 3.6 or later installed outside of brew:
|
||||
|
||||
``` bash
|
||||
brew install bash coreutils gnu-sed python3 git
|
||||
pip3 install psutil
|
||||
sudo python3 -m ensurepip
|
||||
sudo python3 -m pip install psutil
|
||||
```
|
||||
|
||||
>If you haven't got python3 installed:
|
||||
|
||||
```
|
||||
brew install python3
|
||||
python3 -m pip install psutil
|
||||
```
|
||||
|
||||
>Install dependencies
|
||||
|
||||
|
||||
``` bash
|
||||
brew install bash coreutils gnu-sed git
|
||||
```
|
||||
|
||||
>Install optional dependency osx-cpu-temp
|
||||
|
@ -195,9 +208,7 @@ brew install osx-cpu-temp
|
|||
>Install with pkg and pip
|
||||
|
||||
``` bash
|
||||
sudo pkg install coreutils gsed python3 git
|
||||
sudo python3 -m ensurepip
|
||||
sudo pip3 install psutil
|
||||
sudo pkg install coreutils gsed git py37-psutil
|
||||
```
|
||||
|
||||
#### Manual installation Linux, OSX and FreeBSD
|
||||
|
@ -216,6 +227,16 @@ sudo make install
|
|||
sudo make uninstall
|
||||
```
|
||||
|
||||
#### FreeBSD package
|
||||
|
||||
Available in [FreeBSD ports](https://www.freshports.org/sysutils/bashtop/)
|
||||
|
||||
Install pre-built pacakge
|
||||
|
||||
``` bash
|
||||
sudo pkg install bashtop
|
||||
```
|
||||
|
||||
#### Arch based
|
||||
|
||||
Available in the AUR as [bashtop-git](https://aur.archlinux.org/packages/bashtop-git/)
|
||||
|
@ -242,6 +263,16 @@ Or use quick installation:
|
|||
sudo ./build --remove
|
||||
```
|
||||
|
||||
#### Guix based
|
||||
|
||||
Available in [official Guix repository](https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/admin.scm) since 6bbd0fd2
|
||||
|
||||
>Installation
|
||||
|
||||
``` bash
|
||||
guix install bashtop
|
||||
```
|
||||
|
||||
#### Ubuntu based
|
||||
|
||||
Available in [official Ubuntu repository](https://launchpad.net/ubuntu/+source/bashtop) since Ubuntu 20.10
|
||||
|
@ -296,21 +327,25 @@ Config files stored in "$HOME/.config/bashtop" folder
|
|||
#### bashtop.cfg: (auto generated if not found)
|
||||
|
||||
```bash
|
||||
#? Config file for bashtop v. 0.9.9
|
||||
#? Config file for bashtop v. 0.9.21
|
||||
|
||||
#* Color theme, looks for a .theme file in "$HOME/.config/bashtop/themes" and "$HOME/.config/bashtop/user_themes", "Default" for builtin default theme
|
||||
#* Color theme, looks for a .theme file in "$HOME/.config/bashtop/themes" and "$HOME/.config/bashtop/user_themes"
|
||||
#* Should be prefixed with either "themes/" or "user_themes/" depending on location, "Default" for builtin default theme
|
||||
color_theme="Default"
|
||||
|
||||
#* Update time in milliseconds, increases automatically if set below internal loops processing time, recommended 2000 ms or above for better sample times for graphs
|
||||
update_ms="2500"
|
||||
|
||||
#* Processes sorting, "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu responsive" "tree"
|
||||
#* "cpu lazy" updates sorting over time, "cpu responsive" updates sorting directly at a cpu usage cost
|
||||
#* Processes sorting, "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu responsive"
|
||||
#* "cpu lazy" updates sorting over time, "cpu responsive" updates sorting directly
|
||||
proc_sorting="cpu lazy"
|
||||
|
||||
#* Reverse sorting order, "true" or "false"
|
||||
proc_reversed="false"
|
||||
|
||||
#* Show processes as a tree
|
||||
proc_tree="false"
|
||||
|
||||
#* Check cpu temperature, only works if "sensors", "vcgencmd" or "osx-cpu-temp" commands is available
|
||||
check_temp="true"
|
||||
|
||||
|
@ -365,8 +400,7 @@ Might finish off items out of order since I usually work on multiple at a time.
|
|||
- [ ] Add gpu temp and usage. (If feasible)
|
||||
- [x] Add io stats for disks.
|
||||
- [ ] Add cpu and mem stats for docker containers. (If feasible)
|
||||
- [ ] Change process list to line scroll instead of page change.
|
||||
- [ ] Add option for custom color gradient in process list in theme settings.
|
||||
- [x] Change process list to line scroll instead of page change.
|
||||
- [ ] Add optional window for tailing log files.
|
||||
- [ ] Add options for resizing all boxes.
|
||||
- [ ] Add command line argument parsing.
|
||||
|
|
275
bashtop
275
bashtop
|
@ -93,7 +93,7 @@ banner=(
|
|||
"██╔══██╗██╔══██║╚════██║██╔══██║ ██║ ██║ ██║██╔═══╝ "
|
||||
"██████╔╝██║ ██║███████║██║ ██║ ██║ ╚██████╔╝██║ "
|
||||
"╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ")
|
||||
declare version="0.9.16"
|
||||
declare version="0.9.25"
|
||||
|
||||
#* Get latest version of BashTOP from https://github.com/aristocratos/bashtop
|
||||
|
||||
|
@ -122,7 +122,8 @@ read tty_height tty_width < <(${stty} size)
|
|||
#? Any changes made here will be ignored if config file exists
|
||||
aaa_config() { : ; } #! Do not remove this line!
|
||||
|
||||
#* Color theme, looks for a .theme file in "$HOME/.config/bashtop/themes" and "$HOME/.config/bashtop/user_themes", "Default" for builtin default theme
|
||||
#* Color theme, looks for a .theme file in "$HOME/.config/bashtop/themes" and "$HOME/.config/bashtop/user_themes"
|
||||
#* Should be prefixed with either "themes/" or "user_themes/" depending on location, "Default" for builtin default theme
|
||||
color_theme="Default"
|
||||
|
||||
#* Update time in milliseconds, increases automatically if set below internal loops processing time, recommended 2000 ms or above for better sample times for graphs
|
||||
|
@ -277,47 +278,6 @@ box[double_right_corner_down]="╝"
|
|||
box[double_title_left]="╟"
|
||||
box[double_title_right]="╢"
|
||||
|
||||
#* If using bash version 5, set timestamps with EPOCHREALTIME variable
|
||||
if [[ -n $EPOCHREALTIME ]]; then
|
||||
get_ms() { #? Set given variable to current epoch millisecond with EPOCHREALTIME varialble
|
||||
local -n ms_out=$1
|
||||
ms_out=$((${EPOCHREALTIME/[.,]/}/1000))
|
||||
}
|
||||
|
||||
#* If not, use date command, through fifo if possible
|
||||
else
|
||||
tmpdir=""
|
||||
if [[ -n $XDG_RUNTIME_DIR && -w "$XDG_RUNTIME_DIR" ]]; then
|
||||
tmpdir="$XDG_RUNTIME_DIR"
|
||||
elif [[ -w /dev/shm ]]; then
|
||||
tmpdir="/dev/shm"
|
||||
elif [[ -w /tmp ]]; then
|
||||
tmpdir="/tmp"
|
||||
elif [[ -w "$HOME" ]]; then
|
||||
tmpdir="$HOME"
|
||||
fi
|
||||
|
||||
if [[ -n $tmpdir ]] && command -v ${stdbuf} >/dev/null 2>&1; then
|
||||
${mkfifo} "${tmpdir}/bashtop_datefifo"
|
||||
exec 5> >(exec ${stdbuf} -o0 ${date} -f - +%s%3N > "${tmpdir}/bashtop_datefifo" 2>&1)
|
||||
exec 6< "${tmpdir}/bashtop_datefifo"
|
||||
${rm} -f "${tmpdir}/bashtop_datefifo"
|
||||
|
||||
get_ms() { #? Set given variable to current epoch millisecond with date command through background fifo
|
||||
local -n ms_out=$1
|
||||
echo now >&5 &&
|
||||
read -u 6 ms_out
|
||||
}
|
||||
|
||||
else
|
||||
get_ms() { #? Set given variable to current epoch millisecond with forked date command
|
||||
local -n ms_out=$1
|
||||
ms_out=""
|
||||
read ms_out < <(${date} +%s%3N)
|
||||
}
|
||||
fi
|
||||
fi
|
||||
|
||||
init_() { #? Collect needed information and set options before startig main loop
|
||||
if [[ -z $1 ]]; then
|
||||
local i stx=0
|
||||
|
@ -491,7 +451,7 @@ init_() { #? Collect needed information and set options before startig main loop
|
|||
print -bg "#00" -fg "#30ff50" -r 1 -t "√"
|
||||
print -m $(( (tty_height/2-3)+stx++ )) 0 -bg "#00" -fg "#cc" -c -b "Running process collection init..."
|
||||
proc[selected]=0
|
||||
proc[page]=1
|
||||
proc[start]=1
|
||||
collect_processes init
|
||||
|
||||
#* Draw first screen
|
||||
|
@ -533,7 +493,7 @@ color_init_() { #? Check for theme file and set colors
|
|||
done
|
||||
|
||||
#* Check if theme set in config exists and source it if it does
|
||||
if [[ -n ${color_theme} && ${color_theme} != "Default" && -e "${config_dir}/${color_theme%.theme}.theme" ]]; then
|
||||
if [[ -n ${color_theme} && ${color_theme} != "Default" && ${color_theme} =~ (themes/)|(user_themes/) && -e "${config_dir}/${color_theme%.theme}.theme" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "${config_dir}/${color_theme%.theme}.theme"
|
||||
sourced=1
|
||||
|
@ -630,7 +590,7 @@ quit_() { #? Clean exit
|
|||
if [[ $use_psutil == true && $2 != "psutil" ]]; then
|
||||
py_command quit
|
||||
sleep 0.1
|
||||
rm "${pywrapper}"
|
||||
rm -rf "${pytmpdir}"
|
||||
fi
|
||||
echo -en "${clear_screen}${normal_screen}${show_cursor}"
|
||||
${stty} "${saved_stty}"
|
||||
|
@ -918,7 +878,7 @@ get_cpu_info() {
|
|||
if [[ $use_psutil == true ]]; then
|
||||
if [[ -z ${cpu[threads]} || -z ${cpu[cores]} ]]; then
|
||||
py_command -v pyin "get_cpu_cores()"
|
||||
read cpu[threads] cpu[cores] <<<"${pyin}"
|
||||
read cpu[cores] cpu[threads] <<<"${pyin}"
|
||||
fi
|
||||
|
||||
else
|
||||
|
@ -2169,8 +2129,10 @@ collect_cpu_temps() { #? Collect cpu temperatures
|
|||
#* Get CPU package temp for Rapberry Pi cpus and for OSX
|
||||
elif [[ $sensor_comm != "sensors" && -n ${misc_var} ]]; then
|
||||
cpu[temp_0]="${misc_var#temp=}"
|
||||
cpu[temp_unit]="°${cpu[temp_0]:(-1)}"; cpu[temp_0]=${cpu[temp_0]%.*}; if [[ ${cpu[temp_0]::1} == "+" ]]; then cpu[temp_0]=${cpu[temp_0]#+}; fi
|
||||
cpu[temp_high]="75"; cpu[temp_crit]=$((cpu[temp_high]+10))
|
||||
cpu[temp_unit]="°${cpu[temp_0]:(-1)}"; cpu[temp_0]=${cpu[temp_0]%%.*}; if [[ ${cpu[temp_0]::1} == "+" ]]; then cpu[temp_0]=${cpu[temp_0]#+}; fi
|
||||
if [[ -z ${cpu[temp_high]} ]]; then
|
||||
cpu[temp_high]="75"; cpu[temp_crit]=$((cpu[temp_high]+10))
|
||||
fi
|
||||
|
||||
#* Copy cpu temp to cores
|
||||
for((i=1;i<=threads;i++)); do
|
||||
|
@ -2273,7 +2235,7 @@ collect_mem() { #? Collect memory information from "/proc/meminfo"
|
|||
if ! py_command -a df_array "get_disks(exclude='squashfs'${filtering})"; then psutil_disk_fail=1; psutil_on="false"; fi
|
||||
fi
|
||||
if [[ $psutil_on == false ]]; then
|
||||
readarray -t df_array < <(${df} -x squashfs -x tmpfs -x devtmpfs -x overlay 2>/dev/null || true)
|
||||
readarray -t df_array < <(${df} -x squashfs -x tmpfs -x devtmpfs -x overlay -x 9p 2>/dev/null || true)
|
||||
fi
|
||||
for df_line in "${df_array[@]:1}"; do
|
||||
line_array=(${df_line})
|
||||
|
@ -2399,9 +2361,6 @@ collect_processes() { #? Collect process information and calculate accurate cpu
|
|||
proc_array=("${grep_array[@]}")
|
||||
fi
|
||||
|
||||
proc[pages]=$(( (${#proc_array[@]}-1)/(height-3)+1 ))
|
||||
if ((proc[page]>proc[pages])); then proc[page]=${proc[pages]}; fi
|
||||
|
||||
|
||||
#* Get accurate cpu usage by fetching and comparing values in /proc/"pid"/stat
|
||||
local operations operation utime stime count time_elapsed cpu_percent_string rgb=231 step add proc_out tmp_value_array i pcpu_usage cpu_int tmp_percent breaking
|
||||
|
@ -2414,7 +2373,7 @@ collect_processes() { #? Collect process information and calculate accurate cpu
|
|||
((++count))
|
||||
|
||||
if ((count==height-3 & breaking==0)); then
|
||||
if [[ -n $filter || $proc_sorting != "cpu lazy" || ${proc[selected]} -gt 0 || ${proc[page]} -gt 1 || ${proc_reversed} == true ]]; then :
|
||||
if [[ -n $filter || $proc_sorting != "cpu lazy" || ${proc[selected]} -gt 0 || ${proc[start]} -gt 1 || ${proc_reversed} == true ]]; then :
|
||||
else breaking=1; fi
|
||||
fi
|
||||
|
||||
|
@ -2663,8 +2622,6 @@ collect_processes_psutil() {
|
|||
fi
|
||||
|
||||
proc_array[0]="${proc_array[0]/ ${selected}/${symbol}${selected}}"
|
||||
proc[pages]=$(( (${#proc_array[@]}-1)/(height-3)+1 ))
|
||||
if ((proc[page]>proc[pages])); then proc[page]=${proc[pages]}; fi
|
||||
|
||||
for((i=1;i<${#proc_array[@]};i++)); do
|
||||
if [[ -z ${proc_array[i]} ]]; then continue; fi
|
||||
|
@ -2684,7 +2641,7 @@ collect_processes_psutil() {
|
|||
|
||||
pid_history[${pid}]="1"
|
||||
|
||||
#* Create small graphs for all visible processes using more than 1% cpu time
|
||||
#* Create small graphs for all visible processes using more than 1% rounded cpu time
|
||||
pid_graph="pid_${pid}_graph"
|
||||
if ! local -n pid_count="pid_${pid}_count" 2>/dev/null; then continue; fi
|
||||
|
||||
|
@ -2696,8 +2653,10 @@ collect_processes_psutil() {
|
|||
elif [[ ${pid_count} -gt 0 ]]; then
|
||||
if [[ ${cpu_int} -gt 9 ]]; then
|
||||
create_mini_graph -nc -add-value "pid_${pid}_graph" "$((cpu_int+15))"
|
||||
else
|
||||
elif [[ ${cpu_int} -gt 0 ]]; then
|
||||
create_mini_graph -nc -add-value "pid_${pid}_graph" "$((cpu_int+9))"
|
||||
else
|
||||
create_mini_graph -nc -add-value "pid_${pid}_graph" "0"
|
||||
fi
|
||||
pid_count=$((${pid_count}-1))
|
||||
elif [[ ${pid_count} == "0" ]]; then
|
||||
|
@ -2760,7 +2719,7 @@ collect_processes_psutil() {
|
|||
fi
|
||||
|
||||
if ((i==height-2)); then
|
||||
if [[ ${proc[selected]} -gt 0 || ${proc[page]} -gt 1 || -z ${proc[detailed_cpu]} ]]; then :
|
||||
if [[ ${proc[selected]} -gt 0 || -n $filter || ${proc[start]} -gt 1 ]] || [[ ${proc[detailed]} -eq 1 && -z ${proc[detailed_cpu]} && -z ${proc[detailed_killed]} ]]; then :
|
||||
else break; fi
|
||||
fi
|
||||
|
||||
|
@ -2771,16 +2730,14 @@ collect_processes_psutil() {
|
|||
|
||||
|
||||
|
||||
#* Clear up memory by removing variables and graphs of no longer running processes
|
||||
#* Clear up memory
|
||||
((++proc[general_counter]))
|
||||
if ((proc[general_counter]>100)); then
|
||||
proc[general_counter]=0
|
||||
for pids in ${!pid_history[@]}; do
|
||||
if [[ ! -e /proc/${pids} ]]; then
|
||||
unset "pid_${pids}_graph" "pid_${pids}_graph_even" "pid_${pids}_graph_odd" "pid_${pids}_graph_last_type" "pid_${pids}_graph_last_val"
|
||||
unset "pid_${pids}_count"
|
||||
unset "pid_history[${pids}]"
|
||||
fi
|
||||
unset "pid_${pids}_graph" "pid_${pids}_graph_even" "pid_${pids}_graph_odd" "pid_${pids}_graph_last_type" "pid_${pids}_graph_last_val"
|
||||
unset "pid_${pids}_count"
|
||||
unset "pid_history[${pids}]"
|
||||
done
|
||||
fi
|
||||
|
||||
|
@ -3262,8 +3219,8 @@ draw_mem() { #? Draw mem, swap and disk statistics
|
|||
draw_processes() { #? Draw processes and values to screen
|
||||
local argument="$1"
|
||||
if [[ -n $skip_process_draw && $argument != "now" ]]; then return; fi
|
||||
local line=${box[processes_line]} col=${box[processes_col]} width=${box[processes_width]} height=${box[processes_height]} out_line y=1 fg_step_r=0 fg_step_g=0 fg_step_b=0 checker=2 page_string
|
||||
local reverse_string reverse_pos order_left="───────────┤" filter_string current_num detail_location det_no_add com_fg pg_arrow_up_fg pg_arrow_down_fg
|
||||
local line=${box[processes_line]} col=${box[processes_col]} width=${box[processes_width]} height=${box[processes_height]} out_line y=1 fg_step_r=0 fg_step_g=0 fg_step_b=0 checker=2 page_string sel_string
|
||||
local reverse_string reverse_pos order_left="───────────┤" filter_string current_num detail_location det_no_add com_fg pg_arrow_up_fg pg_arrow_down_fg p_height=$((height-3))
|
||||
local pid=0 pid_graph pid_step_r pid_step_g pid_step_b pid_add_r pid_add_g pid_add_b bg_add bg_step proc_start up_fg down_fg page_up_fg page_down_fg this_box=processes
|
||||
local d_width=${box[details_width]} d_height=${box[details_height]} d_line=${box[details_line]} d_col=${box[details_col]}
|
||||
local detail_graph_width=$((d_width/3+2)) detail_graph_height=$((d_height-1)) kill_fg det_mod fg_add_r fg_add_g fg_add_b
|
||||
|
@ -3275,13 +3232,23 @@ draw_processes() { #? Draw processes and values to screen
|
|||
if [[ $argument == "now" ]]; then skip_process_draw=1; fi
|
||||
|
||||
if [[ $proc_gradient == true ]]; then
|
||||
fg_add_r=$(( (fg_r-(fg_r/6) )/height))
|
||||
fg_add_g=$(( (fg_g-(fg_g/6) )/height))
|
||||
fg_add_b=$(( (fg_b-(fg_b/6) )/height))
|
||||
if ((fg_r+fg_g+fg_b<(255*3)/2)); then
|
||||
fg_add_r="$(( (fg_r-255-((fg_r-255)/6) )/height))"
|
||||
fg_add_g="$(( (fg_g-255-((fg_g-255)/6) )/height))"
|
||||
fg_add_b="$(( (fg_b-255-((fg_b-255)/6) )/height))"
|
||||
|
||||
pid_add_r=$(( (pid_r-(pid_r/6) )/height))
|
||||
pid_add_g=$(( (pid_g-(pid_g/6) )/height))
|
||||
pid_add_b=$(( (pid_b-(pid_b/6) )/height))
|
||||
pid_add_r="$(( (pid_r-255-((pid_r-255)/6) )/height))"
|
||||
pid_add_g="$(( (pid_g-255-((pid_g-255)/6) )/height))"
|
||||
pid_add_b="$(( (pid_b-255-((pid_b-255)/6) )/height))"
|
||||
else
|
||||
fg_add_r="$(( (fg_r-(fg_r/6) )/height))"
|
||||
fg_add_g="$(( (fg_g-(fg_g/6) )/height))"
|
||||
fg_add_b="$(( (fg_b-(fg_b/6) )/height))"
|
||||
|
||||
pid_add_r="$(( (pid_r-(pid_r/6) )/height))"
|
||||
pid_add_g="$(( (pid_g-(pid_g/6) )/height))"
|
||||
pid_add_b="$(( (pid_b-(pid_b/6) )/height))"
|
||||
fi
|
||||
fi
|
||||
|
||||
unset proc_out
|
||||
|
@ -3383,11 +3350,14 @@ draw_processes() { #? Draw processes and values to screen
|
|||
print -v proc_out -fg ${theme[title]} -b -t "${proc[detailed_mem_string]}"
|
||||
fi
|
||||
|
||||
#* Print processes
|
||||
if ((${#proc_array[@]}<=p_height)); then
|
||||
proc[start]=1
|
||||
elif (( proc[start]>(${#proc_array[@]}-1)-p_height )); then
|
||||
proc[start]=$(( (${#proc_array[@]}-1)-p_height ))
|
||||
fi
|
||||
|
||||
if ((proc[page]==1)); then proc_start=1
|
||||
else proc_start=$(( (height-3)*(proc[page]-1)+1 )); fi
|
||||
|
||||
if ((proc_start+proc[selected]>${#proc_array[@]})); then proc[selected]=$((${#proc_array[@]}-proc_start)); fi
|
||||
if ((proc[selected]>${#proc_array[@]}-1)); then proc[selected]=$((${#proc_array[@]}-1)); fi
|
||||
|
||||
if [[ $proc_gradient == true ]] && ((proc[selected]>1)); then
|
||||
fg_r="$(( fg_r-( fg_add_r*(proc[selected]-1) ) ))"
|
||||
|
@ -3404,7 +3374,7 @@ draw_processes() { #? Draw processes and values to screen
|
|||
print -v proc_out -rs -m $((line+y++)) $((col+1)) -fg ${theme[title]} -b -t "${proc_array[0]::$((width-3))} " -rs
|
||||
|
||||
local -a out_arr
|
||||
for out_line in "${proc_array[@]:$proc_start}"; do
|
||||
for out_line in "${proc_array[@]:${proc[start]}}"; do
|
||||
|
||||
if [[ $use_psutil == true ]]; then
|
||||
out_arr=(${out_line})
|
||||
|
@ -3454,6 +3424,12 @@ draw_processes() { #? Draw processes and values to screen
|
|||
print -v proc_out -m $((line+y++)) $((col+1)) -rp $((width-2)) -t " "
|
||||
done
|
||||
|
||||
if ((proc[selected]>0)); then sel_string=$((proc[start]-1+proc[selected])); else sel_string=0; fi
|
||||
page_string="${sel_string}/$((${#proc_array[@]}-2${filter:++1}))"
|
||||
print -v proc_out -m $((line+height-1)) $((col+width-20)) -fg ${box[processes_color]} -rp 19 -t "─"
|
||||
print -v proc_out -m $((line+height-1)) $((col+width-${#page_string}-4)) -fg ${box[processes_color]} -t "┤" -b -fg ${theme[title]} -t "$page_string" -rs -fg ${box[processes_color]} -t "├"
|
||||
|
||||
|
||||
if ((proc[order_change]==1 | proc[filter_change]==1 | resized>0)); then
|
||||
unset proc_misc
|
||||
proc[order_change]=0
|
||||
|
@ -3488,22 +3464,15 @@ draw_processes() { #? Draw processes and values to screen
|
|||
print -v proc_misc -m $line $((col+14)) -fg ${box[processes_color]} -t "┤" -fg ${theme[hi_fg]} -b -t "f" -fg ${theme[title]} -t " ${filter_string} " -fg ${theme[hi_fg]} -t "c" -rs -fg ${box[processes_color]} -t "├"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
proc_out+="${proc_misc}"
|
||||
fi
|
||||
|
||||
if ((proc[page_change]==1 | resized>0)); then
|
||||
unset proc_misc2
|
||||
proc[page_change]=0
|
||||
if ((proc[selected]>0)); then up_fg="${theme[hi_fg]}"; kill_fg="${theme[hi_fg]}"; com_fg="${theme[title]}"; else up_fg="${theme[inactive_fg]}"; kill_fg="${theme[inactive_fg]}"; com_fg="${theme[inactive_fg]}"; fi
|
||||
if ((proc[selected]==${#proc_array[@]}-proc_start)); then down_fg="${theme[inactive_fg]}"; else down_fg="${theme[hi_fg]}"; fi
|
||||
|
||||
if ((proc[page]>1)); then page_up_fg="${theme[title]}"; pg_arrow_up_fg="${theme[hi_fg]}"; else page_up_fg="${theme[inactive_fg]}"; pg_arrow_up_fg="${theme[inactive_fg]}"; fi
|
||||
if ((proc[page]<proc[pages])); then page_down_fg="${theme[title]}"; pg_arrow_down_fg="${theme[hi_fg]}" ; else page_down_fg="${theme[inactive_fg]}"; pg_arrow_down_fg="${theme[inactive_fg]}"; fi
|
||||
page_string="${proc[page]}/${proc[pages]}"
|
||||
print -v proc_misc2 -m $((line+height-1)) $((col+width-20)) -fg ${box[processes_color]} -rp 19 -t "─"
|
||||
print -v proc_misc2 -m $((line+height-1)) $((col+width-${#page_string}-12)) -fg ${box[processes_color]} -t "┤" -b -fg $page_up_fg -t "pg" -fg $pg_arrow_up_fg "↑" -fg ${theme[title]} -t " $page_string " -fg $page_down_fg -t "pg" -fg $pg_arrow_down_fg "↓" -rs -fg ${box[processes_color]} -t "├"
|
||||
if ((proc[selected]>0)); then kill_fg="${theme[hi_fg]}"; com_fg="${theme[title]}"; else kill_fg="${theme[inactive_fg]}"; com_fg="${theme[inactive_fg]}"; fi
|
||||
if ((proc[selected]==(${#proc_array[@]}-1${filter:++1})-proc[start])); then down_fg="${theme[inactive_fg]}"; else down_fg="${theme[hi_fg]}"; fi
|
||||
if ((proc[selected]>0 | proc[start]>1)); then up_fg="${theme[hi_fg]}"; else up_fg="${theme[inactive_fg]}"; fi
|
||||
|
||||
print -v proc_misc2 -m $((line+height-1)) $((col+2)) -fg ${box[processes_color]} -t "┤" -fg $up_fg -b -t "↑" -fg ${theme[title]} -t " select " -fg $down_fg -t "↓" -rs -fg ${box[processes_color]} -t "├"
|
||||
print -v proc_misc2 -r 1 -fg ${box[processes_color]} -t "┤" -fg $com_fg -b -t "info " -fg $kill_fg "↲" -rs -fg ${box[processes_color]} -t "├"
|
||||
|
@ -3878,8 +3847,8 @@ options_() { #? Shows the options overlay
|
|||
desc_use_psutil=( "Enable the use of psutil python3 module for"
|
||||
"data collection. Default on non Linux."
|
||||
""
|
||||
"Program will automatically restart if setting"
|
||||
"to true to check for compatibility."
|
||||
"Program will automatically restart if changing"
|
||||
"this setting to check for compatibility."
|
||||
" "
|
||||
"True or false."
|
||||
" "
|
||||
|
@ -4187,7 +4156,7 @@ options_() { #? Shows the options overlay
|
|||
resized=1
|
||||
fi
|
||||
if [[ $selected == "use_psutil" && $system != "Linux" ]]; then use_psutil="true"
|
||||
elif [[ $selected == "use_psutil" && $use_psutil == true ]]; then quit_ restart psutil; fi
|
||||
elif [[ $selected == "use_psutil" ]]; then quit_ restart psutil; fi
|
||||
if [[ $selected == "error_logging" ]]; then quit_ restart; fi
|
||||
|
||||
;;
|
||||
|
@ -4265,7 +4234,8 @@ killer_() { #? Kill process with selected signal
|
|||
local kill_op="$1" kill_pid="$2" killer_out killer_box col line program keypress selected selected_int=0 sig confirmed=0 option killer_pause status msg
|
||||
local -a options=("yes" "no")
|
||||
|
||||
if ! program="$(ps -o comm --no-header -p ${kill_pid})"; then return; fi
|
||||
if ! program="$(ps -o comm -p ${kill_pid})"; then return
|
||||
else program="$(tail -n1 <<<"$program")"; fi
|
||||
|
||||
case $kill_op in
|
||||
t|T) kill_op="terminate"; sig="SIGTERM" ;;
|
||||
|
@ -4399,10 +4369,10 @@ get_key() { #? Get one key from standard input and translate key code to readabl
|
|||
if [[ -z $key && $esc -eq 1 ]]; then key="escape"
|
||||
elif [[ $esc -eq 1 ]]; then
|
||||
case "${key}" in
|
||||
'[A'*) key="up" ;;
|
||||
'[B'*) key="down" ;;
|
||||
'[D'*) key="left" ;;
|
||||
'[C'*) key="right" ;;
|
||||
'[A'*|'OA'*) key="up" ;;
|
||||
'[B'*|'OB'*) key="down" ;;
|
||||
'[D'*|'OD'*) key="left" ;;
|
||||
'[C'*|'OC'*) key="right" ;;
|
||||
'[2~') key="insert" ;;
|
||||
'[3~') key="delete" ;;
|
||||
'[H'*) key="home" ;;
|
||||
|
@ -4437,7 +4407,7 @@ get_key() { #? Get one key from standard input and translate key code to readabl
|
|||
}
|
||||
|
||||
process_input() { #? Process keypresses for main ui
|
||||
local wait_time="$1" keypress esc prev_screen anykey filter_change
|
||||
local wait_time="$1" keypress esc prev_screen anykey filter_change p_height=$((box[processes_height]-3))
|
||||
late_update=0
|
||||
#* Wait while reading input
|
||||
get_key -v keypress -w "${wait_time}"
|
||||
|
@ -4449,7 +4419,7 @@ process_input() { #? Process keypresses for main ui
|
|||
"enter") unset input_to_filter ;;
|
||||
"backspace") if [[ ${#filter} -gt 0 ]]; then filter="${filter:: (-1)}"; else unset filter_change; fi ;;
|
||||
"escape") unset input_to_filter filter ;;
|
||||
*) if [[ ${#keypress} -eq 1 ]]; then filter+="${keypress//[\\\$\"\']/}"; else unset filter_change; fi ;;
|
||||
*) if [[ ${#keypress} -eq 1 && $keypress =~ ^[A-Za-z0-9\!\@\#\%\&\/\(\)\[\+\-\_\*\,\;\.\:]$ ]]; then filter+="${keypress//[\\\$\"\']/}"; else unset filter_change; fi ;;
|
||||
esac
|
||||
|
||||
else
|
||||
|
@ -4497,16 +4467,24 @@ process_input() { #? Process keypresses for main ui
|
|||
fi
|
||||
;;
|
||||
up|shift_tab) #* Move process selector up one
|
||||
if [[ ${proc[selected]} -gt 0 ]]; then
|
||||
if ((proc[selected]>1)); then
|
||||
((proc[selected]--))
|
||||
if ((proc[page]>1 & proc[selected]==0)); then ((--proc[page])); proc[selected]=$((box[processes_height]-3)); fi
|
||||
proc[page_change]=1
|
||||
elif ((proc[start]>1)); then
|
||||
if ((proc[selected]==0)); then proc[selected]=${p_height}; fi
|
||||
((proc[start]--))
|
||||
proc[page_change]=1
|
||||
elif ((proc[start]==1 & proc[selected]==1)); then
|
||||
proc[selected]=0
|
||||
proc[page_change]=1
|
||||
fi
|
||||
;;
|
||||
down|tab) #* Move process selector down one
|
||||
if ! ((proc[page]==proc[pages] & proc[selected]>=box[processes_height]-3)); then
|
||||
if ((++proc[selected]==1)); then proc[detailed_change]=1; fi
|
||||
if ((proc[selected]>box[processes_height]-3)); then ((proc[page]++)); proc[selected]=1; fi
|
||||
if ((proc[selected]<p_height & proc[start]+proc[selected]<(${#proc_array[@]}) )); then
|
||||
((++proc[selected]))
|
||||
proc[page_change]=1
|
||||
elif ((proc[start]+proc[selected]<(${#proc_array[@]}) )); then
|
||||
((++proc[start]))
|
||||
proc[page_change]=1
|
||||
fi
|
||||
;;
|
||||
|
@ -4515,7 +4493,6 @@ process_input() { #? Process keypresses for main ui
|
|||
proc[detailed]=1
|
||||
proc[detailed_change]=1
|
||||
proc[detailed_pid]=${proc[selected_pid]}
|
||||
proc[page]=1
|
||||
proc[selected]=0
|
||||
unset 'proc[detailed_name]' 'detail_history[@]' 'detail_mem_history[@]' 'proc[detailed_killed]'
|
||||
calc_sizes
|
||||
|
@ -4528,30 +4505,34 @@ process_input() { #? Process keypresses for main ui
|
|||
fi
|
||||
;;
|
||||
page_up) #* Move up one page in process box
|
||||
if [[ ${proc[page]} -gt 1 ]]; then
|
||||
((--proc[page]))
|
||||
if ((proc[start]>1)); then
|
||||
proc[start]=$(( proc[start]-p_height ))
|
||||
if ((proc[start]<1)); then proc[start]=1; fi
|
||||
proc[page_change]=1
|
||||
elif [[ ${proc[selected]} -gt 0 ]]; then
|
||||
elif ((proc[selected]>0)); then
|
||||
proc[selected]=0
|
||||
proc[start]=1
|
||||
proc[page_change]=1
|
||||
fi
|
||||
;;
|
||||
page_down) #* Move down one page in process box
|
||||
if [[ ${proc[page]} -lt ${proc[pages]} ]]; then
|
||||
if ((proc[page]++==1)); then collect_processes now; fi
|
||||
if ((proc[start]<(${#proc_array[@]}-1)-p_height)); then
|
||||
if ((proc[start]==1)) && [[ $use_psutil == false ]]; then collect_processes now; fi
|
||||
proc[start]=$(( proc[start]+p_height ))
|
||||
if (( proc[start]>(${#proc_array[@]})-p_height )); then proc[start]=$(( (${#proc_array[@]})-p_height )); fi
|
||||
proc[page_change]=1
|
||||
elif [[ ${proc[selected]} -gt 0 ]]; then
|
||||
proc[selected]=$((box[processes_height]-3))
|
||||
elif ((proc[selected]>0)); then
|
||||
proc[selected]=$((p_height))
|
||||
proc[page_change]=1
|
||||
fi
|
||||
;;
|
||||
home) #* Go to first page in process box
|
||||
proc[page]=1
|
||||
proc[start]=1
|
||||
proc[page_change]=1
|
||||
;;
|
||||
end) #* Go to last page in process box
|
||||
if ((proc[selected]==0)); then collect_processes now; fi
|
||||
proc[page]=${proc[pages]}
|
||||
if ((proc[selected]==0)) && [[ $use_psutil == false ]]; then collect_processes now; fi
|
||||
proc[start]=$(((${#proc_array[@]}-1)-p_height))
|
||||
proc[page_change]=1
|
||||
;;
|
||||
r|R) #* Reverse order of processes sorting column
|
||||
|
@ -4601,6 +4582,8 @@ process_input() { #? Process keypresses for main ui
|
|||
f|F) #* Start process filtering input
|
||||
input_to_filter=1
|
||||
filter_change=1
|
||||
if ((proc[selected]>1)); then proc[selected]=1; fi
|
||||
proc[start]=1
|
||||
;;
|
||||
c|C) #* Clear process filter
|
||||
if [[ -n $filter ]]; then
|
||||
|
@ -4780,7 +4763,7 @@ if [[ $use_psutil == true ]]; then
|
|||
else
|
||||
exit 1
|
||||
fi
|
||||
elif [[ $use_psutil == true ]] && ! python3 -c "import psutil" >/dev/null 2>&1; then
|
||||
elif [[ $use_psutil == true ]] && ! (cd / && python3 -c "import psutil") >/dev/null 2>&1; then
|
||||
echo "Error: Missing python3 psutil module!"
|
||||
if [[ $system == "Linux" ]]; then
|
||||
use_psutil="false"
|
||||
|
@ -4790,8 +4773,28 @@ if [[ $use_psutil == true ]]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
#* if we have been sourced by another shell, quit. Allows sourcing only function definition.
|
||||
[[ "${#BASH_SOURCE[@]}" -gt 1 ]] && { return 0; }
|
||||
#* If using bash version 5, set timestamps with EPOCHREALTIME variable
|
||||
if [[ -n $EPOCHREALTIME ]]; then
|
||||
get_ms() { #? Set given variable to current epoch millisecond with EPOCHREALTIME varialble
|
||||
local -n ms_out=$1
|
||||
ms_out=$((${EPOCHREALTIME/[.,]/}/1000))
|
||||
}
|
||||
|
||||
#* If not, but using psutil, set timestamps with python
|
||||
elif [[ $use_psutil == true ]]; then
|
||||
get_ms() {
|
||||
local -n ms_out=$1
|
||||
py_command -v ms_out "get_ms()"
|
||||
}
|
||||
|
||||
#* Else use date command
|
||||
else
|
||||
get_ms() { #? Set given variable to current epoch millisecond with date command
|
||||
local -n ms_out=$1
|
||||
ms_out=""
|
||||
read ms_out < <(${date} +%s%3N)
|
||||
}
|
||||
fi
|
||||
|
||||
#* Setup psutil script
|
||||
if [[ $use_psutil == true ]]; then
|
||||
|
@ -4826,7 +4829,15 @@ if [[ $use_psutil == true ]]; then
|
|||
return 0
|
||||
}
|
||||
|
||||
pywrapper=$(mktemp "${TMPDIR:-/tmp}"/bashtop.psutil.XXXX)
|
||||
if ! pytmpdir=$(mktemp -d "${TMPDIR:-/tmp}"/XXXXXXXXXXXX); then
|
||||
if [[ $system == "Linux" ]]; then
|
||||
use_psutil="false"
|
||||
else
|
||||
echo "ERROR: Failed setting up temp directory for psutil script!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
pywrapper="${pytmpdir}/bashtop.psutil"
|
||||
|
||||
cat << 'EOF' > "${pywrapper}"
|
||||
import os, sys, subprocess, re, time, psutil
|
||||
|
@ -4859,7 +4870,8 @@ allowed_commands: Tuple[str] = (
|
|||
'get_net',
|
||||
'get_cmd_out',
|
||||
'get_sensors',
|
||||
'get_sensors_check'
|
||||
'get_sensors_check',
|
||||
'get_ms'
|
||||
)
|
||||
command: str = ''
|
||||
cpu_count: int = psutil.cpu_count()
|
||||
|
@ -4873,6 +4885,11 @@ def get_cmd_out(cmd: str):
|
|||
'''Save bash the trouble of creating child processes by running through python instead'''
|
||||
print(subprocess.check_output(cmd, shell=True, universal_newlines=True).rstrip())
|
||||
|
||||
def get_ms():
|
||||
'''Get current epoch millisecond'''
|
||||
t = str(time.time()).split(".")
|
||||
print(f'{t[0]}{t[1][:3]}')
|
||||
|
||||
def get_sensors():
|
||||
'''A clone of "sensors" but using psutil'''
|
||||
temps = psutil.sensors_temperatures()
|
||||
|
@ -4942,8 +4959,8 @@ def get_cpu_name():
|
|||
|
||||
def get_cpu_cores():
|
||||
'''Get number of CPU cores and threads'''
|
||||
cores: int = psutil.cpu_count(logical=True)
|
||||
threads: int = psutil.cpu_count(logical=False)
|
||||
cores: int = psutil.cpu_count(logical=False)
|
||||
threads: int = psutil.cpu_count(logical=True)
|
||||
print(f'{cores} {threads if threads else cores}')
|
||||
|
||||
def get_cpu_usage():
|
||||
|
@ -5047,11 +5064,14 @@ def get_proc(sorting='cpu lazy', tree=False, prog_len=0, arg_len=0, search='', r
|
|||
print(f"{'Pid:':>7} {'Program:':<{prog_len}}", f"{'Arguments:':<{arg_len-4}}" if arg_len else '', f"{'Threads:' if arg_len else ' Tr:'} {'User:':<9}Mem%{'Cpu%':>11}", sep='')
|
||||
|
||||
for p in sorted(psutil.process_iter(['pid', 'name', 'cmdline', 'num_threads', 'username', 'memory_percent', 'cpu_percent', 'cpu_times', 'create_time'], err), key=lambda p: eval(sort_cmd), reverse=reverse):
|
||||
if p.info['name'] == 'idle':
|
||||
if p.info['name'] == 'idle' or p.info['name'] == err or p.info['pid'] == err:
|
||||
continue
|
||||
if p.info['cpu_times'] == err:
|
||||
if p.info['cmdline'] == err:
|
||||
p.info['cmdline'] = ""
|
||||
if p.info['username'] == err:
|
||||
p.info['username'] = "?"
|
||||
if p.info['num_threads'] == err:
|
||||
p.info['num_threads'] = 0
|
||||
p.info['cmdline'] = ''
|
||||
if search:
|
||||
found = False
|
||||
for value in [ p.info['name'], ' '.join(p.info['cmdline']), str(p.info['pid']), p.info['username'] ]:
|
||||
|
@ -5108,6 +5128,8 @@ def proc_tree(width: int, sorting: str = 'cpu lazy', reverse: bool = True, max_l
|
|||
if getinfo and cont:
|
||||
if getinfo['cpu_times'] == err:
|
||||
getinfo['num_threads'] = 0
|
||||
if p.info['username'] == err:
|
||||
p.info['username'] = "?"
|
||||
cpu = getinfo['cpu_percent'] if proc_per_cpu else (getinfo['cpu_percent'] / psutil.cpu_count())
|
||||
print(f"{getinfo['num_threads']:>4} " if getinfo['num_threads'] < 1000 else '999> ',
|
||||
f"{getinfo['username']:<9.9}" if len(getinfo['username']) < 10 else f"{getinfo['username'][:8]:<8}+",
|
||||
|
@ -5223,7 +5245,7 @@ while command != 'quit':
|
|||
print('/EOL')
|
||||
#print(f'{command}', file=sys.stderr)
|
||||
EOF
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
#* Set up traps for ctrl-c, soft kill, window resize, ctrl-z and resume from ctrl-z
|
||||
|
@ -5255,6 +5277,9 @@ else
|
|||
exec 2>/dev/null
|
||||
fi
|
||||
|
||||
#* If we have been sourced by another shell, quit. Allows sourcing only function definition.
|
||||
[[ "${#BASH_SOURCE[@]}" -gt 1 ]] && { return 0; }
|
||||
|
||||
#* Call init function
|
||||
init_
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ allowed_commands: Tuple[str] = (
|
|||
'get_net',
|
||||
'get_cmd_out',
|
||||
'get_sensors',
|
||||
'get_sensors_check'
|
||||
'get_sensors_check',
|
||||
'get_ms'
|
||||
)
|
||||
command: str = ''
|
||||
cpu_count: int = psutil.cpu_count()
|
||||
|
@ -46,6 +47,11 @@ def get_cmd_out(cmd: str):
|
|||
'''Save bash the trouble of creating child processes by running through python instead'''
|
||||
print(subprocess.check_output(cmd, shell=True, universal_newlines=True).rstrip())
|
||||
|
||||
def get_ms():
|
||||
'''Get current epoch millisecond'''
|
||||
t = str(time.time()).split(".")
|
||||
print(f'{t[0]}{t[1][:3]}')
|
||||
|
||||
def get_sensors():
|
||||
'''A clone of "sensors" but using psutil'''
|
||||
temps = psutil.sensors_temperatures()
|
||||
|
@ -115,8 +121,8 @@ def get_cpu_name():
|
|||
|
||||
def get_cpu_cores():
|
||||
'''Get number of CPU cores and threads'''
|
||||
cores: int = psutil.cpu_count(logical=True)
|
||||
threads: int = psutil.cpu_count(logical=False)
|
||||
cores: int = psutil.cpu_count(logical=False)
|
||||
threads: int = psutil.cpu_count(logical=True)
|
||||
print(f'{cores} {threads if threads else cores}')
|
||||
|
||||
def get_cpu_usage():
|
||||
|
@ -220,11 +226,14 @@ def get_proc(sorting='cpu lazy', tree=False, prog_len=0, arg_len=0, search='', r
|
|||
print(f"{'Pid:':>7} {'Program:':<{prog_len}}", f"{'Arguments:':<{arg_len-4}}" if arg_len else '', f"{'Threads:' if arg_len else ' Tr:'} {'User:':<9}Mem%{'Cpu%':>11}", sep='')
|
||||
|
||||
for p in sorted(psutil.process_iter(['pid', 'name', 'cmdline', 'num_threads', 'username', 'memory_percent', 'cpu_percent', 'cpu_times', 'create_time'], err), key=lambda p: eval(sort_cmd), reverse=reverse):
|
||||
if p.info['name'] == 'idle':
|
||||
if p.info['name'] == 'idle' or p.info['name'] == err or p.info['pid'] == err:
|
||||
continue
|
||||
if p.info['cpu_times'] == err:
|
||||
if p.info['cmdline'] == err:
|
||||
p.info['cmdline'] = ""
|
||||
if p.info['username'] == err:
|
||||
p.info['username'] = "?"
|
||||
if p.info['num_threads'] == err:
|
||||
p.info['num_threads'] = 0
|
||||
p.info['cmdline'] = ''
|
||||
if search:
|
||||
found = False
|
||||
for value in [ p.info['name'], ' '.join(p.info['cmdline']), str(p.info['pid']), p.info['username'] ]:
|
||||
|
@ -281,6 +290,8 @@ def proc_tree(width: int, sorting: str = 'cpu lazy', reverse: bool = True, max_l
|
|||
if getinfo and cont:
|
||||
if getinfo['cpu_times'] == err:
|
||||
getinfo['num_threads'] = 0
|
||||
if p.info['username'] == err:
|
||||
p.info['username'] = "?"
|
||||
cpu = getinfo['cpu_percent'] if proc_per_cpu else (getinfo['cpu_percent'] / psutil.cpu_count())
|
||||
print(f"{getinfo['num_threads']:>4} " if getinfo['num_threads'] < 1000 else '999> ',
|
||||
f"{getinfo['username']:<9.9}" if len(getinfo['username']) < 10 else f"{getinfo['username'][:8]:<8}+",
|
||||
|
|
|
@ -60,7 +60,7 @@ theme[cpu_end]="#F92672"
|
|||
|
||||
# Mem/Disk free meter
|
||||
theme[free_start]="#75715E"
|
||||
theme[free_mid]="a9c474"
|
||||
theme[free_mid]="#a9c474"
|
||||
theme[free_end]="#e2f5bc"
|
||||
|
||||
# Mem/Disk cached meter
|
||||
|
|
Loading…
Reference in New Issue