Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 156f5a78 authored by GeunSik Lim's avatar GeunSik Lim Committed by Greg Kroah-Hartman
Browse files

debugfs: Fix terminology inconsistency of dir name to mount debugfs filesystem.

Many developers use "/debug/" or "/debugfs/" or "/sys/kernel/debug/"
directory name to mount debugfs filesystem for ftrace according to
./Documentation/tracers/ftrace.txt file.

And, three directory names(ex:/debug/, /debugfs/, /sys/kernel/debug/) is
existed in kernel source like ftrace, DRM, Wireless, Documentation,
Network[sky2]files to mount debugfs filesystem.

debugfs means debug filesystem for debugging easy to use by greg kroah
hartman. "/sys/kernel/debug/" name is suitable as directory name
of debugfs filesystem.
- debugfs related reference: http://lwn.net/Articles/334546/



Fix inconsistency of directory name to mount debugfs filesystem.

* From Steven Rostedt
  - find_debugfs() and tracing_files() in this patch.

Signed-off-by: default avatarGeunSik Lim <geunsik.lim@samsung.com>
Acked-by     : Inaky Perez-Gonzalez <inaky@linux.intel.com>
Reviewed-by  : Steven Rostedt <rostedt@goodmis.org>
Reviewed-by  : James Smart <james.smart@emulex.com>
CC: Jiri Kosina <trivial@kernel.org>
CC: David Airlie <airlied@linux.ie>
CC: Peter Osterlund <petero2@telia.com>
CC: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
CC: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
CC: Masami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1b713e00
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -106,7 +106,7 @@
      number of errors are printk'ed including a full stack trace.
      number of errors are printk'ed including a full stack trace.
    </para>
    </para>
    <para>
    <para>
      The statistics are available via debugfs/debug_objects/stats.
      The statistics are available via /sys/kernel/debug/debug_objects/stats.
      They provide information about the number of warnings and the
      They provide information about the number of warnings and the
      number of successful fixups along with information about the
      number of successful fixups along with information about the
      usage of the internal tracking objects and the state of the
      usage of the internal tracking objects and the state of the
+1 −1
Original line number Original line Diff line number Diff line
@@ -117,7 +117,7 @@ Using the pktcdvd debugfs interface


To read pktcdvd device infos in human readable form, do:
To read pktcdvd device infos in human readable form, do:


	# cat /debug/pktcdvd/pktcdvd[0-7]/info
	# cat /sys/kernel/debug/pktcdvd/pktcdvd[0-7]/info


For a description of the debugfs interface look into the file:
For a description of the debugfs interface look into the file:


+35 −35
Original line number Original line Diff line number Diff line
@@ -29,16 +29,16 @@ o debugfs entries
fault-inject-debugfs kernel module provides some debugfs entries for runtime
fault-inject-debugfs kernel module provides some debugfs entries for runtime
configuration of fault-injection capabilities.
configuration of fault-injection capabilities.


- /debug/fail*/probability:
- /sys/kernel/debug/fail*/probability:


	likelihood of failure injection, in percent.
	likelihood of failure injection, in percent.
	Format: <percent>
	Format: <percent>


	Note that one-failure-per-hundred is a very high error rate
	Note that one-failure-per-hundred is a very high error rate
	for some testcases.  Consider setting probability=100 and configure
	for some testcases.  Consider setting probability=100 and configure
	/debug/fail*/interval for such testcases.
	/sys/kernel/debug/fail*/interval for such testcases.


- /debug/fail*/interval:
- /sys/kernel/debug/fail*/interval:


	specifies the interval between failures, for calls to
	specifies the interval between failures, for calls to
	should_fail() that pass all the other tests.
	should_fail() that pass all the other tests.
@@ -46,18 +46,18 @@ configuration of fault-injection capabilities.
	Note that if you enable this, by setting interval>1, you will
	Note that if you enable this, by setting interval>1, you will
	probably want to set probability=100.
	probably want to set probability=100.


- /debug/fail*/times:
- /sys/kernel/debug/fail*/times:


	specifies how many times failures may happen at most.
	specifies how many times failures may happen at most.
	A value of -1 means "no limit".
	A value of -1 means "no limit".


- /debug/fail*/space:
- /sys/kernel/debug/fail*/space:


	specifies an initial resource "budget", decremented by "size"
	specifies an initial resource "budget", decremented by "size"
	on each call to should_fail(,size).  Failure injection is
	on each call to should_fail(,size).  Failure injection is
	suppressed until "space" reaches zero.
	suppressed until "space" reaches zero.


