File tree 1 file changed +60
-0
lines changed
1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # ch13/3_lockdep/lock_stats_demo.sh
3
+ # ***************************************************************
4
+ # This program is part of the source code released for the book
5
+ # "Linux Kernel Programming"
6
+ # (c) Author: Kaiwan N Billimoria
7
+ # Publisher: Packt
8
+ # GitHub repository:
9
+ # https://github.com/PacktPublishing/Linux-Kernel-Programming
10
+ # ****************************************************************
11
+ # Brief Description:
12
+ # Simple script to demo some kernel locking statistics.
13
+ # [This script was initially not in the repo; apologies!]
14
+ name=$( basename $0 )
15
+
16
+ die ()
17
+ {
18
+ echo >&2 " FATAL: $@ "
19
+ exit 1
20
+ }
21
+
22
+ clear_lock_stats () {
23
+ echo 0 > /proc/lock_stat
24
+ }
25
+ enable_lock_stats () {
26
+ echo 1 > /proc/sys/kernel/lock_stat
27
+ }
28
+ disable_lock_stats () {
29
+ echo 0 > /proc/sys/kernel/lock_stat
30
+ }
31
+ view_lock_stats () {
32
+ cat /proc/lock_stat
33
+ }
34
+
35
+
36
+ # --- 'main'
37
+ [[ -f /boot/config-$( uname -r) ]] && { # at least on x86[_64]
38
+ grep -w " CONFIG_LOCK_STAT=y" /boot/config-$( uname -r) > /dev/null 2>&1
39
+ [[ $? -ne 0 ]] && die " ${name} : you're running this on a kernel without lock stats (CONFIG_LOCK_STAT) enabled"
40
+ }
41
+
42
+ [[ $( id -u) -ne 0 ]] && die " Needs root."
43
+
44
+ disable_lock_stats
45
+
46
+ # --- Test case --------------------------------------------------------
47
+ # We want to see some kernel locks and their stats.
48
+ # So run a simple command and capture the stats.
49
+ # Enable lock stats only now!
50
+ clear_lock_stats
51
+ enable_lock_stats
52
+ cat /proc/self/cmdline
53
+ # ----------------------------------------------------------------------
54
+
55
+ disable_lock_stats
56
+ REPFILE=lockstats.txt
57
+ view_lock_stats > ${REPFILE}
58
+ # view_lock_stats |tee ${REPFILE}
59
+ echo " ${name} : done, see the kernel locking stats in ${REPFILE} "
60
+ exit 0
You can’t perform that action at this time.
0 commit comments