summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2009-09-16 15:55:19 -0700
committerJosh Stone <jistone@redhat.com>2009-09-16 15:55:19 -0700
commit9f7d5236c8fb1fd84636656416e1dad531e9586d (patch)
tree0dc2bdf43e92a67f3c182dad87836cb084697c3e
parentac505f97f1e85d95c9fe2b0401a375c2c8cd1cb9 (diff)
parent6be6402d1514d149e6e6adf66a5c50b80b8bbb0f (diff)
downloadsystemtap-steved-9f7d5236c8fb1fd84636656416e1dad531e9586d.tar.gz
systemtap-steved-9f7d5236c8fb1fd84636656416e1dad531e9586d.tar.xz
systemtap-steved-9f7d5236c8fb1fd84636656416e1dad531e9586d.zip
Merge branch 'master' of sourceware.org:/git/systemtap
-rw-r--r--NEWS3
-rw-r--r--loc2c-test.c1
-rw-r--r--runtime/staprun/relay.c83
-rw-r--r--runtime/staprun/relay_old.c82
-rw-r--r--staprun.8.in33
-rw-r--r--testsuite/systemtap.base/flightrec1.exp12
-rw-r--r--testsuite/systemtap.base/flightrec4.exp56
-rw-r--r--testsuite/systemtap.base/flightrec5.exp64
8 files changed, 297 insertions, 37 deletions
diff --git a/NEWS b/NEWS
index b31eaaf7..4fbf59e8 100644
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,9 @@
SYSTEMTAP_RUNTIME, SYSTEMTAP_TAPSET, SYSTEMTAP_DEBUGINFO_PATH
- nss and nss-tools are required to use this feature.
+- Support output file switching by SIGUSR2. Users can command running
+ stapio to switch output file by sending SIGUSR2.
+
- Memory consumption for scripts involving many uprobes has been
dramatically reduced.
diff --git a/loc2c-test.c b/loc2c-test.c
index 46c45827..b8883876 100644
--- a/loc2c-test.c
+++ b/loc2c-test.c
@@ -304,6 +304,7 @@ handle_variable (Dwarf_Die *lscopes, int lnscopes, int out,
break;
case DW_TAG_pointer_type:
+ case DW_TAG_reference_type:
if (store)
error (2, 0, _("store not supported for pointer type"));
c_translate_pointer (&pool, 1, cubias, typedie, &tail);
diff --git a/runtime/staprun/relay.c b/runtime/staprun/relay.c
index f4aa139f..0c009235 100644
--- a/runtime/staprun/relay.c
+++ b/runtime/staprun/relay.c
@@ -15,6 +15,7 @@
int out_fd[NR_CPUS];
static pthread_t reader[NR_CPUS];
static int relay_fd[NR_CPUS];
+static int switch_file[NR_CPUS];
static int bulkmode = 0;
static volatile int stop_threads = 0;
static time_t *time_backlog[NR_CPUS];
@@ -107,11 +108,25 @@ static int open_outfile(int fnum, int cpu, int remove_file)
return 0;
}
+static int switch_outfile(int cpu, int *fnum)
+{
+ int remove_file = 0;
+
+ dbug(3, "thread %d switching file\n", cpu);
+ close(out_fd[cpu]);
+ *fnum += 1;
+ if (fnum_max && *fnum >= fnum_max)
+ remove_file = 1;
+ if (open_outfile(*fnum, cpu, remove_file) < 0) {
+ perr("Couldn't open file for cpu %d, exiting.", cpu);
+ return -1;
+ }
+ return 0;
+}
+
/**
* reader_thread - per-cpu channel buffer reader
*/
-static void empty_handler(int __attribute__((unused)) sig) { /* do nothing */ }
-
static void *reader_thread(void *data)
{
char buf[131072];
@@ -119,10 +134,8 @@ static void *reader_thread(void *data)
struct pollfd pollfd;
struct timespec tim = {.tv_sec=0, .tv_nsec=200000000}, *timeout = &tim;
sigset_t sigs;
- struct sigaction sa;
off_t wsize = 0;
int fnum = 0;
- int remove_file = 0;
sigemptyset(&sigs);
sigaddset(&sigs,SIGUSR2);
@@ -131,11 +144,6 @@ static void *reader_thread(void *data)
sigfillset(&sigs);
sigdelset(&sigs,SIGUSR2);
- sa.sa_handler = empty_handler;
- sa.sa_flags = 0;
- sigemptyset(&sa.sa_mask);
- sigaction(SIGUSR2, &sa, NULL);
-
if (bulkmode) {
cpu_set_t cpu_mask;
CPU_ZERO(&cpu_mask);
@@ -156,33 +164,39 @@ static void *reader_thread(void *data)
pollfd.events = POLLIN;
do {
+ dbug(3, "thread %d start ppoll\n", cpu);
rc = ppoll(&pollfd, 1, timeout, &sigs);
+ dbug(3, "thread %d end ppoll:%d\n", cpu, rc);
if (rc < 0) {
dbug(3, "cpu=%d poll=%d errno=%d\n", cpu, rc, errno);
- if (errno != EINTR) {
+ if (errno == EINTR) {
+ if (stop_threads)
+ break;
+ if (switch_file[cpu]) {
+ switch_file[cpu] = 0;
+ if (switch_outfile(cpu, &fnum) < 0)
+ goto error_out;
+ wsize = 0;
+ }
+ } else {
_perr("poll error");
goto error_out;
- }
+ }
}
+
while ((rc = read(relay_fd[cpu], buf, sizeof(buf))) > 0) {
- wsize += rc;
/* Switching file */
- if (fsize_max && wsize > fsize_max) {
- close(out_fd[cpu]);
- fnum++;
- if (fnum_max && fnum == fnum_max)
- remove_file = 1;
- if (open_outfile(fnum, cpu, remove_file) < 0) {
- perr("Couldn't open file for cpu %d, exiting.", cpu);
+ if (fsize_max && wsize + rc > fsize_max) {
+ if (switch_outfile(cpu, &fnum) < 0)
goto error_out;
- }
- wsize = rc;
+ wsize = 0;
}
if (write(out_fd[cpu], buf, rc) != rc) {
if (errno != EPIPE)
perr("Couldn't write to output %d for cpu %d, exiting.", out_fd[cpu], cpu);
goto error_out;
}
+ wsize += rc;
}
} while (!stop_threads);
dbug(3, "exiting thread for cpu %d\n", cpu);
@@ -195,6 +209,25 @@ error_out:
return(NULL);
}
+static void switchfile_handler(int sig)
+{
+ int i;
+ if (stop_threads)
+ return;
+ for (i = 0; i < ncpus; i++)
+ if (reader[i] && switch_file[i]) {
+ dbug(2, "file switching is progressing, signal ignored.\n", sig);
+ return;
+ }
+ for (i = 0; i < ncpus; i++) {
+ if (reader[i]) {
+ switch_file[i] = 1;
+ pthread_kill(reader[i], SIGUSR2);
+ } else
+ break;
+ }
+}
+
/**
* init_relayfs - create files and threads for relayfs processing
*
@@ -308,6 +341,12 @@ int init_relayfs(void)
}
if (!load_only) {
+ struct sigaction sa;
+
+ sa.sa_handler = switchfile_handler;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGUSR2, &sa, NULL);
dbug(2, "starting threads\n");
for (i = 0; i < ncpus; i++) {
if (pthread_create(&reader[i], NULL, reader_thread,
@@ -327,7 +366,7 @@ void close_relayfs(void)
stop_threads = 1;
dbug(2, "closing\n");
for (i = 0; i < ncpus; i++) {
- if (reader[i])
+ if (reader[i])
pthread_kill(reader[i], SIGUSR2);
else
break;
diff --git a/runtime/staprun/relay_old.c b/runtime/staprun/relay_old.c
index 0254173f..8dfcc16b 100644
--- a/runtime/staprun/relay_old.c
+++ b/runtime/staprun/relay_old.c
@@ -19,6 +19,7 @@ static int proc_fd[NR_CPUS];
static FILE *percpu_tmpfile[NR_CPUS];
static char *relay_buffer[NR_CPUS];
static pthread_t reader[NR_CPUS];
+static int switch_file[NR_CPUS];
static int bulkmode = 0;
unsigned subbuf_size = 0;
unsigned n_subbufs = 0;
@@ -214,6 +215,22 @@ err1:
}
+static int switch_oldoutfile(int cpu, struct switchfile_ctrl_block *scb)
+{
+ dbug(3, "thread %d switching file\n", cpu);
+ if (percpu_tmpfile[cpu])
+ fclose(percpu_tmpfile[cpu]);
+ else
+ close(out_fd[cpu]);
+ scb->fnum ++;
+ if (fnum_max && scb->fnum == fnum_max)
+ scb->rmfile = 1;
+ if (open_oldoutfile(scb->fnum, cpu, scb->rmfile) < 0) {
+ perr("Couldn't open file for cpu %d, exiting.", cpu);
+ return -1;
+ }
+ return 0;
+}
/**
* process_subbufs - write ready subbufs to disk
*/
@@ -238,11 +255,7 @@ static int process_subbufs(struct _stp_buf_info *info,
len = (subbuf_size - sizeof(padding)) - padding;
scb->wsize += len;
if (fsize_max && scb->wsize > fsize_max) {
- fclose(percpu_tmpfile[cpu]);
- scb->fnum ++;
- if (fnum_max && scb->fnum == fnum_max)
- scb->rmfile = 1;
- if (open_oldoutfile(scb->fnum, cpu, scb->rmfile) < 0) {
+ if (switch_oldoutfile(cpu, scb) < 0) {
perr("Couldn't open file for cpu %d, exiting.", cpu);
return -1;
}
@@ -272,8 +285,17 @@ static void *reader_thread(void *data)
struct _stp_consumed_info consumed_info;
unsigned subbufs_consumed;
cpu_set_t cpu_mask;
+ struct timespec tim = {.tv_sec=0, .tv_nsec=200000000}, *timeout = &tim;
struct switchfile_ctrl_block scb = {0, 0, 0};
+ sigset_t sigs;
+
+ sigemptyset(&sigs);
+ sigaddset(&sigs,SIGUSR2);
+ pthread_sigmask(SIG_BLOCK, &sigs, NULL);
+ sigfillset(&sigs);
+ sigdelset(&sigs,SIGUSR2);
+
CPU_ZERO(&cpu_mask);
CPU_SET(cpu, &cpu_mask);
if( sched_setaffinity( 0, sizeof(cpu_mask), &cpu_mask ) < 0 )
@@ -281,15 +303,29 @@ static void *reader_thread(void *data)
pollfd.fd = relay_fd[cpu];
pollfd.events = POLLIN;
+#ifdef NEED_PPOLL
+ /* Without a real ppoll, there is a small race condition that could */
+ /* block ppoll(). So use a timeout to prevent that. */
+ timeout->tv_sec = 10;
+ timeout->tv_nsec = 0;
+#else
+ timeout = NULL;
+#endif
do {
- rc = poll(&pollfd, 1, -1);
+ rc = ppoll(&pollfd, 1, timeout, &sigs);
if (rc < 0) {
- if (errno != EINTR) {
+ if (errno == EINTR) {
+ if (switch_file[cpu]) {
+ switch_file[cpu] = 0;
+ if (switch_oldoutfile(cpu, &scb) < 0)
+ break;
+ scb.wsize = 0;
+ }
+ } else {
_perr("poll error");
break;
}
- err("WARNING: poll warning: %s\n", strerror(errno));
rc = 0;
}
@@ -324,12 +360,7 @@ int write_realtime_data(void *data, ssize_t nb)
ssize_t bw;
global_scb.wsize += nb;
if (fsize_max && global_scb.wsize > fsize_max) {
- close(out_fd[0]);
- global_scb.fnum++;
- if (fnum_max && global_scb.fnum == fnum_max)
- global_scb.rmfile = 1;
- if (open_oldoutfile(global_scb.fnum, 0,
- global_scb.rmfile) < 0) {
+ if (switch_oldoutfile(0, &global_scb) < 0) {
perr("Couldn't open file, exiting.");
return -1;
}
@@ -343,6 +374,23 @@ int write_realtime_data(void *data, ssize_t nb)
return bw != nb;
}
+static void switchfile_handler(int sig)
+{
+ int i;
+ for (i = 0; i < ncpus; i++)
+ if (reader[i] && switch_file[i]) {
+ dbug(2, "file switching is progressing, signal ignored.\n", sig);
+ return;
+ }
+ for (i = 0; i < ncpus; i++) {
+ if (reader[i]) {
+ switch_file[i] = 1;
+ pthread_kill(reader[i], SIGUSR2);
+ } else
+ break;
+ }
+}
+
/**
* init_relayfs - create files and threads for relayfs processing
*
@@ -353,6 +401,12 @@ int init_oldrelayfs(void)
int i, j;
struct statfs st;
char relay_filebase[PATH_MAX], proc_filebase[PATH_MAX];
+ struct sigaction sa;
+
+ sa.sa_handler = switchfile_handler;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGUSR2, &sa, NULL);
dbug(2, "initializing relayfs.n_subbufs=%d subbuf_size=%d\n", n_subbufs, subbuf_size);
diff --git a/staprun.8.in b/staprun.8.in
index 5fe2e7fa..5bf2ec61 100644
--- a/staprun.8.in
+++ b/staprun.8.in
@@ -138,6 +138,39 @@ To reattach to a kernel module, the
.I staprun
.B \-A
option would be used.
+
+.SH FILE SWITCHING BY SIGNAL
+After the
+.I staprun
+launched the
+.I stapio
+, users can command it to switch output file to next file when it
+outputs to file(s) (running staprun with
+.B \-o
+option) by sending a
+.B SIGUSR2
+signal to the
+.I stapio
+process. When it receives SIGUSR2, it will switch output file to
+new file with suffix
+.I .N
+where N is the sequential number.
+For example,
+.PP
+\& $ staprun \-o foo ...
+.PP
+outputs trace logs to
+.I foo
+and if it receives
+.B SIGUSR2
+signal, it switches output to
+.I foo.1
+file. And receiving
+.B SIGUSR2
+again, it switches to
+.I foo.2
+file.
+
.SH SAFETY AND SECURITY
Systemtap is an administrative tool. It exposes kernel internal data
structures and potentially private user information. See the
diff --git a/testsuite/systemtap.base/flightrec1.exp b/testsuite/systemtap.base/flightrec1.exp
index c32a77f2..73b6221e 100644
--- a/testsuite/systemtap.base/flightrec1.exp
+++ b/testsuite/systemtap.base/flightrec1.exp
@@ -30,7 +30,8 @@ expect {
}
wait
-exec kill -TERM $pid
+# switch file
+exec kill -USR2 $pid
# check output file
if {[catch {exec rm $test.out}]} {
@@ -40,4 +41,13 @@ if {[catch {exec rm $test.out}]} {
pass "$test (output file)"
}
+exec kill -TERM $pid
+
+# check switched output file
+if {[catch {exec rm $test.out.1}]} {
+ fail "$test (failed to switch output file)"
+ return -1
+} else {
+ pass "$test (switch output file)"
+}
diff --git a/testsuite/systemtap.base/flightrec4.exp b/testsuite/systemtap.base/flightrec4.exp
new file mode 100644
index 00000000..3f17563d
--- /dev/null
+++ b/testsuite/systemtap.base/flightrec4.exp
@@ -0,0 +1,56 @@
+set test "flightrec4"
+if {![installtest_p]} { untested $test; return }
+
+# run stapio in background mode with number limit
+spawn stap -F -S 1,2 -o $test.out -we {probe begin {}}
+# check whether stap outputs stapio pid
+set pid 0
+expect {
+ -timeout 240
+ -re {([0-9]+)\r\n} {
+ pass "$test (flight recorder option)"
+ set pid $expect_out(1,string)
+ exp_continue}
+ timeout { fail "$test (timeout)" }
+ eof { }
+}
+wait
+if {$pid == 0} {
+ fail "$test (no pid)"
+ return -1
+}
+
+# switch file to .1
+exec kill -USR2 $pid
+
+# check output file
+if {[catch {exec rm $test.out.0}]} {
+ fail "$test (no output file)"
+ return -1
+} else {
+ pass "$test (output file)"
+}
+
+# switch file to .2
+exec kill -USR2 $pid
+# switch file to .3 (this time, .1 file should be deleted)
+exec kill -USR2 $pid
+
+# check switched output file
+if {[catch {exec rm $test.out.1}]} {
+ pass "$test (old output file is removed)"
+} else {
+ fail "$test (failed to remove output file)"
+ return -1
+}
+
+exec kill -TERM $pid
+
+# check switched output file
+if {[catch {exec rm $test.out.2 $test.out.3}]} {
+ fail "$test (failed to switch output file)"
+ return -1
+} else {
+ pass "$test (switch output file)"
+}
+
diff --git a/testsuite/systemtap.base/flightrec5.exp b/testsuite/systemtap.base/flightrec5.exp
new file mode 100644
index 00000000..5d1c6d53
--- /dev/null
+++ b/testsuite/systemtap.base/flightrec5.exp
@@ -0,0 +1,64 @@
+set test "flightrec5"
+if {![installtest_p]} { untested $test; return }
+
+# run stapio in background mode with number limit and bulk mode
+spawn stap -F -S 1,2 -b -o $test.out -we {probe begin {}}
+# check whether stap outputs stapio pid
+set pid 0
+expect {
+ -timeout 240
+ -re {([0-9]+)\r\n} {
+ pass "$test (flight recorder option)"
+ set pid $expect_out(1,string)
+ exp_continue}
+ timeout { fail "$test (timeout)" }
+ eof { }
+}
+wait
+if {$pid == 0} {
+ fail "$test (no pid)"
+ return -1
+}
+
+# switch file to .1
+exec kill -USR2 $pid
+
+# check output file
+eval set outfile {[glob -nocomplain $test.out_cpu*.0]}
+if {$outfile == ""} {
+ fail "$test (no output file) $outfile"
+ exec kill -TERM $pid
+ return -1
+} else {
+ pass "$test (output file)"
+}
+eval exec rm $outfile
+
+print "pid = $pid"
+# switch file to .2
+exec kill -USR2 $pid
+# switch file to .3 (this time, .1 file should be deleted)
+exec kill -USR2 $pid
+
+exec kill -TERM $pid
+
+# check switched output file
+eval set outfile {[glob -nocomplain $test.out_cpu*.1]}
+if {$outfile == ""} {
+ pass "$test (old output file is removed)"
+} else {
+ fail "$test (failed to remove output file)"
+ eval exec rm $outfile
+ return -1
+}
+
+# check switched output file
+eval set outfile {[glob -nocomplain $test.out_cpu*.*]}
+if {$outfile == ""} {
+ fail "$test (failed to switch output file)"
+ return -1
+} else {
+ pass "$test (switch output file)"
+}
+eval exec rm $outfile
+