- /debug/fail*/verbose
- /sys/kernel/debug/fail*/verbose


	Format: { 0 | 1 | 2 }
	Format: { 0 | 1 | 2 }
	specifies the verbosity of the messages when failure is
	specifies the verbosity of the messages when failure is
@@ -65,17 +65,17 @@ configuration of fault-injection capabilities.
	log line per failure; '2' will print a call trace too -- useful
	log line per failure; '2' will print a call trace too -- useful
	to debug the problems revealed by fault injection.
	to debug the problems revealed by fault injection.


- /debug/fail*/task-filter:
- /sys/kernel/debug/fail*/task-filter:


	Format: { 'Y' | 'N' }
	Format: { 'Y' | 'N' }
	A value of 'N' disables filtering by process (default).
	A value of 'N' disables filtering by process (default).
	Any positive value limits failures to only processes indicated by
	Any positive value limits failures to only processes indicated by
	/proc/<pid>/make-it-fail==1.
	/proc/<pid>/make-it-fail==1.


- /debug/fail*/require-start:
- /sys/kernel/debug/fail*/require-start:
- /debug/fail*/require-end:
- /sys/kernel/debug/fail*/require-end:
- /debug/fail*/reject-start:
- /sys/kernel/debug/fail*/reject-start:
- /debug/fail*/reject-end:
- /sys/kernel/debug/fail*/reject-end:


	specifies the range of virtual addresses tested during
	specifies the range of virtual addresses tested during
	stacktrace walking.  Failure is injected only if some caller
	stacktrace walking.  Failure is injected only if some caller
@@ -84,26 +84,26 @@ configuration of fault-injection capabilities.
	Default required range is [0,ULONG_MAX) (whole of virtual address space).
	Default required range is [0,ULONG_MAX) (whole of virtual address space).
	Default rejected range is [0,0).
	Default rejected range is [0,0).


- /debug/fail*/stacktrace-depth:
- /sys/kernel/debug/fail*/stacktrace-depth:


	specifies the maximum stacktrace depth walked during search
	specifies the maximum stacktrace depth walked during search
	for a caller within [require-start,require-end) OR
	for a caller within [require-start,require-end) OR
	[reject-start,reject-end).
	[reject-start,reject-end).


- /debug/fail_page_alloc/ignore-gfp-highmem:
- /sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem:


	Format: { 'Y' | 'N' }
	Format: { 'Y' | 'N' }
	default is 'N', setting it to 'Y' won't inject failures into
	default is 'N', setting it to 'Y' won't inject failures into
	highmem/user allocations.
	highmem/user allocations.


- /debug/failslab/ignore-gfp-wait:
- /sys/kernel/debug/failslab/ignore-gfp-wait:
- /debug/fail_page_alloc/ignore-gfp-wait:
- /sys/kernel/debug/fail_page_alloc/ignore-gfp-wait:


	Format: { 'Y' | 'N' }
	Format: { 'Y' | 'N' }
	default is 'N', setting it to 'Y' will inject failures
	default is 'N', setting it to 'Y' will inject failures
	only into non-sleep allocations (GFP_ATOMIC allocations).
	only into non-sleep allocations (GFP_ATOMIC allocations).


- /debug/fail_page_alloc/min-order:
- /sys/kernel/debug/fail_page_alloc/min-order:


	specifies the minimum page allocation order to be injected
	specifies the minimum page allocation order to be injected
	failures.
	failures.
@@ -166,13 +166,13 @@ o Inject slab allocation failures into module init/exit code
#!/bin/bash
#!/bin/bash


FAILTYPE=failslab
FAILTYPE=failslab
echo Y > /debug/$FAILTYPE/task-filter
echo Y > /sys/kernel/debug/$FAILTYPE/task-filter
echo 10 > /debug/$FAILTYPE/probability
echo 10 > /sys/kernel/debug/$FAILTYPE/probability
echo 100 > /debug/$FAILTYPE/interval
echo 100 > /sys/kernel/debug/$FAILTYPE/interval
echo -1 > /debug/$FAILTYPE/times
echo -1 > /sys/kernel/debug/$FAILTYPE/times
echo 0 > /debug/$FAILTYPE/space
echo 0 > /sys/kernel/debug/$FAILTYPE/space
echo 2 > /debug/$FAILTYPE/verbose
echo 2 > /sys/kernel/debug/$FAILTYPE/verbose
echo 1 > /debug/$FAILTYPE/ignore-gfp-wait
echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait


