* [PATCH 0/2 V3] memory usage tracing update
@ 2013-01-17 8:55 dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-01-17 8:55 ` [PATCH 1/2 V3] add function getargnum dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-01-17 8:55 ` [PATCH 2/2 V3] Add memory usage trace to diffrent hook points dyoung-H+wXaHxf7aLQT0dZR+AlfA
0 siblings, 2 replies; 7+ messages in thread
From: dyoung-H+wXaHxf7aLQT0dZR+AlfA @ 2013-01-17 8:55 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: vgoyal-H+wXaHxf7aLQT0dZR+AlfA, jstancek-H+wXaHxf7aLQT0dZR+AlfA,
initramfs-u79uwXL29TY76Z2rM5mHXA
Hi,
This is the v3 patch set. There's several fixes per Harald's comments.
Please review.
Thanks
Dave
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2 V3] add function getargnum
2013-01-17 8:55 [PATCH 0/2 V3] memory usage tracing update dyoung-H+wXaHxf7aLQT0dZR+AlfA
@ 2013-01-17 8:55 ` dyoung-H+wXaHxf7aLQT0dZR+AlfA
[not found] ` <20130117085724.062434676-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-17 8:55 ` [PATCH 2/2 V3] Add memory usage trace to diffrent hook points dyoung-H+wXaHxf7aLQT0dZR+AlfA
1 sibling, 1 reply; 7+ messages in thread
From: dyoung-H+wXaHxf7aLQT0dZR+AlfA @ 2013-01-17 8:55 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: vgoyal-H+wXaHxf7aLQT0dZR+AlfA, jstancek-H+wXaHxf7aLQT0dZR+AlfA,
initramfs-u79uwXL29TY76Z2rM5mHXA, Dave Young
[-- Attachment #1: patch1 --]
[-- Type: text/plain, Size: 1505 bytes --]
For cmdline argument with numeric value, add a new function getargnum
It will get proper value with default value as $1, min value as $2,
max value as $3, and param name as $4. valid result will be echo to stdout.
for nul or value not valid it will just echo the default value.
Note: The values should be >=0
[v1->v2]: add arg <minval>
[v2->v3]: do not use bash string match =~
Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
modules.d/99base/dracut-lib.sh | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
--- dracut.orig/modules.d/99base/dracut-lib.sh
+++ dracut/modules.d/99base/dracut-lib.sh
@@ -167,6 +167,35 @@ getargbool() {
return 0
}
+isdigit() {
+ case "$1" in
+ *[!0-9]*|"") return 1;;
+ esac
+
+ return 0
+}
+
+# getargnum <defaultval> <minval> <maxval> <arg>
+# Will echo the arg if it's in range [minval - maxval].
+# If it's not set or it's not valid, will set it <defaultval>.
+# Note all values are required to be >= 0 here.
+# <defaultval> should be with [minval -maxval].
+getargnum() {
+ local _b
+ unset _b
+ local _default _min _max
+ _default=$1; shift
+ _min=$1; shift
+ _max=$1; shift
+ _b=$(getarg "$1")
+ [ $? -ne 0 -a -z "$_b" ] && _b=$_default
+ if [ -n "$_b" ]; then
+ isdigit "$_b" && _b=$(($_b)) && \
+ [[ $_b -ge $_min && $_b -le $_max ]] && echo $_b && return
+ fi
+ echo $_default
+}
+
_dogetargs() {
debug_off
local _o _found _key
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2 V3] Add memory usage trace to diffrent hook points
2013-01-17 8:55 [PATCH 0/2 V3] memory usage tracing update dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-01-17 8:55 ` [PATCH 1/2 V3] add function getargnum dyoung-H+wXaHxf7aLQT0dZR+AlfA
@ 2013-01-17 8:55 ` dyoung-H+wXaHxf7aLQT0dZR+AlfA
[not found] ` <20130117085724.212324334-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
1 sibling, 1 reply; 7+ messages in thread
From: dyoung-H+wXaHxf7aLQT0dZR+AlfA @ 2013-01-17 8:55 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: vgoyal-H+wXaHxf7aLQT0dZR+AlfA, jstancek-H+wXaHxf7aLQT0dZR+AlfA,
initramfs-u79uwXL29TY76Z2rM5mHXA, Dave Young
[-- Attachment #1: patch2 --]
[-- Type: text/plain, Size: 6719 bytes --]
Port mkdumprd memory trace functions wrote by jstancek-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
For kdump, memory usage tracing is important because there's limited
memory in kdump 2nd kernel.
Add a rd.memdebug cmdline for this. set rd.memdebug=<X> will set the
debug level to X which is the debug verbose level.
the format of cmdline is like below:
<level>[+]:<type>
<level> is the debug level
[+] means debug level >= <level>
<type> is the debug info type, as for this patch I added mem, iomem, slab
mem is for /proc/meminfo, iomem is for /proc/iomem, slab is for /proc/slabinfo
Also shortmem is the stripped /proc/meminfo which only includes 3 lines of
Memfree, Cached and Slab, for example:
MemFree: 6327176 kB
Cached: 741916 kB
Slab: 77284 kB
I added several trace point to the begin of several init hooks
At cmdline hooks I'm adding trace of "1+:mem 1+:iomem 3+:slab"
For other hooks I'm adding trace of "1:shortmem 2+:mem 3+:slab"
This means:
rd.memdebug=1)
cmdline hook: print mem and iomem
other hooks: print shortmem
rd.memdebug=2)
cmdline hook: print mem and iomem
other hooks: print mem
rd.memdebug=3):
cmdline hook: print mem iomem, and slabinfo
other hooks: print mem and slabinfo
*):
do not print any mem debug info
[v1->v2]: update to use getargnum with <minval> as argument
print iomem info at cmdline hook as well
[v2->v3]: harald: use $() instead of ``
use bash string match instead of grep and pipe.
Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
dracut.cmdline.7.asc | 4 +
modules.d/98systemd/dracut-cmdline.sh | 1
modules.d/98systemd/dracut-initqueue.sh | 1
modules.d/98systemd/dracut-pre-pivot.sh | 1
modules.d/98systemd/dracut-pre-trigger.sh | 1
modules.d/98systemd/dracut-pre-udev.sh | 1
modules.d/99base/dracut-lib.sh | 91 ++++++++++++++++++++++++++++++
7 files changed, 100 insertions(+)
--- dracut.orig/modules.d/98systemd/dracut-cmdline.sh
+++ dracut/modules.d/98systemd/dracut-cmdline.sh
@@ -18,6 +18,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook cmdline" 1+:mem 1+:iomem 3+:slab
# run scriptlets to parse the command line
getarg 'rd.break=cmdline' -d 'rdbreak=cmdline' && emergency_shell -n cmdline "Break before cmdline"
source_hook cmdline
--- dracut.orig/modules.d/98systemd/dracut-initqueue.sh
+++ dracut/modules.d/98systemd/dracut-initqueue.sh
@@ -10,6 +10,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook initqueue" 1:shortmem 2+:mem 3+:slab
getarg 'rd.break=initqueue' -d 'rdbreak=initqueue' && emergency_shell -n initqueue "Break before initqueue"
RDRETRY=$(getarg rd.retry -d 'rd_retry=')
--- dracut.orig/modules.d/98systemd/dracut-pre-pivot.sh
+++ dracut/modules.d/98systemd/dracut-pre-pivot.sh
@@ -10,6 +10,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook pre-pivot" 1:shortmem 2+:mem 3+:slab
# pre pivot scripts are sourced just before we doing cleanup and switch over
# to the new root.
getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot "Break pre-pivot"
--- dracut.orig/modules.d/98systemd/dracut-pre-trigger.sh
+++ dracut/modules.d/98systemd/dracut-pre-trigger.sh
@@ -10,6 +10,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook pre-trigger" 1:shortmem 2+:mem 3+:slab
getargbool 0 rd.udev.info -n -y rdudevinfo && udevadm control --log-priority=info
getargbool 0 rd.udev.debug -n -y rdudevdebug && udevadm control --log-priority=debug
udevproperty "hookdir=$hookdir"
--- dracut.orig/modules.d/98systemd/dracut-pre-udev.sh
+++ dracut/modules.d/98systemd/dracut-pre-udev.sh
@@ -9,6 +9,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook pre-udev" 1:shortmem 2+:mem 3+:slab
# pre pivot scripts are sourced just before we doing cleanup and switch over
# to the new root.
getarg 'rd.break=pre-udev' 'rdbreak=pre-udev' && emergency_shell -n pre-udev "Break pre-udev"
--- dracut.orig/dracut.cmdline.7.asc
+++ dracut/dracut.cmdline.7.asc
@@ -143,6 +143,10 @@ It should be attached to any report abou
If systemd is not active, the logs are written to dmesg and _/run/initramfs/init.log_.
If "quiet" is set, it also logs to the console.
+**rd.memdebug=[0-3]**::
+ print memory usage debug info, set the verbose level from 1 to 3
+ print nothing when set rd.memdebug=0
+
**rd.break**::
drop to a shell at the end
--- dracut.orig/modules.d/99base/dracut-lib.sh
+++ dracut/modules.d/99base/dracut-lib.sh
@@ -994,3 +994,94 @@ listlist() {
are_lists_eq() {
listlist "$1" "$2" "$3" "$4" && listlist "$1" "$3" "$2" "$4"
}
+
+setmemdebug() {
+ if [ -z "$DEBUG_MEM_LEVEL" ]; then
+ export DEBUG_MEM_LEVEL=$(getargnum 0 0 3 rd.memdebug)
+ fi
+}
+
+setmemdebug
+
+# parameters: msg [trace_level:trace]...
+function make_trace_mem()
+{
+ msg=$1
+ shift
+ if [ "$DEBUG_MEM_LEVEL" -gt 0 ]; then
+ make_trace show_memstats $DEBUG_MEM_LEVEL "[debug_mem]" "$msg" "$@"
+ fi
+}
+
+# parameters: func log_level prefix msg [trace_level:trace]...
+function make_trace()
+{
+ func=$1
+ shift
+
+ log_level=$1
+ shift
+
+ prefix=$1
+ shift
+
+ msg=$1
+ shift
+
+ if [ -z "$log_level" ]; then
+ return
+ fi
+
+ msg=$(echo $msg)
+
+ msg_printed=0
+ while [ $# -gt 0 ]; do
+ trace=${1%%:*}
+ trace_level=${trace%%+}
+ [ "$trace" != "$trace_level" ] && trace_in_higher_levels="yes"
+ trace=${1##*:}
+
+ if [ -z "$trace_level" ]; then
+ trace_level=0
+ fi
+
+ insert_trace=0
+ if [ -n "$trace_in_higher_levels" ]; then
+ if [ "$log_level" -ge "$trace_level" ]; then
+ insert_trace=1
+ fi
+ else
+ if [ "$log_level" -eq "$trace_level" ]; then
+ insert_trace=1
+ fi
+ fi
+
+ if [ $insert_trace -eq 1 ]; then
+ if [ $msg_printed -eq 0 ]; then
+ echo "$prefix $msg"
+ msg_printed=1
+ fi
+ $func $trace
+ fi
+ shift
+ done
+}
+
+# parameters: type
+show_memstats()
+{
+ case $1 in
+ shortmem)
+ cat /proc/meminfo | grep -e "^MemFree" -e "^Cached" -e "^Slab"
+ ;;
+ mem)
+ cat /proc/meminfo
+ ;;
+ slab)
+ cat /proc/slabinfo
+ ;;
+ iomem)
+ cat /proc/iomem
+ ;;
+ esac
+}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2 V3] Add memory usage trace to diffrent hook points
[not found] ` <20130117085724.212324334-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2013-01-17 13:43 ` Harald Hoyer
[not found] ` <50F7FFF2.4020309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Harald Hoyer @ 2013-01-17 13:43 UTC (permalink / raw)
To: dyoung-H+wXaHxf7aLQT0dZR+AlfA
Cc: vgoyal-H+wXaHxf7aLQT0dZR+AlfA, jstancek-H+wXaHxf7aLQT0dZR+AlfA,
initramfs-u79uwXL29TY76Z2rM5mHXA
Am 17.01.2013 09:55, schrieb dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org:
> Port mkdumprd memory trace functions wrote by jstancek-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
> For kdump, memory usage tracing is important because there's limited
> memory in kdump 2nd kernel.
>
> Add a rd.memdebug cmdline for this. set rd.memdebug=<X> will set the
> debug level to X which is the debug verbose level.
>
> the format of cmdline is like below:
> <level>[+]:<type>
> <level> is the debug level
> [+] means debug level >= <level>
> <type> is the debug info type, as for this patch I added mem, iomem, slab
> mem is for /proc/meminfo, iomem is for /proc/iomem, slab is for /proc/slabinfo
> Also shortmem is the stripped /proc/meminfo which only includes 3 lines of
> Memfree, Cached and Slab, for example:
> MemFree: 6327176 kB
> Cached: 741916 kB
> Slab: 77284 kB
>
> I added several trace point to the begin of several init hooks
> At cmdline hooks I'm adding trace of "1+:mem 1+:iomem 3+:slab"
> For other hooks I'm adding trace of "1:shortmem 2+:mem 3+:slab"
>
> This means:
> rd.memdebug=1)
> cmdline hook: print mem and iomem
> other hooks: print shortmem
> rd.memdebug=2)
> cmdline hook: print mem and iomem
> other hooks: print mem
> rd.memdebug=3):
> cmdline hook: print mem iomem, and slabinfo
> other hooks: print mem and slabinfo
> *):
> do not print any mem debug info
>
> [v1->v2]: update to use getargnum with <minval> as argument
> print iomem info at cmdline hook as well
> [v2->v3]: harald: use $() instead of ``
> use bash string match instead of grep and pipe.
>
> Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
> dracut.cmdline.7.asc | 4 +
> modules.d/98systemd/dracut-cmdline.sh | 1
> modules.d/98systemd/dracut-initqueue.sh | 1
> modules.d/98systemd/dracut-pre-pivot.sh | 1
> modules.d/98systemd/dracut-pre-trigger.sh | 1
> modules.d/98systemd/dracut-pre-udev.sh | 1
> modules.d/99base/dracut-lib.sh | 91 ++++++++++++++++++++++++++++++
> 7 files changed, 100 insertions(+)
>
...
> --- dracut.orig/modules.d/99base/dracut-lib.sh
> +++ dracut/modules.d/99base/dracut-lib.sh
...
> +# parameters: msg [trace_level:trace]...
> +function make_trace_mem()
> +{
local msg
> + msg=$1
> + shift
> + if [ "$DEBUG_MEM_LEVEL" -gt 0 ]; then
> + make_trace show_memstats $DEBUG_MEM_LEVEL "[debug_mem]" "$msg" "$@"
> + fi
> +}
> +
> +# parameters: func log_level prefix msg [trace_level:trace]...
> +function make_trace()
> +{
local func
local log_level
local prefix
.....
> + func=$1
> + shift
> +
> + log_level=$1
> + shift
> +
> + prefix=$1
> + shift
> +
> + msg=$1
> + shift
> +
> + if [ -z "$log_level" ]; then
> + return
> + fi
> +
> + msg=$(echo $msg)
> +
> + msg_printed=0
> + while [ $# -gt 0 ]; do
> + trace=${1%%:*}
> + trace_level=${trace%%+}
> + [ "$trace" != "$trace_level" ] && trace_in_higher_levels="yes"
> + trace=${1##*:}
> +
> + if [ -z "$trace_level" ]; then
> + trace_level=0
> + fi
> +
> + insert_trace=0
> + if [ -n "$trace_in_higher_levels" ]; then
> + if [ "$log_level" -ge "$trace_level" ]; then
> + insert_trace=1
> + fi
> + else
> + if [ "$log_level" -eq "$trace_level" ]; then
> + insert_trace=1
> + fi
> + fi
> +
> + if [ $insert_trace -eq 1 ]; then
> + if [ $msg_printed -eq 0 ]; then
> + echo "$prefix $msg"
> + msg_printed=1
> + fi
> + $func $trace
> + fi
> + shift
> + done
> +}
> +
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2 V4] Add memory usage trace to diffrent hook points
[not found] ` <50F7FFF2.4020309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2013-01-18 1:59 ` Dave Young
[not found] ` <50F8AC98.1060308-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Dave Young @ 2013-01-18 1:59 UTC (permalink / raw)
To: Harald Hoyer
Cc: vgoyal-H+wXaHxf7aLQT0dZR+AlfA, jstancek-H+wXaHxf7aLQT0dZR+AlfA,
initramfs-u79uwXL29TY76Z2rM5mHXA
Hi, Here is an update of this patch, fixed the local variable issue.
---
Add memory usage trace to diffrent hook points
Port mkdumprd memory trace functions wrote by jstancek-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
For kdump, memory usage tracing is important because there's limited
memory in kdump 2nd kernel.
Add a rd.memdebug cmdline for this. set rd.memdebug=<X> will set the
debug level to X which is the debug verbose level.
the format of cmdline is like below:
<level>[+]:<type>
<level> is the debug level
[+] means debug level >= <level>
<type> is the debug info type, as for this patch I added mem, iomem, slab
mem is for /proc/meminfo, iomem is for /proc/iomem, slab is for /proc/slabinfo
Also shortmem is the stripped /proc/meminfo which only includes 3 lines of
Memfree, Cached and Slab, for example:
MemFree: 6327176 kB
Cached: 741916 kB
Slab: 77284 kB
I added several trace point to the begin of several init hooks
At cmdline hooks I'm adding trace of "1+:mem 1+:iomem 3+:slab"
For other hooks I'm adding trace of "1:shortmem 2+:mem 3+:slab"
This means:
rd.memdebug=1)
cmdline hook: print mem and iomem
other hooks: print shortmem
rd.memdebug=2)
cmdline hook: print mem and iomem
other hooks: print mem
rd.memdebug=3):
cmdline hook: print mem iomem, and slabinfo
other hooks: print mem and slabinfo
*):
do not print any mem debug info
[v1->v2]: update to use getargnum with <minval> as argument
print iomem info at cmdline hook as well
[v2->v3]: harald: use $() instead of ``
use bash string match instead of grep and pipe.
[v3->v4]: harald: use local variables in function.
Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
dracut.cmdline.7.asc | 4 +
modules.d/98systemd/dracut-cmdline.sh | 1
modules.d/98systemd/dracut-initqueue.sh | 1
modules.d/98systemd/dracut-pre-pivot.sh | 1
modules.d/98systemd/dracut-pre-trigger.sh | 1
modules.d/98systemd/dracut-pre-udev.sh | 1
modules.d/99base/dracut-lib.sh | 94 ++++++++++++++++++++++++++++++
7 files changed, 103 insertions(+)
--- dracut.orig/modules.d/98systemd/dracut-cmdline.sh
+++ dracut/modules.d/98systemd/dracut-cmdline.sh
@@ -18,6 +18,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook cmdline" 1+:mem 1+:iomem 3+:slab
# run scriptlets to parse the command line
getarg 'rd.break=cmdline' -d 'rdbreak=cmdline' && emergency_shell -n cmdline "Break before cmdline"
source_hook cmdline
--- dracut.orig/modules.d/98systemd/dracut-initqueue.sh
+++ dracut/modules.d/98systemd/dracut-initqueue.sh
@@ -10,6 +10,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook initqueue" 1:shortmem 2+:mem 3+:slab
getarg 'rd.break=initqueue' -d 'rdbreak=initqueue' && emergency_shell -n initqueue "Break before initqueue"
RDRETRY=$(getarg rd.retry -d 'rd_retry=')
--- dracut.orig/modules.d/98systemd/dracut-pre-pivot.sh
+++ dracut/modules.d/98systemd/dracut-pre-pivot.sh
@@ -10,6 +10,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook pre-pivot" 1:shortmem 2+:mem 3+:slab
# pre pivot scripts are sourced just before we doing cleanup and switch over
# to the new root.
getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot "Break pre-pivot"
--- dracut.orig/modules.d/98systemd/dracut-pre-trigger.sh
+++ dracut/modules.d/98systemd/dracut-pre-trigger.sh
@@ -10,6 +10,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook pre-trigger" 1:shortmem 2+:mem 3+:slab
getargbool 0 rd.udev.info -n -y rdudevinfo && udevadm control --log-priority=info
getargbool 0 rd.udev.debug -n -y rdudevdebug && udevadm control --log-priority=debug
udevproperty "hookdir=$hookdir"
--- dracut.orig/modules.d/98systemd/dracut-pre-udev.sh
+++ dracut/modules.d/98systemd/dracut-pre-udev.sh
@@ -9,6 +9,7 @@ type getarg >/dev/null 2>&1 || . /lib/dr
source_conf /etc/conf.d
+make_trace_mem "hook pre-udev" 1:shortmem 2+:mem 3+:slab
# pre pivot scripts are sourced just before we doing cleanup and switch over
# to the new root.
getarg 'rd.break=pre-udev' 'rdbreak=pre-udev' && emergency_shell -n pre-udev "Break pre-udev"
--- dracut.orig/dracut.cmdline.7.asc
+++ dracut/dracut.cmdline.7.asc
@@ -143,6 +143,10 @@ It should be attached to any report abou
If systemd is not active, the logs are written to dmesg and _/run/initramfs/init.log_.
If "quiet" is set, it also logs to the console.
+**rd.memdebug=[0-3]**::
+ print memory usage debug info, set the verbose level from 1 to 3
+ print nothing when set rd.memdebug=0
+
**rd.break**::
drop to a shell at the end
--- dracut.orig/modules.d/99base/dracut-lib.sh
+++ dracut/modules.d/99base/dracut-lib.sh
@@ -994,3 +994,97 @@ listlist() {
are_lists_eq() {
listlist "$1" "$2" "$3" "$4" && listlist "$1" "$3" "$2" "$4"
}
+
+setmemdebug() {
+ if [ -z "$DEBUG_MEM_LEVEL" ]; then
+ export DEBUG_MEM_LEVEL=$(getargnum 0 0 3 rd.memdebug)
+ fi
+}
+
+setmemdebug
+
+# parameters: msg [trace_level:trace]...
+function make_trace_mem()
+{
+ local msg=$1
+ shift
+ if [ "$DEBUG_MEM_LEVEL" -gt 0 ]; then
+ make_trace show_memstats $DEBUG_MEM_LEVEL "[debug_mem]" "$msg" "$@"
+ fi
+}
+
+# parameters: func log_level prefix msg [trace_level:trace]...
+function make_trace()
+{
+ local func log_level prefix msg msg_printed
+ local trace trace_level trace_in_higher_levels insert_trace
+
+ func=$1
+ shift
+
+ log_level=$1
+ shift
+
+ prefix=$1
+ shift
+
+ msg=$1
+ shift
+
+ if [ -z "$log_level" ]; then
+ return
+ fi
+
+ msg=$(echo $msg)
+
+ msg_printed=0
+ while [ $# -gt 0 ]; do
+ trace=${1%%:*}
+ trace_level=${trace%%+}
+ [ "$trace" != "$trace_level" ] && trace_in_higher_levels="yes"
+ trace=${1##*:}
+
+ if [ -z "$trace_level" ]; then
+ trace_level=0
+ fi
+
+ insert_trace=0
+ if [ -n "$trace_in_higher_levels" ]; then
+ if [ "$log_level" -ge "$trace_level" ]; then
+ insert_trace=1
+ fi
+ else
+ if [ "$log_level" -eq "$trace_level" ]; then
+ insert_trace=1
+ fi
+ fi
+
+ if [ $insert_trace -eq 1 ]; then
+ if [ $msg_printed -eq 0 ]; then
+ echo "$prefix $msg"
+ msg_printed=1
+ fi
+ $func $trace
+ fi
+ shift
+ done
+}
+
+# parameters: type
+show_memstats()
+{
+ case $1 in
+ shortmem)
+ cat /proc/meminfo | grep -e "^MemFree" -e "^Cached" -e "^Slab"
+ ;;
+ mem)
+ cat /proc/meminfo
+ ;;
+ slab)
+ cat /proc/slabinfo
+ ;;
+ iomem)
+ cat /proc/iomem
+ ;;
+ esac
+}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2 V3] add function getargnum
[not found] ` <20130117085724.062434676-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2013-01-22 14:32 ` Harald Hoyer
0 siblings, 0 replies; 7+ messages in thread
From: Harald Hoyer @ 2013-01-22 14:32 UTC (permalink / raw)
To: dyoung-H+wXaHxf7aLQT0dZR+AlfA
Cc: vgoyal-H+wXaHxf7aLQT0dZR+AlfA, jstancek-H+wXaHxf7aLQT0dZR+AlfA,
initramfs-u79uwXL29TY76Z2rM5mHXA
Am 17.01.2013 09:55, schrieb dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org:
> For cmdline argument with numeric value, add a new function getargnum
> It will get proper value with default value as $1, min value as $2,
> max value as $3, and param name as $4. valid result will be echo to stdout.
> for nul or value not valid it will just echo the default value.
> Note: The values should be >=0
>
> [v1->v2]: add arg <minval>
> [v2->v3]: do not use bash string match =~
>
> Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
merged
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2 V4] Add memory usage trace to diffrent hook points
[not found] ` <50F8AC98.1060308-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2013-01-22 14:32 ` Harald Hoyer
0 siblings, 0 replies; 7+ messages in thread
From: Harald Hoyer @ 2013-01-22 14:32 UTC (permalink / raw)
To: Dave Young
Cc: vgoyal-H+wXaHxf7aLQT0dZR+AlfA, jstancek-H+wXaHxf7aLQT0dZR+AlfA,
initramfs-u79uwXL29TY76Z2rM5mHXA
Am 18.01.2013 02:59, schrieb Dave Young:
>
> Hi, Here is an update of this patch, fixed the local variable issue.
> ---
>
> Add memory usage trace to diffrent hook points
>
> Port mkdumprd memory trace functions wrote by jstancek-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
> For kdump, memory usage tracing is important because there's limited
> memory in kdump 2nd kernel.
>
> Add a rd.memdebug cmdline for this. set rd.memdebug=<X> will set the
> debug level to X which is the debug verbose level.
>
> the format of cmdline is like below:
> <level>[+]:<type>
> <level> is the debug level
> [+] means debug level >= <level>
> <type> is the debug info type, as for this patch I added mem, iomem, slab
> mem is for /proc/meminfo, iomem is for /proc/iomem, slab is for /proc/slabinfo
> Also shortmem is the stripped /proc/meminfo which only includes 3 lines of
> Memfree, Cached and Slab, for example:
> MemFree: 6327176 kB
> Cached: 741916 kB
> Slab: 77284 kB
>
> I added several trace point to the begin of several init hooks
> At cmdline hooks I'm adding trace of "1+:mem 1+:iomem 3+:slab"
> For other hooks I'm adding trace of "1:shortmem 2+:mem 3+:slab"
>
> This means:
> rd.memdebug=1)
> cmdline hook: print mem and iomem
> other hooks: print shortmem
> rd.memdebug=2)
> cmdline hook: print mem and iomem
> other hooks: print mem
> rd.memdebug=3):
> cmdline hook: print mem iomem, and slabinfo
> other hooks: print mem and slabinfo
> *):
> do not print any mem debug info
>
> [v1->v2]: update to use getargnum with <minval> as argument
> print iomem info at cmdline hook as well
> [v2->v3]: harald: use $() instead of ``
> use bash string match instead of grep and pipe.
> [v3->v4]: harald: use local variables in function.
>
> Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
merged
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-01-22 14:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-17 8:55 [PATCH 0/2 V3] memory usage tracing update dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-01-17 8:55 ` [PATCH 1/2 V3] add function getargnum dyoung-H+wXaHxf7aLQT0dZR+AlfA
[not found] ` <20130117085724.062434676-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-22 14:32 ` Harald Hoyer
2013-01-17 8:55 ` [PATCH 2/2 V3] Add memory usage trace to diffrent hook points dyoung-H+wXaHxf7aLQT0dZR+AlfA
[not found] ` <20130117085724.212324334-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-17 13:43 ` Harald Hoyer
[not found] ` <50F7FFF2.4020309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-18 1:59 ` [PATCH 2/2 V4] " Dave Young
[not found] ` <50F8AC98.1060308-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-22 14:32 ` Harald Hoyer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox