Skip to content

Commit

Permalink
Split out the memory into a separate tab
Browse files Browse the repository at this point in the history
and add some more information about memory and swap
  • Loading branch information
tronical committed Oct 8, 2021
1 parent bcf4f2b commit 0c4da48
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 11 deletions.
68 changes: 58 additions & 10 deletions examples/bash/sysinfo.60
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Please contact info@sixtyfps.io for more information.
LICENSE END */

import { TabWidget, StandardButton, GridBox, ListView } from "sixtyfps_widgets.60";
import { TabWidget, StandardButton, GridBox, VerticalBox, ListView } from "sixtyfps_widgets.60";


SysInfo := Dialog {
Expand All @@ -18,6 +18,10 @@ SysInfo := Dialog {
property cpu_model <=> cpu-model.text;
property cpu_vendor <=> cpu-vendor.text;
property<int> mem_size_kb;
property<int> buffer_mem_size_kb;
property<int> swap_total_kb;
property<int> swap_used_kb;
property<int> swap_free_kb;
property <[{dev: string, mnt: string, total: int, free: int}]> partitions;
title: "System information";

Expand Down Expand Up @@ -77,30 +81,74 @@ SysInfo := Dialog {
cpu-count := Text {}
}
Row {
Text {
Text{
col: 1;
text: "Memory Size:";
text: "Uptime:";
max-width: min-width;
}
uptime := Text {}
}
Rectangle {}
}
}

Tab {
title: "Memory";
GridBox {
Row {
Text {
text: "\{floor(mem_size_kb / (1000*1000))} GB";
text: "Installed Memory:";
max-width: min-width;
}
Text {
text: "\{floor(mem_size_kb / (1024*1024))} GiB";
}
}
Row {
Text{
col: 1;
text: "Uptime:";
Text {
text: "Buffer/Cache Memory:";
max-width: min-width;
}
uptime := Text {}
Text {
text: "\{floor(buffer_mem_size_kb / (1024*1024))} GiB";
}
}
Row {
Text {
text: "Swap Total:";
max-width: min-width;
}
Text {
text: "\{floor(swap_total_kb / (1024*1024))} GiB";
}
}
Row {
Text {
text: "Swap Used:";
max-width: min-width;
}
Text {
text: "\{floor(swap_used_kb / (1024*1024))} GiB";
}
}
Row {
Text {
text: "Swap Free:";
max-width: min-width;
}
Text {
text: "\{floor(swap_free_kb / (1024*1024))} GiB";
}
}
Row {
Rectangle {}
}
Rectangle {}
}
}

Tab {
title: "Partitions";
VerticalLayout {
VerticalBox {
padding: 5px;

HorizontalLayout {
Expand Down
8 changes: 8 additions & 0 deletions examples/bash/sysinfo_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ cpu_vendor=`awk -F ": " '/vendor_id/{ print $2; exit}' < /proc/cpuinfo | tr -d '
cpu_model=`awk -F ": " '/model name/{ print $2; exit}' < /proc/cpuinfo | tr -d '"\\\\'`
mem_size_kb=`sed -n -e "s,MemTotal:\s\+\(.*\)\s\+.\+,\1,p"< /proc/meminfo`
partitions=`df -T --block-size=1 | tail -n+2 | awk 'NR > 1 { printf(", ") } {printf "{ \"dev\": \"%s\", \"mnt\": \"%s\", \"total\": %s, \"free\": %s }", $1,$7, $3, $5}'`
buffer_mem_size_kb=`sed -n -e "s,Buffers:\s\+\(.*\)\s\+.\+,\1,p"< /proc/meminfo`
swap_total_kb=`sed -n -e "s,SwapTotal:\s\+\(.*\)\s\+.\+,\1,p"< /proc/meminfo`
swap_free_kb=`sed -n -e "s,SwapFree:\s\+\(.*\)\s\+.\+,\1,p"< /proc/meminfo`
swap_used_kb=$(swap_total_kb - swap_free_kb))

sixtyfps-viewer `dirname $0`/sysinfo.60 --load-data - <<EOT
{
Expand All @@ -30,6 +34,10 @@ sixtyfps-viewer `dirname $0`/sysinfo.60 --load-data - <<EOT
"cpu_vendor": "$cpu_vendor",
"cpu_model": "$cpu_model",
"mem_size_kb": $mem_size_kb,
"buffer_mem_size_kb": $buffer_mem_size_kb,
"swap_total_kb": $swap_total_kb,
"swap_used_kb": $swap_used_kb,
"swap_free_kb": $swap_free_kb,
"partitions": [ $partitions ]
}
EOT
16 changes: 15 additions & 1 deletion examples/bash/sysinfo_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ uptime=`uptime | awk 'BEGIN{FS="up |,"}{print $2}'`
cpu_count=`sysctl -n hw.ncpu`
cpu_vendor=`sysctl -n machdep.cpu.vendor`
cpu_model=`sysctl -n machdep.cpu.brand_string`
mem_size_kb=`sysctl -n hw.memsize`
mem_size_kb=$((`sysctl -n hw.memsize` / 1000))
page_size=`vm_stat | grep "Mach Virtual Memory Statistics" | sed -n -e 's,.*page size of \(.*\) bytes.*,\1,p'`
pages_inactive=`vm_stat|grep "Pages inactive" | sed -e "s,Pages inactive:[[:space:]]*\(.*\)\.,\1,"`
file_backed_pages=`vm_stat|grep "File-backed pages" | sed -e "s,File-backed pages:[[:space:]]*\(.*\)\.,\1,"`
buffer_mem_size_kb=$(((pages_inactive + file_backed_pages) * page_size / 1024))
swap_total_mb=`sysctl -n vm.swapusage | sed -n -e 's,total = \(.*\)\..*M.*used.*,\1,p'`
swap_total_kb=$(($swap_total_mb * 1024))
swap_used_mb=`sysctl -n vm.swapusage | sed -n -e 's,.*used = \(.*\)\..*M.*free.*,\1,p'`
swap_used_kb=$((swap_used_mb * 1024))
swap_free_mb=`sysctl -n vm.swapusage | sed -n -e 's,.*free = \(.*\)\..*M.*$,\1,p'`
swap_free_kb=$((swap_free_mb * 1024))
partitions=`df -lk | tail -n+2 | sed 's/\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\)/{ "dev": "\1", "mnt": "\9", "total": \2, "free": \4 },/' | sed '$s/,$//'`

sixtyfps-viewer `dirname $0`/sysinfo.60 --load-data - <<EOT
Expand All @@ -27,6 +37,10 @@ sixtyfps-viewer `dirname $0`/sysinfo.60 --load-data - <<EOT
"cpu_vendor": "$cpu_vendor",
"cpu_model": "$cpu_model",
"mem_size_kb": $mem_size_kb,
"buffer_mem_size_kb": $buffer_mem_size_kb,
"swap_total_kb": $swap_total_kb,
"swap_used_kb": $swap_used_kb,
"swap_free_kb": $swap_free_kb,
"partitions": [ $partitions ]
}
EOT

0 comments on commit 0c4da48

Please sign in to comment.