summaryrefslogtreecommitdiff
blob: f29b79f7f84871b146d3b5249a9d71d3d7da60f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
commit a5012d86e87e1c59be4a221b7d47cc791b102555
Author: Maynard Johnson <maynardj@us.ibm.com>
Date:   Wed May 25 16:10:46 2011 -0500

    Fix opcontrol --status to show accurate information for running daemon

diff --git a/utils/opcontrol b/utils/opcontrol
index 0f04354..f002f01 100644
--- a/utils/opcontrol
+++ b/utils/opcontrol
@@ -38,6 +38,16 @@ do_sysctl()
 	echo $val > /proc/sys/$dev_name
 }
 
+# Helper function to check if oprofile daemon is active.
+# Takes one argument: the "lock file" for the oprofile daemon.
+# The lock file may exist even if the daemon was killed or died in
+# some way.  So we do a kill SIG_DFL to test whether the daemon is
+# truly alive. If the lock file is stale (daemon dead), the kill will
+# not return '0'.
+is_oprofiled_active()
+{
+        [ -f "$1" ] && kill -0 `cat "$1"` 2>/dev/null
+}
 
 # check value is set
 error_if_empty()
@@ -355,6 +365,7 @@ do_init()
 	# location for daemon setup information
 	SETUP_DIR="/root/.oprofile"
 	SETUP_FILE="$SETUP_DIR/daemonrc"
+	SEC_SETUP_FILE="$SETUP_DIR/daemonrc_new"
 
 	# initialize daemon vars
 	decide_oprofile_device_mount
@@ -408,6 +419,19 @@ set_event()
 do_save_setup()
 {
 	create_dir "$SETUP_DIR"
+	SAVE_SETUP_FILE="$SETUP_FILE"
+
+# If the daemon is currently running, we want changes to the daemon config
+# stored in the secondary cache file so that 'opcontrol --status' will
+# show actual config data for the running daemon.  The next time the
+# daemon is restarted, we'll reload the config data from this secondary
+# cache file.
+
+	if is_oprofiled_active "$LOCK_FILE"; then
+		SETUP_FILE="$SEC_SETUP_FILE"
+		echo "The profiling daemon is currently active, so changes to the configuration"
+		echo "will be used the next time you restart oprofile after a --shutdown or --deinit."
+	fi
 
 	touch $SETUP_FILE
 	chmod 644 $SETUP_FILE
@@ -451,12 +475,27 @@ do_save_setup()
 	if test "$XEN_RANGE"; then
 		echo "XEN_RANGE=$XEN_RANGE" >> $SETUP_FILE
 	fi
+	SETUP_FILE="$SAVE_SETUP_FILE"
 }
 
 
 # reload all the setup-related information
 do_load_setup()
 {
+# If a secondary setup file exists and the daemon is not running,
+# then we'll move the data from the secondary file to the actual
+# setup file to prepare for daemon startup.
+	if test -z "$SESSION_DIR"; then
+		__TMP_SESSION_DIR="/var/lib/oprofile"
+	else
+		__TMP_SESSION_DIR="$SESSION_DIR"
+	fi
+
+	if test -f "$SEC_SETUP_FILE"; then
+		is_oprofiled_active "$__TMP_SESSION_DIR/lock" \
+		     || mv "$SEC_SETUP_FILE" "$SETUP_FILE"
+	fi
+
 	if test -f "$SETUP_FILE"; then
 		# load the actual information from file
 		# FIXME this is insecure, arbitrary commands could be added to
@@ -1572,7 +1611,12 @@ do_status()
 {
 	OPROFILED_PID=`cat $SESSION_DIR/lock 2>/dev/null`
 	if test -n "$OPROFILED_PID" -a -d "/proc/$OPROFILED_PID"; then
-		echo "Daemon running: pid $OPROFILED_PID"
+		if test "$KERNEL_SUPPORT" = yes \
+		    && test 0 != $(cat /dev/oprofile/enable); then
+			echo "Daemon running: pid $OPROFILED_PID"
+		else
+			echo "Daemon paused: pid $OPROFILED_PID"
+		fi
 	else
 		echo "Daemon not running"
 	fi