summaryrefslogtreecommitdiffstats
path: root/meta/recipes-kernel/oprofile/oprofile/opstart.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-kernel/oprofile/oprofile/opstart.patch')
-rw-r--r--meta/recipes-kernel/oprofile/oprofile/opstart.patch245
1 files changed, 245 insertions, 0 deletions
diff --git a/meta/recipes-kernel/oprofile/oprofile/opstart.patch b/meta/recipes-kernel/oprofile/oprofile/opstart.patch
new file mode 100644
index 0000000000..8696f4ef4d
--- /dev/null
+++ b/meta/recipes-kernel/oprofile/oprofile/opstart.patch
@@ -0,0 +1,245 @@
1Upstream-Status: Pending
2
3The patch gives a low overhead way of starting/stopping oprofile which
4doesn't involve script exection.
5
6(written by RP in OpenedHand days)
7
8diff --git a/utils/Makefile.am b/utils/Makefile.am
9index d34b060..dff15f9 100644
10--- oprofile.orig/utils/Makefile.am
11+++ oprofile/utils/Makefile.am
12@@ -7,7 +7,7 @@ AM_LDFLAGS = @OP_LDFLAGS@
13
14 LIBS=@POPT_LIBS@ @LIBERTY_LIBS@
15
16-bin_PROGRAMS = ophelp op-check-perfevents
17+bin_PROGRAMS = ophelp op-check-perfevents opstart
18 dist_bin_SCRIPTS = opcontrol
19
20 op_check_perfevents_SOURCES = op_perf_events_checker.c
21@@ -15,3 +15,10 @@ op_check_perfevents_CPPFLAGS = ${AM_CFLAGS} @PERF_EVENT_FLAGS@
22
23 ophelp_SOURCES = ophelp.c
24 ophelp_LDADD = ../libop/libop.a ../libutil/libutil.a
25+
26+opstart_SOURCES = opstart.c
27+
28+install-exec-local:
29+ cd $(DESTDIR)/$(bindir) && \
30+ rm -f opstop && \
31+ $(LN_S) opstart opstop
32Index: oprofile/utils/opstart.c
33===================================================================
34--- /dev/null 1970-01-01 00:00:00.000000000 +0000
35+++ oprofile/utils/opstart.c 2008-07-02 15:14:07.000000000 +0100
36@@ -0,0 +1,110 @@
37+/**
38+ * @file opstart.c
39+ * Start/Stop oprofile
40+ *
41+ * @remark Copyright 2007 Openedhand Ltd.
42+ * @remark Read the file COPYING
43+ *
44+ * @author Richard Purdie
45+ */
46+
47+#include <signal.h>
48+#include <stdio.h>
49+#include <stdlib.h>
50+#include <string.h>
51+#include <unistd.h>
52+#include <sys/types.h>
53+#include <sys/stat.h>
54+
55+int main(const int argc, const char* argv[])
56+{
57+ const char *enable = "/dev/oprofile/enable";
58+ const char *lockfile;
59+ unsigned long dpid;
60+ struct stat sbuf;
61+ FILE *lfile, *efile;
62+ int sig, enb, err;
63+
64+ if (argc >= 2) {
65+ printf("Error: Invalid options.\n");
66+ return 1;
67+ }
68+
69+ lockfile = getenv("LOCK_FILE");
70+ if (!lockfile)
71+ lockfile = "/var/lib/oprofile/lock";
72+
73+ /* Add SESSION_DIR support? */
74+
75+ if (geteuid()) {
76+ printf("Error: This program must be run as root.\n");
77+ return 1;
78+ }
79+
80+ if (stat(enable, &sbuf)) {
81+ printf("Error: Could not find /dev/oprofile/enable, the"
82+ " kernel module probably isn't loaded.\n");
83+ printf("This binary only works with 2.6 kernels and oprofile"
84+ " must have been initialised with 'opcontrol --start-daemon'.\n");
85+ return 1;
86+ }
87+
88+ if (stat(lockfile, &sbuf)) {
89+ printf("Error: Could not find lockfile %s.\n", lockfile);
90+ printf("The oprofile daemon must be running (oprofile must"
91+ " have been initialised with 'opcontrol --start-daemon').\n");
92+ return 1;
93+ }
94+
95+ lfile = fopen(lockfile, "r");
96+ if (!lfile) {
97+ printf("Error opening lockfile %s.\n", lockfile);
98+ return 1;
99+ }
100+
101+ err = fscanf(lfile, "%lud", (unsigned long *) &dpid);
102+ if (err != 1) {
103+ printf("Error reading pid from lockfile %s.\n", lockfile);
104+ return 1;
105+ }
106+ fclose(lfile);
107+
108+ efile = fopen(enable, "r");
109+ if (!efile) {
110+ printf("Error opening %s.\n", enable);
111+ return 1;
112+ }
113+
114+ if (strstr(argv[0], "opstart")) {
115+ printf("Starting Profiler\n");
116+ sig = SIGUSR1;
117+ enb = 1;
118+ } else if (strstr(argv[0], "opstop")) {
119+ printf("Stopping Oprofile.\n");
120+ printf("You need to run 'opcontrol --dump' when the session"
121+ " is finished.\n");
122+ sig = SIGUSR2;
123+ enb = 0;
124+ } else {
125+ printf("Error: Please call as 'opstart' or 'opstop'\n");
126+ return 1;
127+ }
128+
129+ err = kill(dpid, 0);
130+ if (err) {
131+ printf("Error sending signal to oprofiled. Stale lockfile"
132+ " (%s) ?\n", lockfile);
133+ return 1;
134+ }
135+
136+ fprintf(efile, "%d\n", enb);
137+ err = kill(dpid, sig);
138+ if (err) {
139+ printf("Error sending signal to oprofiled. Stale lockfile"
140+ " (%s) ?\n", lockfile);
141+ return 1;
142+ }
143+
144+ return 0;
145+}
146+
147Index: oprofile/configure.ac
148===================================================================
149--- oprofile.orig/configure.ac 2008-07-02 15:13:58.000000000 +0100
150+++ oprofile/configure.ac 2008-07-02 15:17:37.000000000 +0100
151@@ -16,6 +16,7 @@
152 AM_CONFIG_HEADER(config.h)
153
154 AC_PROG_RANLIB
155+AC_PROG_LN_S
156 AC_PROG_LIBTOOL
157
158 dnl for the man page
159@@ -241,6 +242,8 @@
160 doc/xsl/catalog-1.xml \
161 doc/oprofile.1 \
162 doc/opcontrol.1 \
163+ doc/opstart.1 \
164+ doc/opstop.1 \
165 doc/ophelp.1 \
166 doc/opreport.1 \
167 doc/opannotate.1 \
168Index: oprofile/doc/Makefile.am
169===================================================================
170--- oprofile.orig/doc/Makefile.am 2008-07-02 15:13:59.000000000 +0100
171+++ oprofile/doc/Makefile.am 2008-07-02 15:14:07.000000000 +0100
172@@ -11,6 +11,8 @@
173 man_MANS = \
174 oprofile.1 \
175 opcontrol.1 \
176+ opstart.1 \
177+ opstop.1 \
178 opreport.1 \
179 opannotate.1 \
180 opgprof.1 \
181Index: oprofile/doc/opstart.1.in
182===================================================================
183--- /dev/null 1970-01-01 00:00:00.000000000 +0000
184+++ oprofile/doc/opstart.1.in 2008-07-02 15:14:07.000000000 +0100
185@@ -0,0 +1,27 @@
186+.TH OPSTART 1 "@DATE@" "oprofile @VERSION@"
187+.UC 4
188+.SH NAME
189+opstart \- start OProfile profiling
190+.SH SYNOPSIS
191+.br
192+.B opstart
193+.SH DESCRIPTION
194+.B opstart
195+is a simple optimised command to start profiling with 2.6 Linux kernels.
196+OProfile should have already been initialised by calling "opcontrol --start-daemon".
197+
198+.SH ENVIRONMENT
199+No special environment variables are recognised by opstart.
200+
201+.SH FILES
202+.TP
203+.I /var/lib/oprofile/samples/
204+The location of the generated sample files.
205+
206+.SH VERSION
207+.TP
208+This man page is current for @PACKAGE@-@VERSION@.
209+
210+.SH SEE ALSO
211+.BR @OP_DOCDIR@,
212+.BR oprofile(1)
213Index: oprofile/doc/opstop.1.in
214===================================================================
215--- /dev/null 1970-01-01 00:00:00.000000000 +0000
216+++ oprofile/doc/opstop.1.in 2008-07-02 15:14:07.000000000 +0100
217@@ -0,0 +1,28 @@
218+.TH OPSTOP 1 "@DATE@" "oprofile @VERSION@"
219+.UC 4
220+.SH NAME
221+opstop \- stop OProfile profiling
222+.SH SYNOPSIS
223+.br
224+.B opstop
225+.SH DESCRIPTION
226+.B opstop
227+is a simple optimsed command to stop profiling with 2.6 Linux kernels.
228+You need to run "opcontrol --dump" before being able to view a profile
229+with opreport.
230+
231+.SH ENVIRONMENT
232+No special environment variables are recognised by opstop.
233+
234+.SH FILES
235+.TP
236+.I /var/lib/oprofile/samples/
237+The location of the generated sample files.
238+
239+.SH VERSION
240+.TP
241+This man page is current for @PACKAGE@-@VERSION@.
242+
243+.SH SEE ALSO
244+.BR @OP_DOCDIR@,
245+.BR oprofile(1)