summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2007-06-20 16:21:56 +0000
committerhunt <hunt>2007-06-20 16:21:56 +0000
commitcb53a4f46d192cd6870d873a1c8b2586eb6bd3b4 (patch)
tree367e67afad75fcbe2d4b3a7cd7c2fde6badcf7ce
parent24374413e181f47ce4c1330e4b64634c985d23a0 (diff)
downloadsystemtap-steved-cb53a4f46d192cd6870d873a1c8b2586eb6bd3b4.tar.gz
systemtap-steved-cb53a4f46d192cd6870d873a1c8b2586eb6bd3b4.tar.xz
systemtap-steved-cb53a4f46d192cd6870d873a1c8b2586eb6bd3b4.zip
2007-06-20 Martin Hunt <hunt@redhat.com>
* stap_merge.c (main): Add verbose option. Will realloc buffer if current size is too small. Check return codes from writes so gcc won't complain.
-rw-r--r--runtime/staprun/ChangeLog6
-rw-r--r--runtime/staprun/stap_merge.c45
2 files changed, 42 insertions, 9 deletions
diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog
index 2ccfbb8a..bbcb57ae 100644
--- a/runtime/staprun/ChangeLog
+++ b/runtime/staprun/ChangeLog
@@ -1,3 +1,9 @@
+2007-06-20 Martin Hunt <hunt@redhat.com>
+
+ * stap_merge.c (main): Add verbose option. Will realloc
+ buffer if current size is too small. Check return codes
+ from writes so gcc won't complain.
+
2007-06-07 Martin Hunt <hunt@redhat.com>
* relay_old.c (open_relayfs_files): Add support for
diff --git a/runtime/staprun/stap_merge.c b/runtime/staprun/stap_merge.c
index 20de1f2a..051a344b 100644
--- a/runtime/staprun/stap_merge.c
+++ b/runtime/staprun/stap_merge.c
@@ -27,8 +27,8 @@
static void usage (char *prog)
{
- fprintf(stderr, "%s [-o output_filename] input_files ...\n", prog);
- exit(1);
+ fprintf(stderr, "%s [-v] [-o output_filename] input_files ...\n", prog);
+ exit(-1);
}
#define TIMESTAMP_SIZE (sizeof(int))
@@ -36,15 +36,24 @@ static void usage (char *prog)
int main (int argc, char *argv[])
{
- char *outfile_name = NULL;
- char buf[8192];
- int c, i, j, dropped=0;
+ char *buf, *outfile_name = NULL;
+ int c, i, j, rc, dropped=0;
long count=0, min, num[NR_CPUS];
FILE *ofp, *fp[NR_CPUS];
- int ncpus, len;
+ int ncpus, len, verbose = 0;
+ int bufsize = 65536;
- while ((c = getopt (argc, argv, "o:")) != EOF) {
+ buf = malloc(bufsize);
+ if (buf == NULL) {
+ fprintf(stderr, "Memory allocation failed.\n");
+ exit(-2);
+ }
+
+ while ((c = getopt (argc, argv, "vo:")) != EOF) {
switch (c) {
+ case 'v':
+ verbose = 1;
+ break;
case 'o':
outfile_name = optarg;
break;
@@ -92,9 +101,27 @@ int main (int argc, char *argv[])
}
}
+
if (fread(&len, sizeof(int), 1, fp[j])) {
- fread(buf, len, 1, fp[j]);
- fwrite(buf, len, 1, ofp);
+ if (verbose)
+ fprintf(stderr, "[CPU %d, seq=%ld, length=%d]\n", j, min, len);
+ if (len > bufsize) {
+ bufsize = len * 2;
+ if (verbose) fprintf(stderr, "reallocating %d bytes\n", bufsize);
+ buf = realloc(buf, bufsize);
+ if (buf == NULL) {
+ fprintf(stderr, "Memory allocation failed.\n");
+ exit(-2);
+ }
+ }
+ if ((rc = fread(buf, len, 1, fp[j]) <= 0)) {
+ fprintf(stderr, "fread error: got %d\n", rc);
+ exit(-3);
+ }
+ if ((rc = fwrite(buf, len, 1, ofp)) <= 0) {
+ fprintf(stderr, "fread error: got %d\n", rc);
+ exit(-3);
+ }
}
if (min && ++count != min) {