Wednesday, June 19, 2013

How To Enable debugfs in kernel dynamically.

Kernel developer has provided a functionality known as “debugfs” to debug the kernel, enabling the log at the run time. It is very useful for the modules which have a lots of logs, and enabling the log statically will make the system very slow. So Kernel developers came up with this idea to enabling the logs only for the time when user wants to check a particular scenario.
So here is the process to enable it :
Step 1. Enable the debugfs, which can be done by following command :
mount -o rw,remount -t debugfs none /sys/kernel/debug
Step 2. Now if you want to see what are the logs defined you can do the same using following command :
cat /sys/kernel/debug/dynamic_debug/control [Here /sys/kernel/debug/ is the directory we mounted in previous command,                    u can change it if you want]
Step 3. Now enable the debug log for the files or paricular function you want to see in the logs:
echo ‘file mdp.c +p’ > /sys/kernel/debug/dynamic_debug/control [It will enable all debugfs logs in mdp.c]
echo ’file mdp.c line 2921 +p’ > /sys/kernel/debug/dynamic_debug/control [It will only enabled the log at 2921 line in mdp.c file]
# (
> echo ’file svcsock.c line 1603 +p’ ;\
> echo ’file svcsock.c line 1563 +p’ ;\
> ) > /sys/kernel/debug/dynamic_debug/control [for enabling to multiple debug logs]
Step 4. Now you can check the logs in demsg or cat /proc/kmsg.
Here I want to mention the logs which used under pr_debug()/dev_dbg() method will be enabled by this feature.So whatever logs you want to enable put those using pr_debug or dev_dbg().
you can find more details for pattern to enable logs @ https://www.kernel.org/doc/ols/2009/ols2009-pages-39-46.pdf

2 comments:

Anonymous said...

In some android version mount returns an error, use this line instead if that happends
"mount -t debugfs none /sys/kernel/debug"

Balaji said...

Hi Rahul , U forgot to mention "CONFIG_DYNAMIC_DEBUG" should be enabled while compiling the kernel for this option to work