diff options
author | hunt <hunt> | 2006-09-18 16:49:03 +0000 |
---|---|---|
committer | hunt <hunt> | 2006-09-18 16:49:03 +0000 |
commit | 8857a715a1c9e504919e9702ee42ced4a8f5dcac (patch) | |
tree | 2bb67c13bcaa8a9702cb83332a628d047eba9738 | |
parent | ddcd4a1d43f7b3bc6edb5c431d4fd29bc72fa471 (diff) | |
download | systemtap-steved-8857a715a1c9e504919e9702ee42ced4a8f5dcac.tar.gz systemtap-steved-8857a715a1c9e504919e9702ee42ced4a8f5dcac.tar.xz systemtap-steved-8857a715a1c9e504919e9702ee42ced4a8f5dcac.zip |
2006-09-18 Martin Hunt <hunt@redhat.com>
* stpd.c (usage): Remove "-m" option.
(main): Print warning if "-m" is used.
* librelay.c (merge_output): Rewrite to handle
new format that support binary.
(stp_main_loop): Read merge option from the
transport info message.
-rw-r--r-- | runtime/stpd/ChangeLog | 9 | ||||
-rw-r--r-- | runtime/stpd/librelay.c | 79 | ||||
-rw-r--r-- | runtime/stpd/stpd.c | 4 |
3 files changed, 57 insertions, 35 deletions
diff --git a/runtime/stpd/ChangeLog b/runtime/stpd/ChangeLog index 370d7671..dfc22682 100644 --- a/runtime/stpd/ChangeLog +++ b/runtime/stpd/ChangeLog @@ -1,3 +1,12 @@ +2006-09-18 Martin Hunt <hunt@redhat.com> + + * stpd.c (usage): Remove "-m" option. + (main): Print warning if "-m" is used. + * librelay.c (merge_output): Rewrite to handle + new format that support binary. + (stp_main_loop): Read merge option from the + transport info message. + 2006-09-13 Martin Hunt <hunt@redhat.com> * librelay.c (init_relayfs): Exec stp_check and find diff --git a/runtime/stpd/librelay.c b/runtime/stpd/librelay.c index e348928d..13b00ebf 100644 --- a/runtime/stpd/librelay.c +++ b/runtime/stpd/librelay.c @@ -40,6 +40,7 @@ #include <linux/limits.h> #include <sys/wait.h> #include <sys/statfs.h> +#include <stdint.h> #include "librelay.h" /* stp_check script */ @@ -57,6 +58,7 @@ static struct params { unsigned subbuf_size; unsigned n_subbufs; + int merge; char relay_filebase[256]; } params; @@ -90,7 +92,7 @@ static pthread_t reader[NR_CPUS]; static int control_channel; /* flags */ -extern int print_only, quiet, merge, verbose; +extern int print_only, quiet, verbose; extern unsigned int buffer_size; extern char *modname; extern char *modpath; @@ -581,20 +583,20 @@ int init_stp(int print_summary) /* length of timestamp in output field 0 */ -#define TIMESTAMP_SIZE (sizeof(int)) +#define TIMESTAMP_SIZE (sizeof(uint32_t)) /** * merge_output - merge per-cpu output * */ -#define MERGE_BUF_SIZE 32768 - +#define MERGE_BUF_SIZE 16*1024 static int merge_output(void) { - int c, i, j, dropped=0; - long count=0, min, num[ncpus]; - char buf[32], tmp[PATH_MAX]; + char *buf[ncpus], tmp[PATH_MAX]; + int i, j, dropped=0; + uint32_t count=0, min, num[ncpus]; FILE *ofp, *fp[ncpus]; + uint32_t length[ncpus]; for (i = 0; i < ncpus; i++) { sprintf (tmp, "%s%d", percpu_tmpfilebase, i); @@ -603,10 +605,19 @@ static int merge_output(void) fprintf (stderr, "error opening file %s.\n", tmp); return -1; } - if (fread (buf, TIMESTAMP_SIZE, 1, fp[i])) - num[i] = *((int *)buf); - else - num[i] = 0; + num[i] = 0; + buf[i] = malloc(MERGE_BUF_SIZE); + printf("buf[%d] = %p\n", i, buf[i]); + if (!buf[i]) { + fprintf(stderr,"Out of memory in merge_output(). Aborting merge.\n"); + printf("Out of memory in merge_output(). Aborting merge.\n"); + return -1; + } + + if (fread_unlocked (&length[i], sizeof(uint32_t), 1, fp[i])) { + if (fread_unlocked (buf[i], length[i]+TIMESTAMP_SIZE, 1, fp[i])) + num[i] = *((uint32_t *)buf[i]); + } } if (!outfile_name) @@ -629,34 +640,35 @@ static int merge_output(void) } } - while (1) { - c = fgetc_unlocked (fp[j]); - if (c == 0 || c == EOF) - break; - if (!quiet) - fputc_unlocked (c, stdout); - if (!print_only) - fputc_unlocked (c, ofp); - } + if (!quiet) + fwrite_unlocked (buf[j]+TIMESTAMP_SIZE, length[j], 1, stdout); + if (!print_only) + fwrite_unlocked (buf[j]+TIMESTAMP_SIZE, length[j], 1, ofp); + if (min && ++count != min) { count = min; dropped++ ; } - if (fread (buf, TIMESTAMP_SIZE, 1, fp[j])) - num[j] = *((int *)buf); - else - num[j] = 0; + num[j] = 0; + if (fread_unlocked (&length[j], sizeof(uint32_t), 1, fp[j])) { + printf("length[%d] = %d\n", j, length[j]); + printf("buf[%d] = %p\n", j, buf[j]); + if (fread_unlocked (buf[j], length[j]+TIMESTAMP_SIZE, 1, fp[j])) + num[j] = *((uint32_t *)buf[j]); + } } while (min); if (!print_only) - fputs ("\n", ofp); + fwrite_unlocked ("\n", 1, 1, ofp); for (i = 0; i < ncpus; i++) fclose (fp[i]); fclose (ofp); + if (dropped) fprintf (stderr, "Sequence had %d drops.\n", dropped); + return 0; } @@ -697,7 +709,7 @@ static void cleanup_and_exit (int closed) if (transport_mode == STP_TRANSPORT_RELAYFS) { close_all_relayfs_files(); - if (merge) { + if (params.merge) { merge_output(); delete_percpu_files(); } @@ -790,13 +802,16 @@ int stp_main_loop(void) transport_mode = info->transport_mode; params.subbuf_size = info->subbuf_size; params.n_subbufs = info->n_subbufs; + params.merge = info->merge; #ifdef DEBUG - if (transport_mode == STP_TRANSPORT_RELAYFS) - fprintf (stderr, "TRANSPORT_INFO recvd: RELAYFS %d bufs of %d bytes.\n", - params.n_subbufs, - params.subbuf_size); - else - fprintf (stderr, "TRANSPORT_INFO recvd: PROC with %d Mbyte buffers.\n", + if (transport_mode == STP_TRANSPORT_RELAYFS) { + fprintf(stderr,"TRANSPORT_INFO recvd: RELAYFS %d bufs of %d bytes.\n", + params.n_subbufs, + params.subbuf_size); + if (params.merge) + fprintf(stderr,"Merge output\n"); + } else + fprintf(stderr,"TRANSPORT_INFO recvd: PROC with %d Mbyte buffers.\n", info->buf_size); #endif if (!streaming()) { diff --git a/runtime/stpd/stpd.c b/runtime/stpd/stpd.c index 96710b08..a815d5be 100644 --- a/runtime/stpd/stpd.c +++ b/runtime/stpd/stpd.c @@ -33,7 +33,6 @@ extern int optind; int print_only = 0; int quiet = 0; -int merge = 1; int verbose = 0; int target_pid = 0; int driver_pid = 0; @@ -52,7 +51,6 @@ static void usage(char *prog) { fprintf(stderr, "\n%s [-m] [-p] [-q] [-r] [-c cmd ] [-t pid]\n" "\t[-b bufsize] [-o FILE] kmod-name [kmod-options]\n", prog); - fprintf(stderr, "-m Don't merge per-cpu files.\n"); fprintf(stderr, "-p Print only. Don't log to files.\n"); fprintf(stderr, "-q Quiet. Don't display trace to stdout.\n"); fprintf(stderr, "-c cmd. Command \'cmd\' will be run and stpd will exit when it does.\n"); @@ -76,7 +74,7 @@ int main(int argc, char **argv) { switch (c) { case 'm': - merge = 0; + fprintf(stderr, "Warning: -m option deprecated. Ignoring...\n"); break; case 'p': print_only = 1; |