faulty_system()
faulty_system()
{
{
@@ -217,20 +217,20 @@ then
	exit 1
	exit 1
fi
fi


cat /sys/module/$module/sections/.text > /debug/$FAILTYPE/require-start
cat /sys/module/$module/sections/.text > /sys/kernel/debug/$FAILTYPE/require-start
cat /sys/module/$module/sections/.data > /debug/$FAILTYPE/require-end
cat /sys/module/$module/sections/.data > /sys/kernel/debug/$FAILTYPE/require-end


echo N > /debug/$FAILTYPE/task-filter
echo N > /sys/kernel/debug/$FAILTYPE/task-filter
echo 10 > /debug/$FAILTYPE/probability
echo 10 > /sys/kernel/debug/$FAILTYPE/probability
echo 100 > /debug/$FAILTYPE/interval
echo 100 > /sys/kernel/debug/$FAILTYPE/interval
echo -1 > /debug/$FAILTYPE/times
echo -1 > /sys/kernel/debug/$FAILTYPE/times
echo 0 > /debug/$FAILTYPE/space
echo 0 > /sys/kernel/debug/$FAILTYPE/space
echo 2 > /debug/$FAILTYPE/verbose
echo 2 > /sys/kernel/debug/$FAILTYPE/verbose
echo 1 > /debug/$FAILTYPE/ignore-gfp-wait
echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait
echo 1 > /debug/$FAILTYPE/ignore-gfp-highmem
echo 1 > /sys/kernel/debug/$FAILTYPE/ignore-gfp-highmem
echo 10 > /debug/$FAILTYPE/stacktrace-depth
echo 10 > /sys/kernel/debug/$FAILTYPE/stacktrace-depth


trap "echo 0 > /debug/$FAILTYPE/probability" SIGINT SIGTERM EXIT
trap "echo 0 > /sys/kernel/debug/$FAILTYPE/probability" SIGINT SIGTERM EXIT


echo "Injecting errors into the module $module... (interrupt to stop)"
echo "Injecting errors into the module $module... (interrupt to stop)"
sleep 1000000
sleep 1000000
+3 −3
Original line number Original line Diff line number Diff line
@@ -507,9 +507,9 @@ http://www.linuxsymposium.org/2006/linuxsymposium_procv2.pdf (pages 101-115)
Appendix A: The kprobes debugfs interface
Appendix A: The kprobes debugfs interface


With recent kernels (> 2.6.20) the list of registered kprobes is visible
With recent kernels (> 2.6.20) the list of registered kprobes is visible
under the /debug/kprobes/ directory (assuming debugfs is mounted at /debug).
under the /sys/kernel/debug/kprobes/ directory (assuming debugfs is mounted at //sys/kernel/debug).


/debug/kprobes/list: Lists all registered probes on the system
/sys/kernel/debug/kprobes/list: Lists all registered probes on the system


c015d71a  k  vfs_read+0x0
c015d71a  k  vfs_read+0x0
c011a316  j  do_fork+0x0
c011a316  j  do_fork+0x0
@@ -525,7 +525,7 @@ virtual addresses that correspond to modules that've been unloaded),
such probes are marked with [GONE]. If the probe is temporarily disabled,
such probes are marked with [GONE]. If the probe is temporarily disabled,
such probes are marked with [DISABLED].
such probes are marked with [DISABLED].


/debug/kprobes/enabled: Turn kprobes ON/OFF forcibly.
/sys/kernel/debug/kprobes/enabled: Turn kprobes ON/OFF forcibly.


Provides a knob to globally and forcibly turn registered kprobes ON or OFF.
Provides a knob to globally and forcibly turn registered kprobes ON or OFF.
By default, all kprobes are enabled. By echoing "0" to this file, all
By default, all kprobes are enabled. By echoing "0" to this file, all
+142 −91
Original line number Original line Diff line number Diff line
@@ -7,7 +7,6 @@ Copyright 2008 Red Hat Inc.
               (dual licensed under the GPL v2)
               (dual licensed under the GPL v2)
Reviewers:   Elias Oltmanns, Randy Dunlap, Andrew Morton,
Reviewers:   Elias Oltmanns, Randy Dunlap, Andrew Morton,
	     John Kacur, and David Teigland.
	     John Kacur, and David Teigland.

Written for: 2.6.28-rc2
Written for: 2.6.28-rc2


Introduction
Introduction
@@ -33,13 +32,26 @@ The File System
Ftrace uses the debugfs file system to hold the control files as
Ftrace uses the debugfs file system to hold the control files as
well as the files to display output.
well as the files to display output.


To mount the debugfs system:
When debugfs is configured into the kernel (which selecting any ftrace
option will do) the directory /sys/kernel/debug will be created. To mount
this directory, you can add to your /etc/fstab file:

 debugfs       /sys/kernel/debug          debugfs defaults        0       0

Or you can mount it at run time with:


  # mkdir /debug
 mount -t debugfs nodev /sys/kernel/debug
  # mount -t debugfs nodev /debug


( Note: it is more common to mount at /sys/kernel/debug, but for
For quicker access to that directory you may want to make a soft link to
  simplicity this document will use /debug)
it:

 ln -s /sys/kernel/debug /debug

Any selected ftrace option will also create a directory called tracing
within the debugfs. The rest of the document will assume that you are in
the ftrace directory (cd /sys/kernel/debug/tracing) and will only concentrate
on the files within that directory and not distract from the content with
the extended "/sys/kernel/debug/tracing" path name.


That's it! (assuming that you have ftrace configured into your kernel)
That's it! (assuming that you have ftrace configured into your kernel)


@@ -389,18 +401,18 @@ trace_options
The trace_options file is used to control what gets printed in
The trace_options file is used to control what gets printed in
the trace output. To see what is available, simply cat the file:
the trace output. To see what is available, simply cat the file:


  cat /debug/tracing/trace_options
  cat trace_options
  print-parent nosym-offset nosym-addr noverbose noraw nohex nobin \
  print-parent nosym-offset nosym-addr noverbose noraw nohex nobin \
  noblock nostacktrace nosched-tree nouserstacktrace nosym-userobj
  noblock nostacktrace nosched-tree nouserstacktrace nosym-userobj


To disable one of the options, echo in the option prepended with
To disable one of the options, echo in the option prepended with
"no".
"no".


  echo noprint-parent > /debug/tracing/trace_options
  echo noprint-parent > trace_options


To enable an option, leave off the "no".
To enable an option, leave off the "no".


  echo sym-offset > /debug/tracing/trace_options
  echo sym-offset > trace_options


Here are the available options:
Here are the available options:


@@ -476,11 +488,11 @@ sched_switch
This tracer simply records schedule switches. Here is an example
This tracer simply records schedule switches. Here is an example
of how to use it.
of how to use it.


 # echo sched_switch > /debug/tracing/current_tracer
 # echo sched_switch > current_tracer
 # echo 1 > /debug/tracing/tracing_enabled
 # echo 1 > tracing_enabled
 # sleep 1
 # sleep 1
 # echo 0 > /debug/tracing/tracing_enabled
 # echo 0 > tracing_enabled
 # cat /debug/tracing/trace
 # cat trace


# tracer: sched_switch
# tracer: sched_switch
#
#
@@ -583,13 +595,13 @@ new trace is saved.
To reset the maximum, echo 0 into tracing_max_latency. Here is
To reset the maximum, echo 0 into tracing_max_latency. Here is
an example:
an example:


 # echo irqsoff > /debug/tracing/current_tracer
 # echo irqsoff > current_tracer
 # echo 0 > /debug/tracing/tracing_max_latency
 # echo 0 > tracing_max_latency
 # echo 1 > /debug/tracing/tracing_enabled
 # echo 1 > tracing_enabled
 # ls -ltr
 # ls -ltr
 [...]
 [...]
 # echo 0 > /debug/tracing/tracing_enabled
 # echo 0 > tracing_enabled
 # cat /debug/tracing/latency_trace
 # cat latency_trace
# tracer: irqsoff
# tracer: irqsoff
#
#
irqsoff latency trace v1.1.5 on 2.6.26
irqsoff latency trace v1.1.5 on 2.6.26
@@ -690,13 +702,13 @@ Like the irqsoff tracer, it records the maximum latency for
which preemption was disabled. The control of preemptoff tracer
which preemption was disabled. The control of preemptoff tracer
is much like the irqsoff tracer.
is much like the irqsoff tracer.


 # echo preemptoff > /debug/tracing/current_tracer
 # echo preemptoff > current_tracer
 # echo 0 > /debug/tracing/tracing_max_latency
 # echo 0 > tracing_max_latency
 # echo 1 > /debug/tracing/tracing_enabled
 # echo 1 > tracing_enabled
 # ls -ltr
 # ls -ltr
 [...]
 [...]
 # echo 0 > /debug/tracing/tracing_enabled
 # echo 0 > tracing_enabled
 # cat /debug/tracing/latency_trace
 # cat latency_trace
# tracer: preemptoff
# tracer: preemptoff
#
#
preemptoff latency trace v1.1.5 on 2.6.26-rc8
preemptoff latency trace v1.1.5 on 2.6.26-rc8
@@ -837,13 +849,13 @@ tracer.
Again, using this trace is much like the irqsoff and preemptoff
Again, using this trace is much like the irqsoff and preemptoff
tracers.
tracers.


 # echo preemptirqsoff > /debug/tracing/current_tracer
 # echo preemptirqsoff > current_tracer
 # echo 0 > /debug/tracing/tracing_max_latency
 # echo 0 > tracing_max_latency
 # echo 1 > /debug/tracing/tracing_enabled
 # echo 1 > tracing_enabled
 # ls -ltr
 # ls -ltr
 [...]
 [...]
 # echo 0 > /debug/tracing/tracing_enabled
 # echo 0 > tracing_enabled
 # cat /debug/tracing/latency_trace
 # cat latency_trace
# tracer: preemptirqsoff
# tracer: preemptirqsoff
#
#
preemptirqsoff latency trace v1.1.5 on 2.6.26-rc8
preemptirqsoff latency trace v1.1.5 on 2.6.26-rc8
@@ -999,12 +1011,12 @@ slightly differently than we did with the previous tracers.
Instead of performing an 'ls', we will run 'sleep 1' under
Instead of performing an 'ls', we will run 'sleep 1' under
'chrt' which changes the priority of the task.
'chrt' which changes the priority of the task.


 # echo wakeup > /debug/tracing/current_tracer
 # echo wakeup > current_tracer
 # echo 0 > /debug/tracing/tracing_max_latency
 # echo 0 > tracing_max_latency
 # echo 1 > /debug/tracing/tracing_enabled
 # echo 1 > tracing_enabled
 # chrt -f 5 sleep 1
 # chrt -f 5 sleep 1
 # echo 0 > /debug/tracing/tracing_enabled
 # echo 0 > tracing_enabled
 # cat /debug/tracing/latency_trace
 # cat latency_trace
# tracer: wakeup
# tracer: wakeup
#
#
wakeup latency trace v1.1.5 on 2.6.26-rc8
wakeup latency trace v1.1.5 on 2.6.26-rc8
@@ -1114,11 +1126,11 @@ can be done from the debug file system. Make sure the
ftrace_enabled is set; otherwise this tracer is a nop.
ftrace_enabled is set; otherwise this tracer is a nop.


 # sysctl kernel.ftrace_enabled=1
 # sysctl kernel.ftrace_enabled=1
 # echo function > /debug/tracing/current_tracer
 # echo function > current_tracer
 # echo 1 > /debug/tracing/tracing_enabled
 # echo 1 > tracing_enabled
 # usleep 1
 # usleep 1
 # echo 0 > /debug/tracing/tracing_enabled
 # echo 0 > tracing_enabled
 # cat /debug/tracing/trace
 # cat trace
# tracer: function
# tracer: function
#
#
#           TASK-PID   CPU#    TIMESTAMP  FUNCTION
#           TASK-PID   CPU#    TIMESTAMP  FUNCTION
@@ -1155,7 +1167,7 @@ int trace_fd;
[...]
[...]
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
	[...]
	[...]
	trace_fd = open("/debug/tracing/tracing_enabled", O_WRONLY);
	trace_fd = open(tracing_file("tracing_enabled"), O_WRONLY);
	[...]
	[...]
	if (condition_hit()) {
	if (condition_hit()) {
		write(trace_fd, "0", 1);
		write(trace_fd, "0", 1);
@@ -1163,26 +1175,20 @@ int main(int argc, char *argv[]) {
	[...]
	[...]
}
}


Note: Here we hard coded the path name. The debugfs mount is not
guaranteed to be at /debug (and is more commonly at
/sys/kernel/debug). For simple one time traces, the above is
sufficent. For anything else, a search through /proc/mounts may
be needed to find where the debugfs file-system is mounted.



Single thread tracing
Single thread tracing
---------------------
---------------------


By writing into /debug/tracing/set_ftrace_pid you can trace a
By writing into set_ftrace_pid you can trace a
single thread. For example:
single thread. For example:


# cat /debug/tracing/set_ftrace_pid
# cat set_ftrace_pid
no pid
no pid
# echo 3111 > /debug/tracing/set_ftrace_pid
# echo 3111 > set_ftrace_pid
# cat /debug/tracing/set_ftrace_pid
# cat set_ftrace_pid
3111
3111
# echo function > /debug/tracing/current_tracer
# echo function > current_tracer
# cat /debug/tracing/trace | head
# cat trace | head
 # tracer: function
 # tracer: function
 #
 #
 #           TASK-PID    CPU#    TIMESTAMP  FUNCTION
 #           TASK-PID    CPU#    TIMESTAMP  FUNCTION
@@ -1193,8 +1199,8 @@ no pid
     yum-updatesd-3111  [003]  1637.254683: lock_hrtimer_base <-hrtimer_try_to_cancel
     yum-updatesd-3111  [003]  1637.254683: lock_hrtimer_base <-hrtimer_try_to_cancel
     yum-updatesd-3111  [003]  1637.254685: fget_light <-do_sys_poll
     yum-updatesd-3111  [003]  1637.254685: fget_light <-do_sys_poll
     yum-updatesd-3111  [003]  1637.254686: pipe_poll <-do_sys_poll
     yum-updatesd-3111  [003]  1637.254686: pipe_poll <-do_sys_poll
# echo -1 > /debug/tracing/set_ftrace_pid
# echo -1 > set_ftrace_pid
# cat /debug/tracing/trace |head
# cat trace |head
 # tracer: function
 # tracer: function
 #
 #
 #           TASK-PID    CPU#    TIMESTAMP  FUNCTION
 #           TASK-PID    CPU#    TIMESTAMP  FUNCTION
@@ -1216,6 +1222,51 @@ something like this simple program:
#include <fcntl.h>
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>


#define _STR(x) #x
#define STR(x) _STR(x)
#define MAX_PATH 256

const char *find_debugfs(void)
{
       static char debugfs[MAX_PATH+1];
       static int debugfs_found;
       char type[100];
       FILE *fp;

       if (debugfs_found)
               return debugfs;

       if ((fp = fopen("/proc/mounts","r")) == NULL) {
               perror("/proc/mounts");
               return NULL;
       }

       while (fscanf(fp, "%*s %"
                     STR(MAX_PATH)
                     "s %99s %*s %*d %*d\n",
                     debugfs, type) == 2) {
               if (strcmp(type, "debugfs") == 0)
                       break;
       }
       fclose(fp);

       if (strcmp(type, "debugfs") != 0) {
               fprintf(stderr, "debugfs not mounted");
               return NULL;
       }

       debugfs_found = 1;

       return debugfs;
}

const char *tracing_file(const char *file_name)
{
       static char trace_file[MAX_PATH+1];
       snprintf(trace_file, MAX_PATH, "%s/%s", find_debugfs(), file_name);
       return trace_file;
}

int main (int argc, char **argv)
int main (int argc, char **argv)
{
{
        if (argc < 1)
        if (argc < 1)
@@ -1226,12 +1277,12 @@ int main (int argc, char **argv)
                char line[64];
                char line[64];
                int s;
                int s;


                ffd = open("/debug/tracing/current_tracer", O_WRONLY);
                ffd = open(tracing_file("current_tracer"), O_WRONLY);
                if (ffd < 0)
                if (ffd < 0)
                        exit(-1);
                        exit(-1);
                write(ffd, "nop", 3);
                write(ffd, "nop", 3);


                fd = open("/debug/tracing/set_ftrace_pid", O_WRONLY);
                fd = open(tracing_file("set_ftrace_pid"), O_WRONLY);
                s = sprintf(line, "%d\n", getpid());
                s = sprintf(line, "%d\n", getpid());
                write(fd, line, s);
                write(fd, line, s);


@@ -1383,22 +1434,22 @@ want, depending on your needs.
  tracing_cpu_mask file) or you might sometimes see unordered
  tracing_cpu_mask file) or you might sometimes see unordered
  function calls while cpu tracing switch.
  function calls while cpu tracing switch.


	hide: echo nofuncgraph-cpu > /debug/tracing/trace_options
	hide: echo nofuncgraph-cpu > trace_options
	show: echo funcgraph-cpu > /debug/tracing/trace_options
	show: echo funcgraph-cpu > trace_options


- The duration (function's time of execution) is displayed on
- The duration (function's time of execution) is displayed on
  the closing bracket line of a function or on the same line
  the closing bracket line of a function or on the same line
  than the current function in case of a leaf one. It is default
  than the current function in case of a leaf one. It is default
  enabled.
  enabled.


	hide: echo nofuncgraph-duration > /debug/tracing/trace_options
	hide: echo nofuncgraph-duration > trace_options
	show: echo funcgraph-duration > /debug/tracing/trace_options
	show: echo funcgraph-duration > trace_options


- The overhead field precedes the duration field in case of
- The overhead field precedes the duration field in case of
  reached duration thresholds.
  reached duration thresholds.


	hide: echo nofuncgraph-overhead > /debug/tracing/trace_options
	hide: echo nofuncgraph-overhead > trace_options
	show: echo funcgraph-overhead > /debug/tracing/trace_options
	show: echo funcgraph-overhead > trace_options
	depends on: funcgraph-duration
	depends on: funcgraph-duration


  ie:
  ie:
@@ -1427,8 +1478,8 @@ want, depending on your needs.
- The task/pid field displays the thread cmdline and pid which
- The task/pid field displays the thread cmdline and pid which
  executed the function. It is default disabled.
  executed the function. It is default disabled.


	hide: echo nofuncgraph-proc > /debug/tracing/trace_options
	hide: echo nofuncgraph-proc > trace_options
	show: echo funcgraph-proc > /debug/tracing/trace_options
	show: echo funcgraph-proc > trace_options


  ie:
  ie:


@@ -1451,8 +1502,8 @@ want, depending on your needs.
  system clock since it started. A snapshot of this time is
  system clock since it started. A snapshot of this time is
  given on each entry/exit of functions
  given on each entry/exit of functions


	hide: echo nofuncgraph-abstime > /debug/tracing/trace_options
	hide: echo nofuncgraph-abstime > trace_options
	show: echo funcgraph-abstime > /debug/tracing/trace_options
	show: echo funcgraph-abstime > trace_options


  ie:
  ie:


@@ -1549,7 +1600,7 @@ listed in:


   available_filter_functions
   available_filter_functions


 # cat /debug/tracing/available_filter_functions
 # cat available_filter_functions
put_prev_task_idle
put_prev_task_idle
kmem_cache_create
kmem_cache_create
pick_next_task_rt
pick_next_task_rt
@@ -1561,12 +1612,12 @@ mutex_lock
If I am only interested in sys_nanosleep and hrtimer_interrupt:
If I am only interested in sys_nanosleep and hrtimer_interrupt:


 # echo sys_nanosleep hrtimer_interrupt \
 # echo sys_nanosleep hrtimer_interrupt \
		> /debug/tracing/set_ftrace_filter
		> set_ftrace_filter
 # echo ftrace > /debug/tracing/current_tracer
 # echo ftrace > current_tracer
 # echo 1 > /debug/tracing/tracing_enabled
 # echo 1 > tracing_enabled
 # usleep 1
 # usleep 1
 # echo 0 > /debug/tracing/tracing_enabled
 # echo 0 > tracing_enabled
 # cat /debug/tracing/trace
 # cat trace
# tracer: ftrace
# tracer: ftrace
#
#
#           TASK-PID   CPU#    TIMESTAMP  FUNCTION
#           TASK-PID   CPU#    TIMESTAMP  FUNCTION
@@ -1577,7 +1628,7 @@ If I am only interested in sys_nanosleep and hrtimer_interrupt:


To see which functions are being traced, you can cat the file:
To see which functions are being traced, you can cat the file:


 # cat /debug/tracing/set_ftrace_filter
 # cat set_ftrace_filter
hrtimer_interrupt
hrtimer_interrupt
sys_nanosleep
sys_nanosleep


@@ -1597,7 +1648,7 @@ Note: It is better to use quotes to enclose the wild cards,
      otherwise the shell may expand the parameters into names
      otherwise the shell may expand the parameters into names
      of files in the local directory.
      of files in the local directory.


 # echo 'hrtimer_*' > /debug/tracing/set_ftrace_filter
 # echo 'hrtimer_*' > set_ftrace_filter


Produces:
Produces:


@@ -1618,7 +1669,7 @@ Produces:


Notice that we lost the sys_nanosleep.
Notice that we lost the sys_nanosleep.


 # cat /debug/tracing/set_ftrace_filter
 # cat set_ftrace_filter
hrtimer_run_queues
hrtimer_run_queues
hrtimer_run_pending
hrtimer_run_pending
hrtimer_init
hrtimer_init
@@ -1644,17 +1695,17 @@ To append to the filters, use '>>'
To clear out a filter so that all functions will be recorded
To clear out a filter so that all functions will be recorded
again:
again:


 # echo > /debug/tracing/set_ftrace_filter
 # echo > set_ftrace_filter
 # cat /debug/tracing/set_ftrace_filter
 # cat set_ftrace_filter
 #
 #


Again, now we want to append.
Again, now we want to append.


 # echo sys_nanosleep > /debug/tracing/set_ftrace_filter
 # echo sys_nanosleep > set_ftrace_filter
 # cat /debug/tracing/set_ftrace_filter
 # cat set_ftrace_filter
sys_nanosleep
sys_nanosleep
 # echo 'hrtimer_*' >> /debug/tracing/set_ftrace_filter
 # echo 'hrtimer_*' >> set_ftrace_filter
 # cat /debug/tracing/set_ftrace_filter
 # cat set_ftrace_filter
hrtimer_run_queues
hrtimer_run_queues
hrtimer_run_pending
hrtimer_run_pending
hrtimer_init
hrtimer_init
@@ -1677,7 +1728,7 @@ hrtimer_init_sleeper
The set_ftrace_notrace prevents those functions from being
The set_ftrace_notrace prevents those functions from being
traced.
traced.


 # echo '*preempt*' '*lock*' > /debug/tracing/set_ftrace_notrace
 # echo '*preempt*' '*lock*' > set_ftrace_notrace


Produces:
Produces:


@@ -1767,13 +1818,13 @@ the effect on the tracing is different. Every read from
trace_pipe is consumed. This means that subsequent reads will be
trace_pipe is consumed. This means that subsequent reads will be
different. The trace is live.
different. The trace is live.


 # echo function > /debug/tracing/current_tracer
 # echo function > current_tracer
 # cat /debug/tracing/trace_pipe > /tmp/trace.out &
 # cat trace_pipe > /tmp/trace.out &
[1] 4153
[1] 4153
 # echo 1 > /debug/tracing/tracing_enabled
 # echo 1 > tracing_enabled
 # usleep 1
 # usleep 1
 # echo 0 > /debug/tracing/tracing_enabled
 # echo 0 > tracing_enabled
 # cat /debug/tracing/trace
 # cat trace
# tracer: function
# tracer: function
#
#
#           TASK-PID   CPU#    TIMESTAMP  FUNCTION
#           TASK-PID   CPU#    TIMESTAMP  FUNCTION
@@ -1809,7 +1860,7 @@ number listed is the number of entries that can be recorded per
CPU. To know the full size, multiply the number of possible CPUS
CPU. To know the full size, multiply the number of possible CPUS
with the number of entries.
with the number of entries.


 # cat /debug/tracing/buffer_size_kb
 # cat buffer_size_kb
1408 (units kilobytes)
1408 (units kilobytes)


Note, to modify this, you must have tracing completely disabled.
Note, to modify this, you must have tracing completely disabled.
@@ -1817,18 +1868,18 @@ To do that, echo "nop" into the current_tracer. If the
current_tracer is not set to "nop", an EINVAL error will be
current_tracer is not set to "nop", an EINVAL error will be
returned.
returned.


 # echo nop > /debug/tracing/current_tracer
 # echo nop > current_tracer
 # echo 10000 > /debug/tracing/buffer_size_kb
 # echo 10000 > buffer_size_kb
 # cat /debug/tracing/buffer_size_kb
 # cat buffer_size_kb
10000 (units kilobytes)
10000 (units kilobytes)


The number of pages which will be allocated is limited to a
The number of pages which will be allocated is limited to a
percentage of available memory. Allocating too much will produce
percentage of available memory. Allocating too much will produce
an error.
an error.


 # echo 1000000000000 > /debug/tracing/buffer_size_kb
 # echo 1000000000000 > buffer_size_kb
-bash: echo: write error: Cannot allocate memory
-bash: echo: write error: Cannot allocate memory
 # cat /debug/tracing/buffer_size_kb
 # cat buffer_size_kb
85
85


-----------
-----------
Loading