summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorhunt <hunt>2005-06-28 17:57:28 +0000
committerhunt <hunt>2005-06-28 17:57:28 +0000
commit8a32c18d30dcd9dd664df74cd0c647ddfc060171 (patch)
treeadbd0e4f348f412e14b27ff5a56e18d3e363dc4f /runtime
parent63e9752cb5df26bc1a195feff92ad09f6d07482a (diff)
downloadsystemtap-steved-8a32c18d30dcd9dd664df74cd0c647ddfc060171.tar.gz
systemtap-steved-8a32c18d30dcd9dd664df74cd0c647ddfc060171.tar.xz
systemtap-steved-8a32c18d30dcd9dd664df74cd0c647ddfc060171.zip
2005-06-28 Martin Hunt <hunt@redhat.com>
* librelay.c (merge_output): Use unlocked stdio to improve speed. * stp_merge.c: New file. * Makefile: Add stp_merge.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/stpd/ChangeLog9
-rw-r--r--runtime/stpd/Makefile7
-rw-r--r--runtime/stpd/librelay.c39
-rw-r--r--runtime/stpd/stp_merge.c120
4 files changed, 149 insertions, 26 deletions
diff --git a/runtime/stpd/ChangeLog b/runtime/stpd/ChangeLog
index 9ff0d198..1a260443 100644
--- a/runtime/stpd/ChangeLog
+++ b/runtime/stpd/ChangeLog
@@ -1,3 +1,12 @@
+2005-06-28 Martin Hunt <hunt@redhat.com>
+
+ * librelay.c (merge_output): Use unlocked stdio
+ to improve speed.
+
+ * stp_merge.c: New file.
+
+ * Makefile: Add stp_merge.
+
2005-06-27 Martin Hunt <hunt@redhat.com>
* stpd.c (main): Add new command line arg, "-m"
diff --git a/runtime/stpd/Makefile b/runtime/stpd/Makefile
index 3e9d9f0e..3446ac7b 100644
--- a/runtime/stpd/Makefile
+++ b/runtime/stpd/Makefile
@@ -1,7 +1,10 @@
-all: stpd
+all: stpd stp_merge
stpd: stpd.c librelay.c
gcc -Wall -O3 -o stpd stpd.c librelay.c -lpthread
+stp_merge: stp_merge.c
+ gcc -Wall -O3 -o stp_merge stp_merge.c
+
clean:
- /bin/rm -f stpd stpd.o librelay.o *~
+ /bin/rm -f stpd stp_merge *.o *~
diff --git a/runtime/stpd/librelay.c b/runtime/stpd/librelay.c
index dd475239..f997981b 100644
--- a/runtime/stpd/librelay.c
+++ b/runtime/stpd/librelay.c
@@ -508,21 +508,15 @@ int init_stp(const char *modname,
static int merge_output(void)
{
int c, i, j, dropped=0;
- long count=0, min, num[NR_CPUS];
- char *ptr, tmp[PATH_MAX];
- FILE *ofp, *fp[NR_CPUS];
+ long count=0, min, num[ncpus];
+ char buf[32], tmp[PATH_MAX];
+ FILE *ofp, *fp[ncpus];
- char *buf = malloc (MERGE_BUF_SIZE);
- if (!buf) {
- perror("malloc in merge_ouptut:");
- return -1;
- }
-
for (i = 0; i < ncpus; i++) {
- sprintf(tmp, "%s%d", percpu_tmpfilebase, i);
- fp[i] = fopen(tmp, "r");
+ sprintf (tmp, "%s%d", percpu_tmpfilebase, i);
+ fp[i] = fopen (tmp, "r");
if (!fp[i]) {
- fprintf(stderr, "error opening file %s.\n", tmp);
+ fprintf (stderr, "error opening file %s.\n", tmp);
return -1;
}
if (fread (buf, TIMESTAMP_SIZE, 1, fp[i]))
@@ -530,9 +524,10 @@ static int merge_output(void)
else
num[i] = 0;
}
- ofp = fopen(outfile_name, "w");
+
+ ofp = fopen (outfile_name, "w");
if (!ofp) {
- fprintf(stderr, "ERROR: couldn't open output file %s: errcode = %s\n",
+ fprintf (stderr, "ERROR: couldn't open output file %s: errcode = %s\n",
outfile_name, strerror(errno));
return -1;
}
@@ -547,12 +542,14 @@ static int merge_output(void)
}
}
- ptr = buf;
while (1) {
- c = fgetc(fp[j]);
+ c = fgetc_unlocked (fp[j]);
if (c == 0 || c == EOF)
break;
- *ptr++ = c;
+ if (!quiet)
+ fputc_unlocked (c, stdout);
+ if (!print_only)
+ fputc_unlocked (c, ofp);
}
if (min && ++count != min) {
// fprintf(stderr, "got %ld. expected %ld\n", min, count);
@@ -560,12 +557,6 @@ static int merge_output(void)
dropped++ ;
}
- *ptr = 0;
- if (!quiet)
- fputs (buf, stdout);
- if (!print_only)
- fputs (buf, ofp);
-
if (fread (buf, TIMESTAMP_SIZE, 1, fp[j]))
num[j] = strtoul (buf, NULL, 10);
else
@@ -595,7 +586,7 @@ static void postprocess_and_exit(void)
if (!streaming() && merge) {
close_all_relayfs_files();
merge_output();
- delete_percpu_files();
+ //delete_percpu_files();
}
close(control_channel);
diff --git a/runtime/stpd/stp_merge.c b/runtime/stpd/stp_merge.c
new file mode 100644
index 00000000..739e34cd
--- /dev/null
+++ b/runtime/stpd/stp_merge.c
@@ -0,0 +1,120 @@
+/*
+ * stp_merge.c - stp merge program
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Redhat Inc, 2005
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+static void usage (char *prog)
+{
+ fprintf(stderr, "%s [-o output_filename] input_files ...\n", prog);
+ exit(1);
+}
+
+#define TIMESTAMP_SIZE 11
+#define NR_CPUS 256
+
+int main (int argc, char *argv[])
+{
+ char *outfile_name = NULL;
+ char buf[32];
+ int c, i, j, dropped=0;
+ long count=0, min, num[NR_CPUS];
+ FILE *ofp, *fp[NR_CPUS];
+ int ncpus;
+
+ while ((c = getopt (argc, argv, "o:")) != EOF) {
+ switch (c) {
+ case 'o':
+ outfile_name = optarg;
+ break;
+ default:
+ usage(argv[0]);
+ }
+ }
+
+ if (optind == argc)
+ usage (argv[0]);
+
+ i = 0;
+ while (optind < argc) {
+ fp[i] = fopen(argv[optind++], "r");
+ if (!fp[i]) {
+ fprintf(stderr, "error opening file %s.\n", argv[optind - 1]);
+ return -1;
+ }
+ if (fread (buf, TIMESTAMP_SIZE, 1, fp[i]))
+ num[i] = strtoul (buf, NULL, 10);
+ else
+ num[i] = 0;
+ i++;
+ }
+ ncpus = i;
+
+ if (!outfile_name)
+ ofp = stdout;
+ else {
+ ofp = fopen(outfile_name, "w");
+ if (!ofp) {
+ fprintf(stderr, "ERROR: couldn't open output file %s: errcode = %s\n",
+ outfile_name, strerror(errno));
+ return -1;
+ }
+ }
+
+ do {
+ min = num[0];
+ j = 0;
+ for (i = 1; i < ncpus; i++) {
+ if (min == 0 || (num[i] && num[i] < min)) {
+ min = num[i];
+ j = i;
+ }
+ }
+
+ while (1) {
+ c = fgetc_unlocked(fp[j]);
+ if (c == 0 || c == EOF)
+ break;
+ fputc_unlocked (c, ofp);
+ }
+ if (min && ++count != min) {
+ // fprintf(stderr, "got %ld. expected %ld\n", min, count);
+ count = min;
+ dropped++ ;
+ }
+
+ if (fread (buf, TIMESTAMP_SIZE, 1, fp[j]))
+ num[j] = strtoul (buf, NULL, 10);
+ else
+ num[j] = 0;
+ } while (min);
+
+ fputs ("\n", ofp);
+
+ for (i = 0; i < ncpus; i++)
+ fclose (fp[i]);
+ fclose (ofp);
+ printf ("sequence had %d drops\n", dropped);
+ return 0;
+}