mirror of
https://github.com/thewtex/tmux-mem-cpu-load.git
synced 2026-09-10 07:16:16 -04:00
Compare commits
204 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
640eac3069 | ||
|
|
0b4c5e9894 | ||
|
|
96405e16ea | ||
|
|
ec3448c5c9 | ||
|
|
606622eb38 | ||
|
|
006b834b9c | ||
|
|
1922b61f3d | ||
|
|
ec284cc78f | ||
|
|
041d53d7d0 | ||
|
|
5aa51ed196 | ||
|
|
6b0f365a86 | ||
|
|
11b856c72d | ||
|
|
fdcde82be0 | ||
|
|
ab991091be | ||
|
|
b5772c1bfb | ||
|
|
df30c399fc | ||
|
|
90f1845d51 | ||
|
|
451107b7eb | ||
|
|
a5662eaca0 | ||
|
|
ef67d00820 | ||
|
|
4ecb3f52d8 | ||
|
|
40d42459f5 | ||
|
|
036e627089 | ||
|
|
6549a6cf2f | ||
|
|
359a595d73 | ||
|
|
9adf9470c7 | ||
|
|
192e31a62c | ||
|
|
abe531fffb | ||
|
|
8d062a7e36 | ||
|
|
83820d97a0 | ||
|
|
df71d2123a | ||
|
|
42bf188155 | ||
|
|
93525a5517 | ||
|
|
13160c7e80 | ||
|
|
bf0b2721df | ||
|
|
06fe4850db | ||
|
|
9c273230a8 | ||
|
|
8d7911abe1 | ||
|
|
79804bc3e1 | ||
|
|
9c83be94d4 | ||
|
|
9a9abc5d13 | ||
|
|
4aa31eb80c | ||
|
|
1dcf3f92fb | ||
|
|
525c6a28b2 | ||
|
|
4cf0dad920 | ||
|
|
451300eda2 | ||
|
|
8f7027f1fd | ||
|
|
b06c049d0f | ||
|
|
d1676552dc | ||
|
|
aa8fe65529 | ||
|
|
ba8489917d | ||
|
|
a991497b9f | ||
|
|
59cca005e4 | ||
|
|
35f9618d1f | ||
|
|
0c9a8d4612 | ||
|
|
c058ed6f21 | ||
|
|
6eec6350be | ||
|
|
d900b3a546 | ||
|
|
6d96a8a490 | ||
|
|
f08fce0f83 | ||
|
|
73b7f6c29f | ||
|
|
94aed0352c | ||
|
|
e232eef156 | ||
|
|
f9663c8f2f | ||
|
|
dc298e162a | ||
|
|
6178ba9aa3 | ||
|
|
88a219a36d | ||
|
|
2c3484286e | ||
|
|
5420cf8696 | ||
|
|
2b19ca8a0a | ||
|
|
b2c6cd43e0 | ||
|
|
a5d66aac16 | ||
|
|
bc279dd2cb | ||
|
|
018c03b131 | ||
|
|
b0644d7372 | ||
|
|
626253d791 | ||
|
|
66dfb979b8 | ||
|
|
adfed692ad | ||
|
|
5dccd1801f | ||
|
|
721cb67a80 | ||
|
|
c158cdd71e | ||
|
|
37220619a2 | ||
|
|
171917715d | ||
|
|
56b71ea699 | ||
|
|
651b134b09 | ||
|
|
a449ed042c | ||
|
|
bc4c0ddbad | ||
|
|
961351433c | ||
|
|
0b6cd002b3 | ||
|
|
d87de550f4 | ||
|
|
4de9c077f5 | ||
|
|
974e40bcb5 | ||
|
|
486e618f41 | ||
|
|
f29c4ff5c5 | ||
|
|
8052318680 | ||
|
|
0077534b96 | ||
|
|
1ac6729ef1 | ||
|
|
04419c8cdf | ||
|
|
b6afa5c5e9 | ||
|
|
96ea7dc050 | ||
|
|
0ca29c4ecd | ||
|
|
4be44f35f7 | ||
|
|
8c2f0e2cfd | ||
|
|
37b08090f1 | ||
|
|
c83d7ee712 | ||
|
|
8b6e394dd3 | ||
|
|
31768a203b | ||
|
|
9113cefccc | ||
|
|
39348840c1 | ||
|
|
3ec357c63c | ||
|
|
acea452957 | ||
|
|
705830d1df | ||
|
|
8c9c31798c | ||
|
|
bf41ae4393 | ||
|
|
e652a93b72 | ||
|
|
db4edaeecc | ||
|
|
39c6c57bf3 | ||
|
|
d5007d4694 | ||
|
|
10ad0b29fd | ||
|
|
fc78a0bdad | ||
|
|
d34821cb95 | ||
|
|
f96ae7a76a | ||
|
|
e24890652e | ||
|
|
12417dc358 | ||
|
|
2107ea84f1 | ||
|
|
67657e6312 | ||
|
|
15da3e0a59 | ||
|
|
2fdcf93296 | ||
|
|
7cf58a8367 | ||
|
|
3fad77c3ac | ||
|
|
abe7290511 | ||
|
|
22f4db4b0e | ||
|
|
75b9ea756e | ||
|
|
26b53ea94b | ||
|
|
0e227c1e88 | ||
|
|
5c37494d11 | ||
|
|
35fea56625 | ||
|
|
8018a0c761 | ||
|
|
d1f95acada | ||
|
|
8b1f07ccca | ||
|
|
d7db6d8c8b | ||
|
|
58564ae6b7 | ||
|
|
54fdf3c68c | ||
|
|
e5595e21f4 | ||
|
|
13c3205ec0 | ||
|
|
1b11c308ac | ||
|
|
dcadec63a2 | ||
|
|
0941898c02 | ||
|
|
1456c16cf8 | ||
|
|
6960e27dc4 | ||
|
|
a26f0ae59d | ||
|
|
18b4ed638a | ||
|
|
8af6dc22b8 | ||
|
|
b7d2d2a73e | ||
|
|
4a2c4efb9a | ||
|
|
ad83d9b3a9 | ||
|
|
c623ca889d | ||
|
|
3e12a64309 | ||
|
|
0bc57a9ac8 | ||
|
|
ce9de3f9aa | ||
|
|
710be9e355 | ||
|
|
3f647a9b2b | ||
|
|
97a655c856 | ||
|
|
cbe3074c6b | ||
|
|
1d1a516eda | ||
|
|
34b9d39b57 | ||
|
|
bac831cd69 | ||
|
|
e9a3726de7 | ||
|
|
6e1dbc6b1f | ||
|
|
b8594ecb82 | ||
|
|
159051079b | ||
|
|
cc59b4952f | ||
|
|
68fd497108 | ||
|
|
be0b914c49 | ||
|
|
6938941b99 | ||
|
|
42275e094d | ||
|
|
fb8e3c6ad0 | ||
|
|
e50d34873f | ||
|
|
7eef3670e0 | ||
|
|
4fd854ce16 | ||
|
|
c5f369ae00 | ||
|
|
81fea73e79 | ||
|
|
a6f57340d8 | ||
|
|
635334b141 | ||
|
|
0e89998ee4 | ||
|
|
1b8fa1ec3a | ||
|
|
451aed4530 | ||
|
|
859c60976a | ||
|
|
cc85854323 | ||
|
|
9ad57c906b | ||
|
|
c036017db3 | ||
|
|
f80a026c45 | ||
|
|
7ca3efacad | ||
|
|
e9af4ea2c0 | ||
|
|
cd0ad5c8ff | ||
|
|
ff36892e29 | ||
|
|
d273cbaf60 | ||
|
|
e1908ebd13 | ||
|
|
8e6d013c66 | ||
|
|
ad0a88d1f2 | ||
|
|
7cc6ff35cc | ||
|
|
79e16ec38b | ||
|
|
62c18a0778 | ||
|
|
b61503e76a |
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
*.cc whitespace=tab-in-indent,no-lf-at-eof,trailing-whitespace
|
||||
*.h whitespace=tab-in-indent,no-lf-at-eof,trailing-whitespace
|
||||
*.rst whitespace=tab-in-indent,no-lf-at-eof,trailing-whitespace
|
||||
*.txt whitespace=tab-in-indent,no-lf-at-eof,trailing-whitespace
|
||||
9
.github/dependabot.yml
vendored
Normal file
9
.github/dependabot.yml
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Set update schedule for GitHub Actions
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
# Check for updates to GitHub Actions every weekday
|
||||
interval: "daily"
|
||||
22
.github/workflows/expired.yml
vendored
Normal file
22
.github/workflows/expired.yml
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
name: 'Close stale issues and PRs'
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 */8 * * *'
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v11
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
exempt-issue-milestones: 'future,alpha,beta,release'
|
||||
exempt-pr-milestones: 'bugfix,improvement'
|
||||
exempt-all-pr-assignees: true
|
||||
stale-issue-message: 'This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 15 days.'
|
||||
stale-pr-message: 'This PR is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 15 days.'
|
||||
close-issue-message: 'This issue was closed because it has been stalled for 30 days with no activity.'
|
||||
close-pr-message: 'This PR was closed because it has been stalled for 30 days with no activity.'
|
||||
days-before-issue-stale: 120
|
||||
days-before-pr-stale: 120
|
||||
days-before-issue-close: 30
|
||||
days-before-pr-close: 30
|
||||
34
.github/workflows/main.yml
vendored
Normal file
34
.github/workflows/main.yml
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
name: tmux-mem-cpu-load
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
paths-ignore:
|
||||
- '**/README.md'
|
||||
- '**/README.rst'
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
image:
|
||||
name: build ${{ matrix.arch_name }} ${{ matrix.build_type }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# Disable: unsupported system: android-arm, android-arm64, android-x86, android-x86_64, web-wasm,
|
||||
# Disable: missing header in linux(GCC): windows-static-x64, windows-static-x64-posix, windows-static-x86, windows-shared-x64, windows-shared-x64-posix, windows-shared-x86,
|
||||
# Disable: string-related vtable linker error: manylinux2014-aarch64
|
||||
arch_name: [linux-arm64, linux-arm64-musl, linux-armv5, linux-armv5-musl, linux-armv6, linux-armv6-musl, linux-armv7, linux-armv7a, linux-armv7l-musl, linux-x64-clang, linux-s390x, linux-x64, linux-x86, linux-mips, linux-ppc64le, manylinux1-x64, manylinux1-x86, manylinux2010-x64, manylinux2010-x86, manylinux2014-x64, manylinux2014-x86, linux-riscv64, linux-riscv32]
|
||||
build_type: [Release, Debug]
|
||||
steps:
|
||||
- name: "📥 Checkout Code"
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
- name: "🛠️ build"
|
||||
run: ./builder/cmake.sh ${{ matrix.arch_name }}:latest -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
|
||||
63
.github/workflows/release.yml
vendored
Normal file
63
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
name: "tagged-release"
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v[0-9]+.[0-9]+.[0-9]+*"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: build ${{ matrix.arch_name }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# Disable: unsupported system: android-arm, android-arm64, android-x86, android-x86_64, web-wasm,
|
||||
# Disable: missing header in linux(GCC): windows-static-x64, windows-static-x64-posix, windows-static-x86, windows-shared-x64, windows-shared-x64-posix, windows-shared-x86,
|
||||
arch_name: [linux-arm64, linux-arm64-musl, linux-armv5, linux-armv5-musl, linux-armv6, linux-armv6-musl, linux-armv7, linux-armv7a, linux-armv7l-musl, linux-x64-clang, linux-s390x, linux-x64, linux-x86, linux-mips, linux-ppc64le, manylinux1-x64, manylinux1-x86, manylinux2010-x64, manylinux2010-x86, manylinux2014-x64, manylinux2014-x86, manylinux2014-aarch64, linux-riscv64, linux-riscv32]
|
||||
steps:
|
||||
- name: "📥 Checkout Code"
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
- name: "🛠️ cmake"
|
||||
run: ./builder/cmake.sh ${{ matrix.arch_name }}:latest -DCMAKE_BUILD_TYPE=Release
|
||||
- name: "✅ checksum"
|
||||
run: cd build-${{ matrix.arch_name }} && find . -maxdepth 1 -name "tmux-mem-cpu-load*" | xargs sha256sum > checksum.sha256
|
||||
- name: "🗜️ compress"
|
||||
run: cd build-${{ matrix.arch_name }} && find . -maxdepth 1 -name "tmux-mem-cpu-load*" -o -name "*.sha256" | XZ_OPT=-e9 tar -cJf tmux-mem-cpu-load-${{ matrix.arch_name }}.tar.xz -T - && mv tmux-mem-cpu-load-${{ matrix.arch_name }}.tar.xz ..
|
||||
- name: "💾 save binaries"
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: bin-artifact-${{ matrix.arch_name }}
|
||||
path: tmux-mem-cpu-load-${{ matrix.arch_name }}.tar.xz
|
||||
retention-days: 1
|
||||
release:
|
||||
name: release
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: "📥 Checkout Code"
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
- name: get artifact
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
pattern: bin-artifact-*
|
||||
merge-multiple: true
|
||||
path: .
|
||||
- name: "✅ checksum"
|
||||
run: find . -maxdepth 1 -name "*.tar.xz" | xargs sha256sum > checksum_all.sha256
|
||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
||||
name: "📤 upload to github"
|
||||
with:
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
prerelease: false
|
||||
files: |
|
||||
LICENSE
|
||||
*.tar.xz
|
||||
*.sha256
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -21,6 +21,12 @@ config.h
|
|||
CTestTestfile.cmake
|
||||
DartConfiguration.tcl
|
||||
|
||||
# Ninja generated #
|
||||
###################
|
||||
.ninja_deps
|
||||
.ninja_log
|
||||
*.ninja
|
||||
|
||||
# Packages #
|
||||
############
|
||||
# it's better to unpack this files and commit raw source
|
||||
|
|
@ -51,3 +57,5 @@ Thumbs.db
|
|||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
dockcross-*
|
||||
build-*
|
||||
|
|
|
|||
1
AUTHORS
1
AUTHORS
|
|
@ -9,3 +9,4 @@ Contributors (in alphabetical order):
|
|||
krieiter <krieiter@gmail.com>
|
||||
Mark Palmeri <mlp6@duke.edu>
|
||||
Pawel 'l0ner' Soltys <pwslts@gmail.com>
|
||||
Compilenix <Compilenix@compilenix.org>
|
||||
|
|
|
|||
|
|
@ -16,33 +16,20 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
if(COMMAND cmake_policy)
|
||||
cmake_policy(VERSION 2.6)
|
||||
endif(COMMAND cmake_policy)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
### General Package stuff
|
||||
project(tmux-mem-cpu-load)
|
||||
set(tmux-mem-cpu-load_VERSION_MAJOR 3)
|
||||
set(tmux-mem-cpu-load_VERSION_MINOR 2)
|
||||
set(tmux-mem-cpu-load_VERSION_PATCH 1)
|
||||
set(tmux-mem-cpu-load_VERSION_MINOR 8)
|
||||
set(tmux-mem-cpu-load_VERSION_PATCH 3)
|
||||
#Compute full version string
|
||||
set(tmux-mem-cpu-load_VERSION
|
||||
${tmux-mem-cpu-load_VERSION_MAJOR}.${tmux-mem-cpu-load_VERSION_MINOR}.${tmux-mem-cpu-load_VERSION_PATCH})
|
||||
|
||||
# Check whether we have support for c++11 in compiler and fail if we don't
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||
|
||||
if(COMPILER_SUPPORTS_CXX11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
elseif(COMPILER_SUPPORTS_CXX0X)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
"Compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} has no C++11 support.")
|
||||
endif()
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# generate header file to handle version
|
||||
configure_file(
|
||||
|
|
@ -67,26 +54,32 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
|||
message(STATUS "FreeBSD detected")
|
||||
set(METER_SOURCES "freebsd/memory.cc" "freebsd/cpu.cc" "common/load.cc")
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
||||
# OpenBSD Stuff Here
|
||||
message(STATUS "OpenBSD detected")
|
||||
set(METER_SOURCES "openbsd/memory.cc" "openbsd/cpu.cc" "common/load.cc")
|
||||
if(CMAKE_SYSTEM_VERSION VERSION_LESS 5.7)
|
||||
add_definitions(-DOPENBSD_WORKAROUND=1)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
|
||||
message(STATUS "NetBSD detected")
|
||||
set(METER_SOURCES "netbsd/memory.cc" "netbsd/cpu.cc" "common/load.cc")
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
message(STATUS "Windows detected")
|
||||
set(METER_SOURCES "windows/memory.cc" "windows/cpu.cc" "windows/load.cc")
|
||||
else()
|
||||
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} Cannot be compiled on this system")
|
||||
message(FATAL_ERROR "Cannot be compiled on this system")
|
||||
endif()
|
||||
|
||||
# set common source files
|
||||
set(COMMON_SOURCES "common/main.cc" "common/graph.cc")
|
||||
|
||||
# add binary tree so we find version.h
|
||||
include_directories("${PROJECT_BINARY_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/common")
|
||||
set(COMMON_SOURCES "common/main.cc" "common/memory.cc" "common/graph.cc" "common/powerline.cc")
|
||||
|
||||
add_executable(tmux-mem-cpu-load ${COMMON_SOURCES} ${METER_SOURCES})
|
||||
# add binary tree so we find version.h
|
||||
target_include_directories(tmux-mem-cpu-load PUBLIC "${PROJECT_BINARY_DIR}")
|
||||
target_include_directories(tmux-mem-cpu-load PUBLIC "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/common")
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
target_link_libraries(tmux-mem-cpu-load Pdh)
|
||||
endif()
|
||||
install(TARGETS tmux-mem-cpu-load RUNTIME DESTINATION bin)
|
||||
|
||||
include(CTest)
|
||||
|
|
@ -111,18 +104,70 @@ if(BUILD_TESTING)
|
|||
COMMAND tmux-mem-cpu-load --colors
|
||||
)
|
||||
|
||||
add_test(NAME colors_short
|
||||
COMMAND tmux-mem-cpu-load -c
|
||||
)
|
||||
|
||||
add_test(NAME powerline-right
|
||||
COMMAND tmux-mem-cpu-load --powerline-right
|
||||
)
|
||||
|
||||
add_test(NAME powerline-left
|
||||
COMMAND tmux-mem-cpu-load --powerline-left
|
||||
)
|
||||
|
||||
add_test(NAME invalid_status_interval
|
||||
COMMAND tmux-mem-cpu-load -i -1
|
||||
)
|
||||
|
||||
add_test(NAME invalid_graph_lines
|
||||
COMMAND tmux-mem-cpu-load --graph_lines -2
|
||||
COMMAND tmux-mem-cpu-load --graph-lines -2
|
||||
)
|
||||
|
||||
add_test(NAME old_option_specification
|
||||
COMMAND tmux-mem-cpu-load 2 8
|
||||
)
|
||||
|
||||
add_test(NAME memory_mode_free_memory
|
||||
COMMAND tmux-mem-cpu-load -m 1
|
||||
)
|
||||
|
||||
add_test(NAME memory_mode_used_percentage
|
||||
COMMAND tmux-mem-cpu-load -m 2
|
||||
)
|
||||
|
||||
add_test(NAME averages_count_0
|
||||
COMMAND tmux-mem-cpu-load -a 0
|
||||
)
|
||||
|
||||
add_test(NAME averages_count_1
|
||||
COMMAND tmux-mem-cpu-load -a 1
|
||||
)
|
||||
|
||||
add_test(NAME averages_count_2
|
||||
COMMAND tmux-mem-cpu-load -a 2
|
||||
)
|
||||
|
||||
add_test(NAME averages_count_3
|
||||
COMMAND tmux-mem-cpu-load -a 3
|
||||
)
|
||||
|
||||
add_test(NAME cpu_mode_0
|
||||
COMMAND tmux-mem-cpu-load --cpu-mode 0
|
||||
)
|
||||
|
||||
add_test(NAME cpu_mode_1
|
||||
COMMAND tmux-mem-cpu-load --cpu-mode 1
|
||||
)
|
||||
|
||||
add_test(NAME cpu_mode_short_0
|
||||
COMMAND tmux-mem-cpu-load -t 0
|
||||
)
|
||||
|
||||
add_test(NAME cpu_mode_short_1
|
||||
COMMAND tmux-mem-cpu-load -t 1
|
||||
)
|
||||
|
||||
set_tests_properties(usage
|
||||
invalid_status_interval
|
||||
invalid_graph_lines
|
||||
|
|
|
|||
115
README.rst
115
README.rst
|
|
@ -1,12 +1,15 @@
|
|||
====================================================
|
||||
tmux-mem-cpu-load
|
||||
====================================================
|
||||
----------------------------------------------------
|
||||
CPU, RAM memory, and load monitor for use with tmux_
|
||||
----------------------------------------------------
|
||||
=============================================
|
||||
tmux-mem-cpu-load
|
||||
=============================================
|
||||
---------------------------------------------
|
||||
CPU, RAM, and load monitor for use with tmux_
|
||||
---------------------------------------------
|
||||
|
||||
.. image:: https://travis-ci.org/thewtex/tmux-mem-cpu-load.svg
|
||||
:target: https://travis-ci.org/thewtex/tmux-mem-cpu-load
|
||||
.. image:: https://circleci.com/gh/thewtex/tmux-mem-cpu-load.svg?style=svg
|
||||
:target: https://circleci.com/gh/thewtex/tmux-mem-cpu-load
|
||||
|
||||
.. image:: https://github.com/thewtex/tmux-mem-cpu-load/actions/workflows/main.yml/badge.svg
|
||||
:target: https://github.com/thewtex/tmux-mem-cpu-load/actions/workflows/main.yml
|
||||
|
||||
Description
|
||||
===========
|
||||
|
|
@ -52,7 +55,7 @@ Currently, Linux, Mac OSX, FreeBSD, OpenBSD, and NetBSD are supported.
|
|||
Building
|
||||
~~~~~~~~
|
||||
|
||||
* >= CMake_ -2.6
|
||||
* >= CMake_ -3.5
|
||||
* C++ compiler with C++11 support (e.g. gcc/g++ >= 4.6)
|
||||
|
||||
Download
|
||||
|
|
@ -78,6 +81,31 @@ Install
|
|||
make install
|
||||
logout
|
||||
|
||||
Build and Install Using tpm_
|
||||
-----------------------------
|
||||
|
||||
Include the plugin in your ``.tmux.conf``, the same file you'll set the
|
||||
configuration in, below.
|
||||
|
||||
::
|
||||
|
||||
set -g @plugin 'thewtex/tmux-mem-cpu-load'
|
||||
|
||||
Install with Package Managers
|
||||
-----------------------------
|
||||
|
||||
* Gentoo: ``emerge tmux-mem-cpu-load``
|
||||
* Homebrew: ``brew install tmux-mem-cpu-load``
|
||||
* FreeBSD: ``pkg install tmux-mem-cpu-load``
|
||||
|
||||
Build and Install Using Antigen_
|
||||
--------------------------------
|
||||
|
||||
Include the bundle in your ``.zshrc``
|
||||
|
||||
::
|
||||
|
||||
antigen bundle thewtex/tmux-mem-cpu-load
|
||||
|
||||
Configuring tmux_
|
||||
=================
|
||||
|
|
@ -89,6 +117,11 @@ Edit ``$HOME/.tmux.conf`` to display the program's output in *status-left* or
|
|||
set -g status-left "#S #[fg=green,bg=black]#(tmux-mem-cpu-load --colors --interval 2)#[default]"
|
||||
set -g status-left-length 60
|
||||
|
||||
If you installed using tpm, you must specify the full path to the
|
||||
``tmux-mem-cpu-load`` script, like below::
|
||||
|
||||
set -g status-right "#[fg=green]#($TMUX_PLUGIN_MANAGER_PATH/tmux-mem-cpu-load/tmux-mem-cpu-load --colors --powerline-right --interval 2)#[default]"
|
||||
|
||||
Note that the *interval* argument to `tmux-mem-cpu-load` should be the same number
|
||||
of seconds that *status-interval* is set at.
|
||||
|
||||
|
|
@ -105,13 +138,64 @@ The full usage::
|
|||
Available options:
|
||||
-h, --help
|
||||
Prints this help message
|
||||
--colors
|
||||
-c, --colors
|
||||
Use tmux colors in output
|
||||
-p, --powerline-left
|
||||
Use powerline left symbols throughout the output, enables --colors
|
||||
-q, --powerline-right
|
||||
Use powerline right symbols throughout the output, enables --colors
|
||||
-v, --vertical-graph
|
||||
Use vertical bar chart for CPU graph
|
||||
-l <value>, --segments-left <value>
|
||||
Enable blending bg/fg color (depending on -p or -q use) with segment to left
|
||||
Provide color to be used depending on -p or -q option for seamless segment blending
|
||||
Color is an integer value which uses the standard tmux color palette values
|
||||
-r <value>, --segments-right <value>
|
||||
Enable blending bg/fg color (depending on -p or -q use) with segment to right
|
||||
Provide color to be used depending on -p or -q option for seamless segment blending
|
||||
Color is an integer value which uses the standard tmux color palette values
|
||||
-i <value>, --interval <value>
|
||||
Set tmux status refresh interval in seconds. Default: 1 second
|
||||
-g <value>, --graph-lines <value>
|
||||
Set how many lines should be drawn in a graph. Default: 10
|
||||
-m <value>, --mem-mode <value>
|
||||
Set memory display mode. 0: Default, 1: Free memory, 2: Usage percent.
|
||||
-t <value>, --cpu-mode <value>
|
||||
Set cpu % display mode. 0: Default max 100%, 1: Max 100% * number of threads.
|
||||
-a <value>, --averages-count <value>
|
||||
Set how many load-averages should be drawn. Default: 3
|
||||
|
||||
Blending Dynamic Colors Tmux Powerline Segments
|
||||
===============================================
|
||||
|
||||
The -l and -r options when used in conjunction with a recent version of Tmux Powerline
|
||||
that has the ability to selectively disable spacing and separators between segments allow
|
||||
for seamless blending of tmux-mem-cpu-load output with other adjacent segments. The end
|
||||
result is dynamic changing of appropriate foreground and background colors as the start
|
||||
and end of the tmux-mem-cpu-load output string that is aggregated with other Tmux
|
||||
Powerline output to produce a more polished status line in Tmux.
|
||||
|
||||
Segment Adjaceny before this feature:
|
||||
|
||||
.. image:: seg-adj1.png
|
||||
|
||||
Segment Adjaceny after this feature:
|
||||
|
||||
.. image:: seg-adj2.png
|
||||
|
||||
Note that the values for the -l and -r options will be the standard Tmux integer color
|
||||
values. They set the appropriate background and foreground colors used for the separator
|
||||
character when used with the poweline-left or powerline-right options so it is easy to
|
||||
match coloring to adjacent segments. An example from the segment script that calls
|
||||
tmux-mem-cpu-load is as follows::
|
||||
|
||||
tmux-mem-cpu-load -q -v -l 52 -r 33
|
||||
|
||||
This combines with theme options available to tmux-powerline, such as the following::
|
||||
|
||||
"disk_usage_cust 52 123 ${TMUX_POWERLINE_SEPARATOR_LEFT_BOLD} 52 123 right_disable" \
|
||||
"tmux_mem_cpu_load_cust 52 234 ${TMUX_POWERLINE_SEPARATOR_LEFT_BOLD} 52 234 both_disable separator_disable" \
|
||||
"batt_cust 33 154 ${TMUX_POWERLINE_SEPARATOR_LEFT_BOLD} 16 33 N separator_disable" \
|
||||
|
||||
Authors
|
||||
=======
|
||||
|
|
@ -120,15 +204,24 @@ Matt McCormick (thewtex) <matt@mmmccormick.com>
|
|||
|
||||
Contributions from:
|
||||
|
||||
* cousine <iam@cousine.me>
|
||||
* Jasper Lievisse Adriaanse <jasper@humppa.nl>
|
||||
* Justin Crawford <justinc@pci-online.net>
|
||||
* krieiter <krieiter@gmail.com>
|
||||
* Mark Palmeri <mlp6@duke.edu>
|
||||
* `Pawel 'l0ner' Soltys`_ <pwslts@gmail.com>
|
||||
|
||||
* Travil Heller <trav.heller@gmail.com>
|
||||
* Tony Narlock <tony@git-pull.com>
|
||||
* Compilenix <Compilenix@compilenix.org>
|
||||
* jodavies <jodavies1010@gmail.com>
|
||||
* `@nhdaly`_ (Nathan Daly) <nhdaly@gmail.com>
|
||||
* bensuperpc <bensuperpc@gmail.com>
|
||||
|
||||
.. _tmux: http://tmux.sourceforge.net/
|
||||
.. _CMake: http://www.cmake.org
|
||||
.. _`project homepage`: http://github.com/thewtex/tmux-mem-cpu-load
|
||||
.. _`tpm`: http://github.com/tmux-plugins/tpm
|
||||
.. _`Antigen`: https://github.com/zsh-users/antigen
|
||||
.. _`terminals with 256 color support`: http://misc.flogisoft.com/bash/tip_colors_and_formatting#terminals_compatibility
|
||||
.. _`Pawel 'l0ner' Soltys` : http://l0ner.github.io/
|
||||
.. _`@nhdaly` : http://github.com/nhdaly
|
||||
|
|
|
|||
6
builder/cmake.sh
Executable file
6
builder/cmake.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
source $(dirname "$0")/functions/cmake_fn.sh
|
||||
|
||||
cmake_build $@
|
||||
11
builder/cmake_all.sh
Executable file
11
builder/cmake_all.sh
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
curl https://raw.githubusercontent.com/dockcross/dockcross/master/Makefile -o dockcross-Makefile
|
||||
make -f dockcross-Makefile display_images
|
||||
|
||||
source $(dirname "$0")/functions/cmake_fn.sh
|
||||
|
||||
for image in $(make -f dockcross-Makefile display_images); do
|
||||
cmake_build $image $@
|
||||
done
|
||||
19
builder/functions/cmake_fn.sh
Executable file
19
builder/functions/cmake_fn.sh
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
cmake_build () {
|
||||
local image=$1
|
||||
local build_file=build-${image%:*}
|
||||
shift 1
|
||||
local cmake_arg=$@
|
||||
echo "cmake arg: $cmake_arg"
|
||||
|
||||
echo "Pulling dockcross/$image"
|
||||
docker pull dockcross/$image
|
||||
echo "Make script dockcross-$image"
|
||||
docker run --rm dockcross/$image > ./dockcross-$image
|
||||
chmod +x ./dockcross-$image
|
||||
echo "Build $build_file"
|
||||
./dockcross-$image cmake -B$build_file -H. -GNinja $cmake_arg
|
||||
./dockcross-$image ninja -C$build_file
|
||||
}
|
||||
15
builder/functions/makefile_fn.sh
Executable file
15
builder/functions/makefile_fn.sh
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
makefile_build () {
|
||||
local image=$1
|
||||
shift 1
|
||||
|
||||
echo "Pulling dockcross/$image"
|
||||
docker pull dockcross/$image
|
||||
echo "Make script dockcross-$image"
|
||||
docker run --rm dockcross/$image > ./dockcross-$image
|
||||
chmod +x ./dockcross-$image
|
||||
echo "Build..."
|
||||
./dockcross-$image bash -c 'make CXX=$CXX CC=$CC AR=$AR AS=$AS CPP=$CPP FC=$FC'
|
||||
}
|
||||
6
builder/makefile.sh
Executable file
6
builder/makefile.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
source $(dirname "$0")/functions/makefile_fn.sh
|
||||
|
||||
makefile_build $@
|
||||
11
builder/makefile_all.sh
Executable file
11
builder/makefile_all.sh
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
curl https://raw.githubusercontent.com/dockcross/dockcross/master/Makefile -o dockcross-Makefile
|
||||
make -f dockcross-Makefile display_images
|
||||
|
||||
source $(dirname "$0")/functions/makefile_fn.sh
|
||||
|
||||
for image in $(make -f dockcross-Makefile display_images); do
|
||||
makefile_build $image $@
|
||||
done
|
||||
|
|
@ -16,7 +16,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
enum
|
||||
#ifndef CONVERSIONS_H_
|
||||
#define CONVERSIONS_H_
|
||||
|
||||
enum BYTE_UNITS
|
||||
{
|
||||
BYTES = 0,
|
||||
KILOBYTES = 1,
|
||||
|
|
@ -33,3 +36,5 @@ inline T convert_unit( T num, int to, int from = BYTES)
|
|||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
21
common/cpu.h
21
common/cpu.h
|
|
@ -19,6 +19,7 @@
|
|||
#ifndef CPU_H_
|
||||
#define CPU_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
|
|
@ -27,12 +28,15 @@
|
|||
#define CP_IDLE 2
|
||||
#define CP_NICE 3
|
||||
#define CP_STATES 4
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <sys/sched.h>
|
||||
#define CP_STATES CPUSTATES
|
||||
#else
|
||||
#define CP_USER 0
|
||||
#define CP_NICE 1
|
||||
#define CP_SYS 2
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
// *BSD or OSX
|
||||
#define CP_INTR 3
|
||||
#define CP_IDLE 4
|
||||
|
|
@ -45,6 +49,19 @@
|
|||
#endif
|
||||
|
||||
float cpu_percentage( unsigned );
|
||||
uint8_t get_cpu_count();
|
||||
uint32_t get_cpu_count();
|
||||
|
||||
/** CPU percentage output mode.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* CPU_MODE_DEFAULT: 100%
|
||||
* CPU_MODE_THREADS: 800% (8 cores, fully loaded)
|
||||
*/
|
||||
enum CPU_MODE
|
||||
{
|
||||
CPU_MODE_DEFAULT,
|
||||
CPU_MODE_THREADS
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@
|
|||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
|
||||
#include "graph.h"
|
||||
|
||||
std::string get_graph_by_percentage( unsigned value, unsigned len )
|
||||
std::string get_graph_by_percentage( unsigned value, unsigned len )
|
||||
{
|
||||
unsigned step = 0;
|
||||
std::string bars;
|
||||
|
|
@ -60,3 +61,20 @@ std::string get_graph_by_value( unsigned value, unsigned max, unsigned len )
|
|||
return bars;
|
||||
}
|
||||
|
||||
std::string get_graph_vert( unsigned value )
|
||||
{
|
||||
static const std::map<unsigned, std::string> graph_chars = {
|
||||
{ 0, " " }, { 10, "▁" }, { 20, "▂" }, { 30, "▃" }, { 40, "▄" },
|
||||
{ 50, "▅" }, { 60, "▆" }, { 70, "▇" }, { 80, "█" }, { 90, "▲" }
|
||||
};
|
||||
|
||||
for( auto it = graph_chars.rbegin(); it != graph_chars.rend(); ++it )
|
||||
{
|
||||
if( value >= it->first )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
return " "; // default return in case value doesn't match map options
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,5 +23,6 @@
|
|||
|
||||
std::string get_graph_by_percentage( unsigned, unsigned len = 10 );
|
||||
std::string get_graph_by_value( unsigned, unsigned, unsigned len = 10 );
|
||||
std::string get_graph_vert( unsigned );
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2013 Justin Crawford <Justasic@gmail.com>
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
* Copyright 2016 Compilenix
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -25,45 +26,68 @@
|
|||
#include <stdlib.h> // getloadavg()
|
||||
#include <cmath> // floorf()
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "load.h"
|
||||
#include "luts.h"
|
||||
|
||||
#include "powerline.h"
|
||||
|
||||
// Load Averages
|
||||
std::string load_string( bool use_colors = false )
|
||||
std::string load_string( bool use_colors,
|
||||
bool use_powerline_left, bool use_powerline_right, short num_averages,
|
||||
bool segments_to_right, short right_color )
|
||||
{
|
||||
std::stringstream ss;
|
||||
// Get only 3 load averages
|
||||
const int nelem = 3;
|
||||
double averages[nelem];
|
||||
std::ostringstream ss;
|
||||
ss.setf( std::ios::fixed, std::ios::floatfield );
|
||||
ss.precision( 2 );
|
||||
|
||||
if( num_averages <= 0 || num_averages > 3)
|
||||
{
|
||||
ss << (char) 0;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
double averages[3];
|
||||
// based on: opensource.apple.com/source/Libc/Libc-262/gen/getloadavg.c
|
||||
|
||||
if( getloadavg( averages, nelem ) < 0 )
|
||||
if( getloadavg( averages, num_averages ) < 0 )
|
||||
{
|
||||
ss << " 0.00 0.00 0.00"; // couldn't get averages.
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned load_percent = static_cast<unsigned int>( averages[0] /
|
||||
get_cpu_count() * 0.5f * 100.0f );
|
||||
|
||||
if( load_percent > 100 )
|
||||
{
|
||||
load_percent = 100;
|
||||
}
|
||||
if( use_colors )
|
||||
{
|
||||
unsigned load_percent = static_cast<unsigned int>( averages[0] /
|
||||
get_cpu_count() * 0.5f * 100.0f );
|
||||
|
||||
if( load_percent > 100 )
|
||||
if( use_powerline_right )
|
||||
{
|
||||
load_percent = 100;
|
||||
powerline( ss, load_lut[load_percent], POWERLINE_RIGHT );
|
||||
}
|
||||
else if( use_powerline_left )
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], POWERLINE_LEFT );
|
||||
}
|
||||
else
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], NONE );
|
||||
}
|
||||
ss << load_lut[load_percent];
|
||||
}
|
||||
|
||||
ss << ' ';
|
||||
for( int i = 0; i < nelem; ++i )
|
||||
for( int i = 0; i < num_averages; ++i )
|
||||
{
|
||||
// Round to nearest, make sure this is only a 0.00 value not a 0.0000
|
||||
float avg = floorf( static_cast<float>( averages[i] ) * 100 + 0.5 ) / 100;
|
||||
// Don't print trailing whitespace for last element
|
||||
if ( i == nelem-1 )
|
||||
if ( i == num_averages-1 )
|
||||
{
|
||||
ss << avg;
|
||||
}
|
||||
|
|
@ -75,7 +99,24 @@ std::string load_string( bool use_colors = false )
|
|||
|
||||
if( use_colors )
|
||||
{
|
||||
ss << "#[fg=default,bg=default]";
|
||||
if( use_powerline_left && segments_to_right )
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], POWERLINE_LEFT, true );
|
||||
powerline_char( ss, load_lut[load_percent], right_color, POWERLINE_LEFT, true );
|
||||
}
|
||||
else if( use_powerline_left && !segments_to_right )
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], POWERLINE_LEFT, true );
|
||||
powerline( ss, "#[fg=default,bg=default]", POWERLINE_LEFT );
|
||||
}
|
||||
else if( !use_powerline_right )
|
||||
{
|
||||
ss << "#[fg=default,bg=default]";
|
||||
}
|
||||
else if ( segments_to_right && use_powerline_right )
|
||||
{
|
||||
powerline_char( ss, load_lut[load_percent], right_color, POWERLINE_RIGHT, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
* Copyright 2016 Compilenix
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,6 +22,9 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
std::string load_string( bool );
|
||||
std::string load_string( bool use_colors = false,
|
||||
bool use_powerline_left = false, bool use_powerline_right = false,
|
||||
short num_averages = 3, bool segments_to_right = false,
|
||||
short right_color = 0 );
|
||||
|
||||
#endif
|
||||
|
|
|
|||
138
common/luts.h
138
common/luts.h
|
|
@ -5,8 +5,74 @@ static const char cpu_percentage_lut[][32] = {
|
|||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
|
|
@ -19,16 +85,12 @@ static const char cpu_percentage_lut[][32] = {
|
|||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
|
|
@ -40,69 +102,7 @@ static const char cpu_percentage_lut[][32] = {
|
|||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour202]",
|
||||
"#[fg=brightwhite,bg=colour202]",
|
||||
"#[fg=brightwhite,bg=colour202]",
|
||||
"#[fg=brightwhite,bg=colour202]",
|
||||
"#[fg=brightwhite,bg=colour202]",
|
||||
"#[fg=brightwhite,bg=colour202]",
|
||||
"#[fg=brightwhite,bg=colour202]",
|
||||
"#[fg=brightwhite,bg=colour202]",
|
||||
"#[fg=brightwhite,bg=colour208]",
|
||||
"#[fg=black,bg=colour208]",
|
||||
"#[fg=black,bg=colour208]",
|
||||
"#[fg=black,bg=colour208]",
|
||||
"#[fg=black,bg=colour208]",
|
||||
"#[fg=black,bg=colour208]",
|
||||
"#[fg=black,bg=colour208]",
|
||||
"#[fg=black,bg=colour214]",
|
||||
"#[fg=black,bg=colour214]",
|
||||
"#[fg=black,bg=colour214]",
|
||||
"#[fg=black,bg=colour214]",
|
||||
"#[fg=black,bg=colour214]",
|
||||
"#[fg=black,bg=colour214]",
|
||||
"#[fg=black,bg=colour214]",
|
||||
"#[fg=black,bg=colour214]",
|
||||
"#[fg=black,bg=colour220]",
|
||||
"#[fg=black,bg=colour220]",
|
||||
"#[fg=black,bg=colour220]",
|
||||
"#[fg=black,bg=colour220]",
|
||||
"#[fg=black,bg=colour220]",
|
||||
"#[fg=black,bg=colour220]",
|
||||
"#[fg=black,bg=colour220]",
|
||||
"#[fg=black,bg=colour226]",
|
||||
"#[fg=black,bg=colour226]",
|
||||
"#[fg=black,bg=colour226]",
|
||||
"#[fg=black,bg=colour226]",
|
||||
"#[fg=black,bg=colour226]",
|
||||
"#[fg=black,bg=colour226]",
|
||||
"#[fg=black,bg=colour227]",
|
||||
"#[fg=black,bg=colour227]",
|
||||
"#[fg=black,bg=colour227]",
|
||||
"#[fg=black,bg=colour227]",
|
||||
"#[fg=black,bg=colour227]",
|
||||
"#[fg=black,bg=colour227]",
|
||||
"#[fg=black,bg=colour228]",
|
||||
"#[fg=black,bg=colour228]",
|
||||
"#[fg=black,bg=colour228]",
|
||||
"#[fg=black,bg=colour228]",
|
||||
"#[fg=black,bg=colour228]",
|
||||
"#[fg=black,bg=colour229]",
|
||||
"#[fg=black,bg=colour229]",
|
||||
"#[fg=black,bg=colour229]",
|
||||
"#[fg=black,bg=colour229]",
|
||||
"#[fg=black,bg=colour229]",
|
||||
"#[fg=black,bg=colour230]",
|
||||
"#[fg=black,bg=colour230]",
|
||||
"#[fg=black,bg=colour230]",
|
||||
"#[fg=black,bg=colour230]",
|
||||
"#[fg=black,bg=colour230]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]"
|
||||
"#[fg=brightwhite,bg=colour196]"
|
||||
}; // end cpu_percentage_lut
|
||||
|
||||
static const char mem_lut[][32] = {
|
||||
|
|
|
|||
165
common/main.cc
165
common/main.cc
|
|
@ -33,11 +33,15 @@
|
|||
#include "memory.h"
|
||||
#include "load.h"
|
||||
|
||||
std::string cpu_string( unsigned int cpu_usage_delay, unsigned int graph_lines,
|
||||
bool use_colors = false )
|
||||
#include "powerline.h"
|
||||
|
||||
std::string cpu_string( CPU_MODE cpu_mode, unsigned int cpu_usage_delay, unsigned int graph_lines,
|
||||
bool use_colors = false,
|
||||
bool use_powerline_left = false, bool use_powerline_right = false, bool use_vert_graph = false)
|
||||
{
|
||||
|
||||
float percentage;
|
||||
float multiplier = 1.0f;
|
||||
|
||||
//output stuff
|
||||
std::ostringstream oss;
|
||||
|
|
@ -47,23 +51,63 @@ std::string cpu_string( unsigned int cpu_usage_delay, unsigned int graph_lines,
|
|||
// get %
|
||||
percentage = cpu_percentage( cpu_usage_delay );
|
||||
|
||||
if( use_colors )
|
||||
// set multiplier to number of threads ?
|
||||
if ( cpu_mode == CPU_MODE_THREADS )
|
||||
{
|
||||
oss << cpu_percentage_lut[static_cast<unsigned int>( percentage )];
|
||||
multiplier = get_cpu_count();
|
||||
}
|
||||
|
||||
if( graph_lines > 0)
|
||||
// if percentage*multiplier >= 100, remove decimal point to keep number short
|
||||
if ( percentage*multiplier >= 100.0f )
|
||||
{
|
||||
oss.precision( 0 );
|
||||
}
|
||||
|
||||
unsigned int percent = static_cast<unsigned int>( percentage );
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_right )
|
||||
{
|
||||
powerline( oss, cpu_percentage_lut[percent], POWERLINE_RIGHT );
|
||||
}
|
||||
else if( use_powerline_left )
|
||||
{
|
||||
powerline( oss, cpu_percentage_lut[percent], POWERLINE_LEFT );
|
||||
}
|
||||
else
|
||||
{
|
||||
powerline( oss, cpu_percentage_lut[percent], NONE );
|
||||
}
|
||||
}
|
||||
|
||||
if( use_vert_graph )
|
||||
{
|
||||
oss << "▕";
|
||||
oss << get_graph_vert( unsigned( percentage ) );
|
||||
oss << "▏";
|
||||
}
|
||||
else if( graph_lines > 0)
|
||||
{
|
||||
oss << " [";
|
||||
oss << get_graph_by_percentage( unsigned( percentage ), graph_lines );
|
||||
oss << "]";
|
||||
}
|
||||
oss.width( 5 );
|
||||
oss << percentage;
|
||||
oss.width( 6 );
|
||||
oss.setf( std::ios::fixed, std::ios::floatfield );
|
||||
oss.precision( 1 );
|
||||
oss.fill( ' ' );
|
||||
oss << std::right << percentage * multiplier;
|
||||
oss << "%";
|
||||
if( use_colors )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
if( use_powerline_left )
|
||||
{
|
||||
powerline( oss, cpu_percentage_lut[percent], POWERLINE_LEFT, true );
|
||||
}
|
||||
else if( !use_powerline_right )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
|
|
@ -79,20 +123,50 @@ void print_help()
|
|||
<< "Available options:\n"
|
||||
<< "-h, --help\n"
|
||||
<< "\t Prints this help message\n"
|
||||
<< "--colors\n"
|
||||
<< "-c, --colors\n"
|
||||
<< "\tUse tmux colors in output\n"
|
||||
<< "-p, --powerline-left\n"
|
||||
<< "\tUse powerline left symbols throughout the output, enables --colors\n"
|
||||
<< "-q, --powerline-right\n"
|
||||
<< "\tUse powerline right symbols throughout the output, enables --colors\n"
|
||||
<< "-v, --vertical-graph\n"
|
||||
<< "\tUse vertical bar chart for CPU graph\n"
|
||||
<< "-l <value>, --segments-left <value>\n"
|
||||
<< "\tEnable blending bg/fg color (depending on -p or -q use) with segment to left\n"
|
||||
<< "\tProvide color to be used depending on -p or -q option for seamless segment blending\n"
|
||||
<< "\tColor is an integer value which uses the standard tmux color palette values\n"
|
||||
<< "-r <value>, --segments-right <value>\n"
|
||||
<< "\tEnable blending bg/fg color (depending on -p or -q use) with segment to right\n"
|
||||
<< "\tProvide color to be used depending on -p or -q option for seamless segment blending\n"
|
||||
<< "\tColor is an integer value which uses the standard tmux color palette values\n"
|
||||
<< "-i <value>, --interval <value>\n"
|
||||
<< "\tSet tmux status refresh interval in seconds. Default: 1 second\n"
|
||||
<< "-g <value>, --graph-lines <value>\n"
|
||||
<< "\tSet how many lines should be drawn in a graph. Default: 10\n"
|
||||
<< "-m <value>, --mem-mode <value>\n"
|
||||
<< "\tSet memory display mode. 0: Default, 1: Free memory, 2: Usage percent.\n"
|
||||
<< "-t <value>, --cpu-mode <value>\n"
|
||||
<< "\tSet cpu % display mode. 0: Default max 100%, 1: Max 100% * number of threads. \n"
|
||||
<< "-a <value>, --averages-count <value>\n"
|
||||
<< "\tSet how many load-averages should be drawn. Default: 3\n"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
unsigned cpu_usage_delay = 990000;
|
||||
short averages_count = 3;
|
||||
short graph_lines = 10; // max 32767 should be enough
|
||||
short left_color = 0;
|
||||
short right_color = 0;
|
||||
bool use_colors = false;
|
||||
bool use_powerline_left = false;
|
||||
bool use_powerline_right = false;
|
||||
bool use_vert_graph = false;
|
||||
bool segments_to_left = false;
|
||||
bool segments_to_right= false;
|
||||
MEMORY_MODE mem_mode = MEMORY_MODE_DEFAULT;
|
||||
CPU_MODE cpu_mode = CPU_MODE_DEFAULT;
|
||||
|
||||
static struct option long_options[] =
|
||||
{
|
||||
|
|
@ -102,14 +176,22 @@ int main( int argc, char** argv )
|
|||
// otherwise it's a value to set the variable *flag points to
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "colors", no_argument, NULL, 'c' },
|
||||
{ "powerline-left", no_argument, NULL, 'p' },
|
||||
{ "powerline-right", no_argument, NULL, 'q' },
|
||||
{ "vertical-graph", no_argument, NULL, 'v' },
|
||||
{ "interval", required_argument, NULL, 'i' },
|
||||
{ "graph-lines", required_argument, NULL, 'g' },
|
||||
{ "mem-mode", required_argument, NULL, 'm' },
|
||||
{ "cpu-mode", required_argument, NULL, 't' },
|
||||
{ "averages-count", required_argument, NULL, 'a' },
|
||||
{ "segments-left", required_argument, NULL, 'l' },
|
||||
{ "segments-right", required_argument, NULL, 'r' },
|
||||
{ 0, 0, 0, 0 } // used to handle unknown long options
|
||||
};
|
||||
|
||||
int c;
|
||||
// while c != -1
|
||||
while( (c = getopt_long( argc, argv, "hi:g:", long_options, NULL) ) != -1 )
|
||||
while( (c = getopt_long( argc, argv, "hi:cpqvl:r:g:m:a:t:", long_options, NULL) ) != -1 )
|
||||
{
|
||||
switch( c )
|
||||
{
|
||||
|
|
@ -120,6 +202,35 @@ int main( int argc, char** argv )
|
|||
case 'c': // --colors
|
||||
use_colors = true;
|
||||
break;
|
||||
case 'p': // --powerline-left
|
||||
use_colors = true;
|
||||
use_powerline_left = true;
|
||||
break;
|
||||
case 'q': // --powerline-right
|
||||
use_colors = true;
|
||||
use_powerline_right = true;
|
||||
break;
|
||||
case 'v': // --vertical-graph
|
||||
use_vert_graph = true;
|
||||
break;
|
||||
case 'l': // --segments-left
|
||||
segments_to_left = true;
|
||||
if( atoi( optarg ) < 0 || atoi( optarg ) > 255 )
|
||||
{
|
||||
std::cerr << "Valid color vaues are from 0 to 255.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
left_color = atoi( optarg ) ;
|
||||
break;
|
||||
case 'r': // --segments-right
|
||||
segments_to_right= true;
|
||||
if( atoi( optarg ) < 0 || atoi( optarg ) > 255 )
|
||||
{
|
||||
std::cerr << "Valid color vaues are from 0 to 255.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
right_color = atoi( optarg ) ;
|
||||
break;
|
||||
case 'i': // --interval, -i
|
||||
if( atoi( optarg ) < 1 )
|
||||
{
|
||||
|
|
@ -136,6 +247,30 @@ int main( int argc, char** argv )
|
|||
}
|
||||
graph_lines = atoi( optarg );
|
||||
break;
|
||||
case 'm': // --mem-mode, -m
|
||||
if( atoi( optarg ) < 0 )
|
||||
{
|
||||
std::cerr << "Memory mode argument must be zero or greater.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
mem_mode = static_cast< MEMORY_MODE >( atoi( optarg ) );
|
||||
break;
|
||||
case 't': // --cpu-mode, -t
|
||||
if( atoi( optarg ) < 0 )
|
||||
{
|
||||
std::cerr << "CPU mode argument must be zero or greater.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cpu_mode = static_cast< CPU_MODE >( atoi( optarg ) );
|
||||
break;
|
||||
case 'a': // --averages-count, -a
|
||||
if( atoi( optarg ) < 0 || atoi( optarg ) > 3 )
|
||||
{
|
||||
std::cerr << "Valid averages-count arguments are: 0, 1, 2, 3\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
averages_count = atoi( optarg );
|
||||
break;
|
||||
case '?':
|
||||
// getopt_long prints error message automatically
|
||||
return EXIT_FAILURE;
|
||||
|
|
@ -154,9 +289,13 @@ int main( int argc, char** argv )
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::cout << mem_string( use_colors )
|
||||
<< cpu_string( cpu_usage_delay, graph_lines, use_colors )
|
||||
<< load_string( use_colors );
|
||||
MemoryStatus memory_status;
|
||||
mem_status( memory_status );
|
||||
std::cout << mem_string( memory_status, mem_mode, use_colors, use_powerline_left, use_powerline_right, segments_to_left, left_color )
|
||||
<< cpu_string( cpu_mode, cpu_usage_delay, graph_lines, use_colors, use_powerline_left, use_powerline_right, use_vert_graph )
|
||||
<< load_string( use_colors, use_powerline_left, use_powerline_right, averages_count, segments_to_right, right_color );
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
122
common/memory.cc
Normal file
122
common/memory.cc
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "memory.h"
|
||||
#include "luts.h"
|
||||
#include "conversions.h"
|
||||
#include "powerline.h"
|
||||
|
||||
std::string mem_string( const MemoryStatus & mem_status,
|
||||
MEMORY_MODE mode,
|
||||
bool use_colors,
|
||||
bool use_powerline_left,
|
||||
bool use_powerline_right,
|
||||
bool segments_to_left,
|
||||
short left_color )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
// Change the percision for floats, for a pretty output
|
||||
oss.precision( 2 );
|
||||
oss.setf( std::ios::fixed | std::ios::right );
|
||||
|
||||
unsigned int color = static_cast< unsigned int >((100 * mem_status.used_mem) / mem_status.total_mem);
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_right && segments_to_left )
|
||||
{
|
||||
powerline_char( oss, mem_lut[color], left_color, POWERLINE_RIGHT, false);
|
||||
oss << ' ';
|
||||
}
|
||||
else if( use_powerline_right && !segments_to_left )
|
||||
{
|
||||
oss << "#[bg=default]";
|
||||
powerline( oss, mem_lut[color], POWERLINE_RIGHT );
|
||||
oss << ' ';
|
||||
}
|
||||
else if( use_powerline_left && segments_to_left )
|
||||
{
|
||||
powerline_char( oss, mem_lut[color], left_color, POWERLINE_LEFT, false);
|
||||
oss << ' ';
|
||||
}
|
||||
else if( use_powerline_left )
|
||||
{
|
||||
//powerline( oss, mem_lut[color], POWERLINE_LEFT );
|
||||
// We do not know how to invert the default background color
|
||||
powerline( oss, mem_lut[color], NONE );
|
||||
oss << ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
powerline( oss, mem_lut[color], NONE );
|
||||
}
|
||||
}
|
||||
|
||||
switch( mode )
|
||||
{
|
||||
case MEMORY_MODE_FREE_MEMORY: // Show free memory in MB or GB
|
||||
{
|
||||
const float free_mem = mem_status.total_mem - mem_status.used_mem;
|
||||
const float free_mem_in_gigabytes = convert_unit( free_mem, GIGABYTES, MEGABYTES );
|
||||
|
||||
// if free memory is less than 1 GB, use MB instead
|
||||
if( free_mem_in_gigabytes < 1.0f )
|
||||
{
|
||||
oss << free_mem << "MB";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << free_mem_in_gigabytes << "GB";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MEMORY_MODE_USAGE_PERCENTAGE:
|
||||
{
|
||||
// Calculate the percentage of used memory
|
||||
const float percentage_mem = mem_status.used_mem /
|
||||
static_cast<float>( mem_status.total_mem ) * 100.0;
|
||||
|
||||
oss << percentage_mem << '%';
|
||||
break;
|
||||
}
|
||||
default: // Default mode, just show the used/total memory in MB
|
||||
if(mem_status.used_mem>10000 && mem_status.total_mem>10000)
|
||||
oss<<static_cast<unsigned int>(mem_status.used_mem/1024)<<"/"<<static_cast<unsigned int>(mem_status.total_mem/1024)<<"GB";
|
||||
else if(mem_status.used_mem<10000 && mem_status.total_mem>10000)
|
||||
oss<<static_cast<unsigned int>(mem_status.used_mem)<<"MB/"<<static_cast<unsigned int>(mem_status.total_mem/1024)<<"GB";
|
||||
else
|
||||
oss<<static_cast<unsigned int>(mem_status.used_mem)<<"/"<<static_cast<unsigned int>(mem_status.total_mem)<<"MB";
|
||||
}
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_left )
|
||||
{
|
||||
powerline( oss, mem_lut[color], POWERLINE_LEFT, true );
|
||||
}
|
||||
else if( !use_powerline_right )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
|
@ -21,6 +21,38 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
std::string mem_string( bool );
|
||||
/** Memory status in megabytes */
|
||||
struct MemoryStatus
|
||||
{
|
||||
float used_mem;
|
||||
float total_mem;
|
||||
};
|
||||
|
||||
/** Get the current memory status */
|
||||
void mem_status( MemoryStatus & status );
|
||||
|
||||
|
||||
/** Memory status string output mode.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* MEMORY_MODE_DEFAULT: 11156/16003MB
|
||||
* MEMORY_MODE_FREE_MEMORY:
|
||||
* MEMORY_MODE_USAGE_PERCENTAGE:
|
||||
*/
|
||||
enum MEMORY_MODE
|
||||
{
|
||||
MEMORY_MODE_DEFAULT,
|
||||
MEMORY_MODE_FREE_MEMORY,
|
||||
MEMORY_MODE_USAGE_PERCENTAGE
|
||||
};
|
||||
|
||||
std::string mem_string( const MemoryStatus & mem_status,
|
||||
MEMORY_MODE mode = MEMORY_MODE_DEFAULT,
|
||||
bool use_colors = false,
|
||||
bool use_powerline_left = false,
|
||||
bool use_powerline_right = false,
|
||||
bool segments_to_left = false,
|
||||
short left_color = 0 );
|
||||
|
||||
#endif
|
||||
|
|
|
|||
102
common/powerline.cc
Normal file
102
common/powerline.cc
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2016 Michał Goliński
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "powerline.h"
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#define PWL_LEFT_FILLED ""
|
||||
#define PWL_RIGHT_FILLED ""
|
||||
|
||||
const char * bg2fg( const char s[] )
|
||||
{
|
||||
static char buf[40] = {0};
|
||||
const char *substr = strchr(s, ',');
|
||||
buf[0] = '#';
|
||||
buf[1] = '[';
|
||||
buf[2] = 'f';
|
||||
strcpy(buf+3, substr+2);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
void powerline( std::ostringstream & oss, const char color[],
|
||||
POWERLINE_DIRECTION direction, bool background_only )
|
||||
{
|
||||
switch( direction )
|
||||
{
|
||||
case NONE:
|
||||
oss << color;
|
||||
break;
|
||||
case POWERLINE_LEFT:
|
||||
if( background_only )
|
||||
{
|
||||
oss << ' ' << bg2fg( color );
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string colorstr( color );
|
||||
oss << "#[" << colorstr.substr( colorstr.find( "," ) + 1 )
|
||||
<< PWL_LEFT_FILLED
|
||||
<< color;
|
||||
}
|
||||
break;
|
||||
case POWERLINE_RIGHT:
|
||||
oss << ' '
|
||||
<< bg2fg( color )
|
||||
<< PWL_RIGHT_FILLED
|
||||
<< color;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
void powerline_char( std::ostringstream & oss, const char dynamic_color[],
|
||||
short static_color, POWERLINE_DIRECTION direction, bool eol )
|
||||
{
|
||||
char write_color[7];
|
||||
sprintf(write_color, "%d", static_color);
|
||||
switch( direction )
|
||||
{
|
||||
case NONE:
|
||||
break;
|
||||
case POWERLINE_LEFT:
|
||||
if ( eol )
|
||||
{
|
||||
oss << bg2fg( dynamic_color ) << "#[bg=colour" << write_color << "]";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << dynamic_color << "#[fg=colour" << write_color << "]";
|
||||
}
|
||||
oss << PWL_LEFT_FILLED << dynamic_color;
|
||||
break;
|
||||
case POWERLINE_RIGHT:
|
||||
if ( eol )
|
||||
{
|
||||
oss << dynamic_color << "#[fg=colour" << write_color << "] ";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << bg2fg(dynamic_color) << " #[bg=colour" << write_color << "]";
|
||||
}
|
||||
oss << PWL_RIGHT_FILLED << dynamic_color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
40
common/powerline.h
Normal file
40
common/powerline.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2016 Michał Goliński
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef POWERLINE_H
|
||||
#define POWERLINE_H
|
||||
|
||||
#include <sstream>
|
||||
|
||||
enum POWERLINE_DIRECTION
|
||||
{
|
||||
NONE,
|
||||
POWERLINE_LEFT,
|
||||
POWERLINE_RIGHT
|
||||
};
|
||||
|
||||
/** Print out a powerline left character inverted version of the given
|
||||
* color. In the case of of using powerline left, the background color needs
|
||||
* to be inverted to the foreground before the powerline character is printed
|
||||
* in the next entr. */
|
||||
void powerline( std::ostringstream & oss, const char color[],
|
||||
POWERLINE_DIRECTION direction, bool background_only = false );
|
||||
void powerline_char( std::ostringstream & oss, const char dynamic_color[],
|
||||
short static_color, POWERLINE_DIRECTION direction, bool eol = false );
|
||||
|
||||
#endif // POWERLINE_H
|
||||
|
|
@ -26,12 +26,12 @@
|
|||
#include "getsysctl.h"
|
||||
#include "cpu.h"
|
||||
|
||||
uint8_t get_cpu_count()
|
||||
uint32_t get_cpu_count()
|
||||
{
|
||||
int32_t cpu_count = 0;
|
||||
GETSYSCTL( "hw.ncpu", cpu_count );
|
||||
|
||||
return static_cast<uint8_t>( cpu_count );
|
||||
return static_cast<uint32_t>( cpu_count );
|
||||
}
|
||||
|
||||
float cpu_percentage( unsigned int cpu_usage_delay )
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "getsysctl.h"
|
||||
#include "memory.h"
|
||||
#include "luts.h"
|
||||
#include "conversions.h"
|
||||
|
||||
std::string mem_string( bool use_colors = false )
|
||||
void mem_status( MemoryStatus & status )
|
||||
{
|
||||
// These values are in bytes
|
||||
//u_int total;
|
||||
|
|
@ -39,13 +39,12 @@ std::string mem_string( bool use_colors = false )
|
|||
u_int active;
|
||||
u_int page_size;
|
||||
u_int page_count;
|
||||
std::ostringstream oss;
|
||||
|
||||
// Get total physical memory, page size, and some other needed info
|
||||
// instead of using realmem which reports quantity of ram installed on
|
||||
// platform, use physmem which reports ram available to system.
|
||||
//GETSYSCTL( "hw.physmem", total );
|
||||
GETSYSCTL( "hw.pagesize", page_size );
|
||||
page_size = getpagesize();
|
||||
// page count reflects actual size of memory we have available for
|
||||
// applications. it will be less than realmem or physmem, since it doesn't
|
||||
// include what's been allocated for kernel, but it will be equal to
|
||||
|
|
@ -64,20 +63,8 @@ std::string mem_string( bool use_colors = false )
|
|||
//u_int unused = ( cache + inactive + free ) * page_size;
|
||||
|
||||
// Used memory on FreeBSD is active + wired.
|
||||
u_int used = ( active + wired ) * page_size;
|
||||
u_int used = ( active + wired );
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << mem_lut[ ( 100 * used ) / ( page_count * page_size ) ];
|
||||
}
|
||||
|
||||
oss << convert_unit( used, MEGABYTES ) << '/'
|
||||
<< convert_unit( page_count * page_size, MEGABYTES ) << "MB";
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
status.used_mem = convert_unit( static_cast< float >( used * (page_size >> 10) ), MEGABYTES, KILOBYTES );
|
||||
status.total_mem = convert_unit( static_cast< float >( page_count * (page_size >> 10) ), MEGABYTES, KILOBYTES);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
#include "cpu.h"
|
||||
#include "luts.h"
|
||||
|
||||
uint8_t get_cpu_count()
|
||||
uint32_t get_cpu_count()
|
||||
{
|
||||
return sysconf( _SC_NPROCESSORS_ONLN );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,31 +21,26 @@
|
|||
#include <sys/sysinfo.h>
|
||||
|
||||
#include "memory.h"
|
||||
#include "luts.h"
|
||||
#include "conversions.h"
|
||||
|
||||
std::string mem_string( bool use_colors = false )
|
||||
void mem_status( MemoryStatus & status )
|
||||
{
|
||||
using std::string;
|
||||
using std::ifstream;
|
||||
using std::stoi;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
string line, substr;
|
||||
std::string line;
|
||||
std::string substr;
|
||||
size_t substr_start;
|
||||
size_t substr_len;
|
||||
|
||||
unsigned int total_mem, used_mem;
|
||||
unsigned int total_mem;
|
||||
unsigned int used_mem;
|
||||
|
||||
/* Since linux uses some RAM for disk caching, the actuall used ram is lower
|
||||
* than what sysinfo(), top or free reports. htop reports the usage in a
|
||||
/* Since linux uses some RAM for disk caching, the actuall used ram is lower
|
||||
* than what sysinfo(), top or free reports. htop reports the usage in a
|
||||
* correct way. The memory used for caching doesn't count as used, since it
|
||||
* can be freed in any moment. Usually it hapens automatically, when an
|
||||
* application requests memory.
|
||||
* In order to calculate the ram that's actually used we need to use the
|
||||
* In order to calculate the ram that's actually used we need to use the
|
||||
* following formula:
|
||||
* total_ram - free_ram - buffered_ram - cached_ram
|
||||
* total_ram + shmem - free_ram - buffered_ram - cached_ram - srclaimable
|
||||
*
|
||||
* example data, junk removed, with comments added:
|
||||
*
|
||||
|
|
@ -59,9 +54,9 @@ std::string mem_string( bool use_colors = false )
|
|||
* SwapFree: 60352 kB old
|
||||
*/
|
||||
|
||||
ifstream memory_info("/proc/meminfo");
|
||||
std::ifstream memory_info("/proc/meminfo");
|
||||
|
||||
while( getline( memory_info, line ) )
|
||||
while( std::getline( memory_info, line ) )
|
||||
{
|
||||
substr_start = 0;
|
||||
substr_len = line.find_first_of( ':' );
|
||||
|
|
@ -71,35 +66,28 @@ std::string mem_string( bool use_colors = false )
|
|||
if( substr.compare( "MemTotal" ) == 0 )
|
||||
{
|
||||
// get total memory
|
||||
total_mem = stoi( line.substr( substr_start, substr_len ) );
|
||||
total_mem = stol( line.substr( substr_start, substr_len ) );
|
||||
}
|
||||
else if( substr.compare( "MemFree" ) == 0 )
|
||||
{
|
||||
used_mem = total_mem - stoi( line.substr( substr_start, substr_len ) );
|
||||
used_mem = total_mem - stol( line.substr( substr_start, substr_len ) );
|
||||
}
|
||||
else if( substr.compare( "Shmem" ) == 0 )
|
||||
{
|
||||
used_mem += stol( line.substr( substr_start, substr_len ) );
|
||||
}
|
||||
else if( substr.compare( "Buffers" ) == 0 ||
|
||||
substr.compare( "Cached" ) == 0 )
|
||||
substr.compare( "Cached" ) == 0 ||
|
||||
substr.compare( "SReclaimable" ) == 0 )
|
||||
{
|
||||
used_mem -= stoi( line.substr( substr_start, substr_len ) );
|
||||
used_mem -= stol( line.substr( substr_start, substr_len ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << mem_lut[(100 * used_mem) / total_mem];
|
||||
}
|
||||
|
||||
// we want megabytes on output, but since the values already come as
|
||||
// we want megabytes on output, but since the values already come as
|
||||
// kilobytes we need to divide them by 1024 only once, thus we use
|
||||
// KILOBYTES
|
||||
oss << convert_unit(used_mem, MEGABYTES, KILOBYTES) << '/'
|
||||
<< convert_unit(total_mem, MEGABYTES, KILOBYTES) << "MB";
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
status.used_mem = convert_unit(static_cast< float >( used_mem ), MEGABYTES, KILOBYTES);
|
||||
status.total_mem = convert_unit(static_cast< float >( total_mem ), MEGABYTES, KILOBYTES);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@
|
|||
#include "getsysctl.h"
|
||||
#include "cpu.h"
|
||||
|
||||
uint8_t get_cpu_count()
|
||||
uint32_t get_cpu_count()
|
||||
{
|
||||
int cpu_count = 0;
|
||||
GETSYSCTL( "hw.ncpu", cpu_count );
|
||||
|
||||
return static_cast<uint8_t>( cpu_count );
|
||||
return static_cast<uint32_t>( cpu_count );
|
||||
}
|
||||
|
||||
float cpu_percentage( unsigned int cpu_usage_delay )
|
||||
|
|
|
|||
|
|
@ -24,14 +24,11 @@
|
|||
#include <uvm/uvm_extern.h> // uvmexp struct
|
||||
|
||||
#include "error.h"
|
||||
#include "luts.h"
|
||||
#include "conversions.h"
|
||||
#include "memory.h"
|
||||
|
||||
std::string mem_string( bool use_colors = false )
|
||||
void mem_status( MemoryStatus & status )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
// get vm memory stats
|
||||
static int vm_totalmem[] = { CTL_VM, VM_UVMEXP2 };
|
||||
struct uvmexp_sysctl mem;
|
||||
|
|
@ -42,23 +39,10 @@ std::string mem_string( bool use_colors = false )
|
|||
}
|
||||
|
||||
int64_t total_mem = ( mem.npages << mem.pageshift );
|
||||
int64_t used_mem =
|
||||
int64_t used_mem =
|
||||
( mem.active + mem.wired - mem.filepages ) << mem.pageshift;
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << mem_lut[( 100 * used_mem ) / total_mem];
|
||||
}
|
||||
|
||||
// add 1 to used which gets lost somewhere along conversions
|
||||
oss << convert_unit( used_mem, MEGABYTES )
|
||||
<< '/' << convert_unit( total_mem, MEGABYTES ) << "MB";
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
|
||||
status.used_mem = convert_unit(static_cast< float >( used_mem ), MEGABYTES );
|
||||
status.total_mem = convert_unit(static_cast< float >( total_mem ), MEGABYTES );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@
|
|||
#include "error.h"
|
||||
#include "cpu.h"
|
||||
|
||||
uint8_t get_cpu_count()
|
||||
uint32_t get_cpu_count()
|
||||
{
|
||||
int cpu_count = 1; // default to 1
|
||||
int mib[2] = { CTL_HW, HW_NCPU };
|
||||
int mib[2] = { CTL_HW, HW_NCPUONLINE };
|
||||
size_t len = sizeof( cpu_count );
|
||||
|
||||
if( sysctl( mib, 2, &cpu_count, &len, NULL, 0 ) < 0 )
|
||||
|
|
@ -35,7 +35,7 @@ uint8_t get_cpu_count()
|
|||
error( "sysctl: error getting cpu count" );
|
||||
}
|
||||
|
||||
return cpu_count;
|
||||
return static_cast<uint32_t>( cpu_count );
|
||||
}
|
||||
|
||||
float cpu_percentage( unsigned int cpu_usage_delay )
|
||||
|
|
@ -55,6 +55,8 @@ float cpu_percentage( unsigned int cpu_usage_delay )
|
|||
|
||||
usleep( cpu_usage_delay );
|
||||
|
||||
size = sizeof( load2 );
|
||||
|
||||
// update cpu times
|
||||
if( sysctl( cpu_ctl, 2, &load2, &size, NULL, 0 ) < 0 )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,20 +37,10 @@
|
|||
|
||||
#include "error.h"
|
||||
#include "memory.h"
|
||||
#include "luts.h"
|
||||
#include "conversions.h"
|
||||
|
||||
static int pageshift;
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
#define pagesh(size) ((size) << pageshift)
|
||||
|
||||
std::string mem_string( bool use_colors = false )
|
||||
void mem_status( MemoryStatus & status )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
// These values are in bytes
|
||||
int64_t total_mem = 0;
|
||||
int64_t used_mem = 0;
|
||||
|
|
@ -66,16 +56,6 @@ std::string mem_string( bool use_colors = false )
|
|||
error( "memory: error getting page size" );
|
||||
}
|
||||
|
||||
// calculate how far we must shift the variables
|
||||
pageshift = 0;
|
||||
while( page_size > 1 )
|
||||
{
|
||||
pageshift++;
|
||||
page_size >>= 1;
|
||||
}
|
||||
|
||||
pageshift -= LOG1024;
|
||||
|
||||
// get vm memory stats
|
||||
static int uvmexp_mib[] = { CTL_VM, VM_UVMEXP };
|
||||
struct uvmexp uvmexp;
|
||||
|
|
@ -95,29 +75,16 @@ std::string mem_string( bool use_colors = false )
|
|||
}
|
||||
|
||||
// calculations based on libgtop
|
||||
used_mem = (uint64_t) pagesh (uvmexp.npages - uvmexp.free) << LOG1024;
|
||||
|
||||
free_mem = (uint64_t) pagesh( uvmexp.free ) << LOG1024;
|
||||
used_mem = ( (uint64_t) uvmexp.npages - uvmexp.free ) << uvmexp.pageshift;
|
||||
free_mem = ( (uint64_t) uvmexp.free ) << uvmexp.pageshift;
|
||||
|
||||
// from nagios-memory plugin
|
||||
used_mem -= pagesh( bcstats.numbufpages );
|
||||
free_mem += pagesh( bcstats.numbufpages );
|
||||
used_mem -= ( (uint64_t) bcstats.numbufpages ) << uvmexp.pageshift;
|
||||
free_mem += ( (uint64_t) bcstats.numbufpages ) << uvmexp.pageshift;
|
||||
|
||||
// calculate total memory
|
||||
total_mem = (uint64_t) pagesh( uvmexp.npages ) << LOG1024;
|
||||
total_mem = ( (uint64_t) uvmexp.npages ) << uvmexp.pageshift;
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << mem_lut[( 100 * used_mem ) / total_mem];
|
||||
}
|
||||
|
||||
oss << convert_unit( used_mem, MEGABYTES )
|
||||
<< '/' << convert_unit( total_mem, MEGABYTES ) << "MB";
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
status.used_mem = convert_unit(static_cast< float >( used_mem ), MEGABYTES );
|
||||
status.total_mem = convert_unit(static_cast< float >( total_mem ), MEGABYTES );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "cpu.h"
|
||||
|
||||
uint8_t get_cpu_count()
|
||||
uint32_t get_cpu_count()
|
||||
{
|
||||
return sysconf( _SC_NPROCESSORS_ONLN );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,20 +22,22 @@
|
|||
#include <sys/sysctl.h> // for sysctl
|
||||
|
||||
#include "memory.h"
|
||||
#include "luts.h"
|
||||
#include "conversions.h"
|
||||
|
||||
std::string mem_string( bool use_colors )
|
||||
void mem_status( MemoryStatus & status )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
// These values are in bytes
|
||||
u_int64_t total_mem;
|
||||
u_int64_t used_mem;
|
||||
// float app_mem = 0.0f;
|
||||
// float cached_file_mem = 0.0f;
|
||||
float available_mem = 0.0f;
|
||||
float percentage_mem;
|
||||
float free_mem;
|
||||
float free_mem_in_gigabytes; // used to check if free mem < 1 GB
|
||||
//u_int64_t unused_mem;
|
||||
|
||||
vm_size_t page_size;
|
||||
vm_statistics_data_t vm_stats;
|
||||
vm_statistics64_data_t vm_stats; // Use 64-bit VM statistics
|
||||
|
||||
// Get total physical memory
|
||||
int mib[] = { CTL_HW, HW_MEMSIZE };
|
||||
|
|
@ -43,30 +45,21 @@ std::string mem_string( bool use_colors )
|
|||
sysctl( mib, 2, &total_mem, &length, NULL, 0 );
|
||||
|
||||
mach_port_t mach_port = mach_host_self();
|
||||
mach_msg_type_number_t count = sizeof( vm_stats ) / sizeof( natural_t );
|
||||
|
||||
// Use HOST_VM_INFO64_COUNT as the count for vm_statistics64_data_t
|
||||
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
|
||||
|
||||
if( KERN_SUCCESS == host_page_size( mach_port, &page_size ) &&
|
||||
KERN_SUCCESS == host_statistics( mach_port, HOST_VM_INFO,
|
||||
( host_info_t )&vm_stats, &count )
|
||||
KERN_SUCCESS == host_statistics64( mach_port, HOST_VM_INFO64,
|
||||
( host_info_t )&vm_stats, &count )
|
||||
)
|
||||
{
|
||||
//unused_mem = static_cast<u_int64_t>( vm_stats.free_count * page_size );
|
||||
|
||||
used_mem = static_cast<u_int64_t>(
|
||||
( vm_stats.active_count + vm_stats.wire_count ) * page_size);
|
||||
// app_mem = static_cast<float>(( vm_stats.internal_page_count - vm_stats.purgeable_count ) * page_size );
|
||||
// cached_file_mem = static_cast<float>(( vm_stats.purgeable_count + vm_stats.external_page_count ) * page_size );
|
||||
available_mem = static_cast<float>(( vm_stats.free_count + vm_stats.external_page_count - vm_stats.speculative_count ) * page_size );
|
||||
}
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << mem_lut[( 100 * used_mem ) / total_mem];
|
||||
}
|
||||
|
||||
oss << convert_unit( used_mem, MEGABYTES ) << '/'
|
||||
<< convert_unit( total_mem, MEGABYTES ) << "MB";
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
status.used_mem = convert_unit(static_cast< float >(total_mem - available_mem ), MEGABYTES );
|
||||
status.total_mem = convert_unit(static_cast< float >( total_mem ), MEGABYTES );
|
||||
}
|
||||
|
|
|
|||
BIN
seg-adj1.png
Normal file
BIN
seg-adj1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
BIN
seg-adj2.png
Normal file
BIN
seg-adj2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
49
tmux-mem-cpu-load.plugin.tmux
Executable file
49
tmux-mem-cpu-load.plugin.tmux
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
# vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
#
|
||||
# Copyright 2012 Matthew McCormick
|
||||
# Copyright 2015 Pawel 'l0ner' Soltys
|
||||
#
|
||||
# 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.
|
||||
|
||||
# The directory where this plugin is located.
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
if [ ! -f $CURRENT_DIR/tmux-mem-cpu-load ] && ! $(builtin type -P "tmux-mem-cpu-load" &> /dev/null) ; then
|
||||
tmux run-shell "echo \"tmux-mem-cpu-load not found. Attempting to build.
|
||||
\""
|
||||
|
||||
pushd $CURRENT_DIR #Pushd to the directory where this plugin is located.
|
||||
|
||||
# Attempt to rebuild the plugin and log any errors in the tmux display window.
|
||||
if output=$(cmake . 2>&1); then
|
||||
tmux run-shell "echo \"'cmake $CURRENT_DIR' completed successfully.
|
||||
\""
|
||||
else
|
||||
tmux run-shell "echo \"'cmake $CURRENT_DIR' failed. Error logged below.
|
||||
$output
|
||||
\""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if output=$(cmake --build . 2>&1); then
|
||||
tmux run-shell "echo \"tmux-mem-cpu-load built successfully.
|
||||
\""
|
||||
else
|
||||
tmux run-shell "echo \"tmux-mem-cpu-load failed to build. Error logged below.
|
||||
$output
|
||||
\""
|
||||
exit 1
|
||||
fi
|
||||
popd
|
||||
fi
|
||||
|
||||
25
tmux-mem-cpu-load.plugin.zsh
Normal file
25
tmux-mem-cpu-load.plugin.zsh
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
#
|
||||
# Copyright 2012 Matthew McCormick
|
||||
# Copyright 2015 Pawel 'l0ner' Soltys
|
||||
#
|
||||
# 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.
|
||||
|
||||
if [ ! -s /usr/local/bin/tmux-mem-cpu-load ];
|
||||
then
|
||||
pushd ${0:a:h} #Pushd to the directory where this plugin is located.
|
||||
cmake .
|
||||
make
|
||||
sudo make install
|
||||
popd
|
||||
fi
|
||||
53
windows/cpu.cc
Normal file
53
windows/cpu.cc
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <unistd.h> // usleep
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "TCHAR.h"
|
||||
#include "pdh.h"
|
||||
|
||||
static PDH_HQUERY cpuQuery;
|
||||
static PDH_HCOUNTER cpuTotal;
|
||||
|
||||
#include "cpu.h"
|
||||
#include "luts.h"
|
||||
|
||||
uint32_t get_cpu_count()
|
||||
{
|
||||
return static_cast< uint32_t >( std::thread::hardware_concurrency() );
|
||||
}
|
||||
|
||||
float cpu_percentage( unsigned cpu_usage_delay )
|
||||
{
|
||||
PdhOpenQuery(NULL, 0, &cpuQuery);
|
||||
PdhAddCounter(cpuQuery, "\\Processor(_Total)\\% Processor Time", 0, &cpuTotal);
|
||||
PdhCollectQueryData(cpuQuery);
|
||||
|
||||
usleep( cpu_usage_delay );
|
||||
|
||||
PDH_FMT_COUNTERVALUE counterVal;
|
||||
|
||||
PdhCollectQueryData(cpuQuery);
|
||||
PdhGetFormattedCounterValue(cpuTotal, PDH_FMT_DOUBLE, NULL, &counterVal);
|
||||
return static_cast< float >( counterVal.doubleValue );
|
||||
}
|
||||
|
||||
44
windows/load.cc
Normal file
44
windows/load.cc
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2013 Justin Crawford <Justasic@gmail.com>
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
* Copyright 2016 Compilenix
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Based on: github.com/freebsd/freebsd/blob/master/usr.bin/top/machine.c
|
||||
// Based on: Apple.cpp for load_string/mem_string and apple's documentation
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cmath> // floorf()
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "load.h"
|
||||
#include "luts.h"
|
||||
|
||||
#include "powerline.h"
|
||||
|
||||
// Load Averages
|
||||
std::string load_string( bool use_colors,
|
||||
bool use_powerline_left, bool use_powerline_right,
|
||||
short num_averages )
|
||||
{
|
||||
// Not implemented
|
||||
std::ostringstream ss;
|
||||
ss << (char) 0;
|
||||
return ss.str();
|
||||
}
|
||||
40
windows/memory.cc
Normal file
40
windows/memory.cc
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#include "memory.h"
|
||||
#include "conversions.h"
|
||||
|
||||
void mem_status( MemoryStatus & status )
|
||||
{
|
||||
MEMORYSTATUSEX memory_status;
|
||||
memory_status.dwLength = sizeof(memory_status);
|
||||
|
||||
GlobalMemoryStatusEx(&memory_status);
|
||||
|
||||
// we want megabytes on output, but since the values already come as
|
||||
// kilobytes we need to divide them by 1024 only once, thus we use
|
||||
// KILOBYTES
|
||||
status.used_mem = convert_unit(static_cast< float >( memory_status.ullAvailPhys ), MEGABYTES, BYTES);
|
||||
status.total_mem = convert_unit(static_cast< float >( memory_status.ullTotalPhys ), MEGABYTES, BYTES);
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue