[PATCH 1/3] Add a script for showing stats about zRAM

Vratislav Podzimek vpodzime at redhat.com
Mon Jul 21 15:15:11 UTC 2014


Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 scripts/Makefile.am |  2 +-
 scripts/makeupdates |  3 ++-
 scripts/zram-stats  | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100755 scripts/zram-stats

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index c9105a1..9bcfdcc 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -18,7 +18,7 @@
 # Author: David Cantrell <dcantrell at redhat.com>
 
 scriptsdir = $(libexecdir)/$(PACKAGE_NAME)
-dist_scripts_SCRIPTS = upd-updates run-anaconda anaconda-yum zramswapon zramswapoff
+dist_scripts_SCRIPTS = upd-updates run-anaconda anaconda-yum zramswapon zramswapoff zram-stats
 dist_noinst_SCRIPTS  = upd-kernel makeupdates
 
 dist_bin_SCRIPTS = analog anaconda-cleanup instperf
diff --git a/scripts/makeupdates b/scripts/makeupdates
index 574694f..4d143cd 100755
--- a/scripts/makeupdates
+++ b/scripts/makeupdates
@@ -295,7 +295,8 @@ def copyUpdatedFiles(tag, updates, cwd):
             install_to_dir(gitfile, "usr/share/anaconda/ui")
         elif gitfile.startswith("data/post-scripts/"):
             install_to_dir(gitfile, "usr/share/anaconda/post-scripts")
-        elif any(gitfile.endswith(libexec_script) for libexec_script in ("anaconda-yum", "zramswapon", "zramswapoff")):
+        elif any(gitfile.endswith(libexec_script) for libexec_script in \
+                 ("anaconda-yum", "zramswapon", "zramswapoff", "zram-stats")):
             install_to_dir(gitfile, "usr/libexec/anaconda")
         elif gitfile.endswith("AnacondaWidgets.py"):
             import gi
diff --git a/scripts/zram-stats b/scripts/zram-stats
new file mode 100755
index 0000000..8d95c95
--- /dev/null
+++ b/scripts/zram-stats
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+##
+# Show stats for all (initialized) zram devices
+# Author: Nitin Gupta
+#
+
+stats=(
+	"disksize"
+	"num_reads"
+	"num_writes"
+	"invalid_io"
+#	"discard"
+	"notify_free"
+	"zero_pages"
+	"orig_data_size"
+	"compr_data_size"
+	"mem_used_total"
+)
+
+function get_stat()
+{
+	local _dev=$1
+	local _stat=$2
+	cat $dev/$_stat
+}
+
+function show_stat()
+{
+	local _name=$1
+	local _val=$2
+	local _unit=$3
+	printf "%-16s %11d %s\n" "$_name:" "$_val" "$_unit"
+}
+
+#for dev in `find /sys/block -name 'zram*'`; do
+find /sys/block -name 'zram*' | while read dev; do
+	orig=0
+	compr=0
+	total=0
+	is_init=$(get_stat $dev initstate)
+
+	# Show stats only for initialized devices
+	[ "$is_init" == 1 ] || continue
+
+	echo "$dev"
+	for stat in "${stats[@]}"; do
+		val=$(get_stat $dev $stat)
+		eval __$stat=$val	# ex: __disksize=$disksize
+		show_stat $stat $val
+	done
+
+	[ "$__orig_data_size" == "0" ] && continue;
+
+	cratio=$(echo "print $__compr_data_size*100/$__orig_data_size" | python | tr -d '\n')
+	show_stat "avg_compr_ratio" $cratio "%"
+
+	# Memory wasted due to fragmentation, metadata overhead etc.
+	ovhd=$(echo "print ($__mem_used_total - $__compr_data_size) * 100 / \
+						$__compr_data_size" | python | tr -d '\n')
+	show_stat "mem_overhead" $ovhd "%"
+	echo
+done
+
-- 
1.9.3



More information about the anaconda-patches mailing list