summaryrefslogtreecommitdiffstats
path: root/meta/recipes-kernel/oprofile/oprofile/opstart.patch
blob: d61c30095fe189f4e6660475a1492384646f83ad (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Index: oprofile/utils/Makefile.am
===================================================================
--- oprofile.orig/utils/Makefile.am	2005-03-31 18:20:41.000000000 +0100
+++ oprofile/utils/Makefile.am	2008-07-02 15:14:07.000000000 +0100
@@ -3,8 +3,15 @@
 
 LIBS=@POPT_LIBS@ @LIBERTY_LIBS@
 
-bin_PROGRAMS = ophelp
+bin_PROGRAMS = ophelp opstart
 dist_bin_SCRIPTS = opcontrol
 
 ophelp_SOURCES = ophelp.c
 ophelp_LDADD = ../libop/libop.a ../libutil/libutil.a
+
+opstart_SOURCES = opstart.c
+
+install-exec-local:
+	cd $(DESTDIR)/$(bindir) && \
+		rm -f opstop && \
+		$(LN_S) opstart opstop
Index: oprofile/utils/opstart.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ oprofile/utils/opstart.c	2008-07-02 15:14:07.000000000 +0100
@@ -0,0 +1,110 @@
+/**
+ * @file opstart.c
+ * Start/Stop oprofile
+ *
+ * @remark Copyright 2007 Openedhand Ltd.
+ * @remark Read the file COPYING
+ *
+ * @author Richard Purdie
+ */
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+int main(const int argc, const char* argv[])
+{
+	const char *enable = "/dev/oprofile/enable";
+	const char *lockfile;
+	unsigned long dpid;
+	struct stat sbuf;
+	FILE *lfile, *efile;
+	int sig, enb, err;
+
+	if (argc >= 2) {
+		printf("Error: Invalid options.\n");
+		return 1;
+	}
+
+	lockfile = getenv("LOCK_FILE");
+	if (!lockfile)
+		lockfile = "/var/lib/oprofile/lock";
+
+	/* Add SESSION_DIR support? */
+
+	if (geteuid()) {
+		printf("Error: This program must be run as root.\n");
+		return 1;
+	}
+
+	if (stat(enable, &sbuf)) {
+		printf("Error: Could not find /dev/oprofile/enable, the"
+		       " kernel module probably isn't loaded.\n");
+		printf("This binary only works with 2.6 kernels and oprofile"
+		       " must have been initialised with 'opcontrol --start-daemon'.\n");
+		return 1;
+	}
+
+	if (stat(lockfile, &sbuf)) {
+		printf("Error: Could not find lockfile %s.\n", lockfile);
+		printf("The oprofile daemon must be running (oprofile must"
+		       " have been initialised with 'opcontrol --start-daemon').\n");
+		return 1;
+	}
+
+	lfile = fopen(lockfile, "r");
+	if (!lfile) {
+		printf("Error opening lockfile %s.\n", lockfile);
+		return 1;
+	}
+
+	err = fscanf(lfile, "%lud", (unsigned long *) &dpid);
+	if (err != 1) {
+		printf("Error reading pid from lockfile %s.\n", lockfile);
+		return 1;
+	}
+	fclose(lfile);
+
+	efile = fopen(enable, "r");
+	if (!efile) {
+		printf("Error opening %s.\n", enable);
+		return 1;
+	}
+
+	if (strstr(argv[0], "opstart")) {
+		printf("Starting Profiler\n");
+		sig = SIGUSR1;
+		enb = 1;
+	} else if (strstr(argv[0], "opstop")) {
+		printf("Stopping Oprofile.\n");
+		printf("You need to run 'opcontrol --dump' when the session"
+		       " is finished.\n");
+		sig = SIGUSR2;
+		enb = 0;
+	} else {
+		printf("Error: Please call as 'opstart' or 'opstop'\n");
+		return 1;
+	}
+
+	err = kill(dpid, 0);
+	if (err) {
+		printf("Error sending signal to oprofiled. Stale lockfile"
+		       " (%s) ?\n", lockfile);
+		return 1;
+	}
+
+	fprintf(efile, "%d\n", enb);
+	err = kill(dpid, sig);
+	if (err) {
+		printf("Error sending signal to oprofiled. Stale lockfile"
+		       " (%s) ?\n", lockfile);
+		return 1;
+	}
+
+	return 0;
+}
+
Index: oprofile/configure.in
===================================================================
--- oprofile.orig/configure.in	2008-07-02 15:13:58.000000000 +0100
+++ oprofile/configure.in	2008-07-02 15:17:37.000000000 +0100
@@ -16,6 +16,7 @@
 AM_CONFIG_HEADER(config.h)
 
 AC_PROG_RANLIB
+AC_PROG_LN_S
 AC_PROG_LIBTOOL
 
 dnl for the man page
@@ -241,6 +242,8 @@
 	doc/xsl/catalog-1.xml \
 	doc/oprofile.1 \
 	doc/opcontrol.1 \
+	doc/opstart.1 \
+	doc/opstop.1 \
 	doc/ophelp.1 \
 	doc/opreport.1 \
 	doc/opannotate.1 \
Index: oprofile/doc/Makefile.am
===================================================================
--- oprofile.orig/doc/Makefile.am	2008-07-02 15:13:59.000000000 +0100
+++ oprofile/doc/Makefile.am	2008-07-02 15:14:07.000000000 +0100
@@ -11,6 +11,8 @@
 man_MANS = \
 	oprofile.1 \
 	opcontrol.1 \
+	opstart.1 \
+	opstop.1 \
 	opreport.1 \
 	opannotate.1 \
 	opgprof.1 \
Index: oprofile/doc/opstart.1.in
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ oprofile/doc/opstart.1.in	2008-07-02 15:14:07.000000000 +0100
@@ -0,0 +1,27 @@
+.TH OPSTART 1 "@DATE@" "oprofile @VERSION@"
+.UC 4
+.SH NAME
+opstart \- start OProfile profiling
+.SH SYNOPSIS
+.br
+.B opstart
+.SH DESCRIPTION
+.B opstart
+is a simple optimised command to start profiling with 2.6 Linux kernels.
+OProfile should have already been initialised by calling "opcontrol --start-daemon".
+
+.SH ENVIRONMENT
+No special environment variables are recognised by opstart.
+
+.SH FILES
+.TP
+.I /var/lib/oprofile/samples/
+The location of the generated sample files.
+
+.SH VERSION
+.TP
+This man page is current for @PACKAGE@-@VERSION@.
+
+.SH SEE ALSO
+.BR @OP_DOCDIR@,
+.BR oprofile(1)
Index: oprofile/doc/opstop.1.in
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ oprofile/doc/opstop.1.in	2008-07-02 15:14:07.000000000 +0100
@@ -0,0 +1,28 @@
+.TH OPSTOP 1 "@DATE@" "oprofile @VERSION@"
+.UC 4
+.SH NAME
+opstop \- stop OProfile profiling
+.SH SYNOPSIS
+.br
+.B opstop
+.SH DESCRIPTION
+.B opstop
+is a simple optimsed command to stop profiling with 2.6 Linux kernels.
+You need to run "opcontrol --dump" before being able to view a profile
+with opreport.
+
+.SH ENVIRONMENT
+No special environment variables are recognised by opstop.
+
+.SH FILES
+.TP
+.I /var/lib/oprofile/samples/
+The location of the generated sample files.
+
+.SH VERSION
+.TP
+This man page is current for @PACKAGE@-@VERSION@.
+
+.SH SEE ALSO
+.BR @OP_DOCDIR@,
+.BR oprofile(1)