Add vfork/exec perf test. exec1 tests static binaries, exec2 tests dynamic
authorMatthew Dillon <dillon@dragonflybsd.org>
Sat, 10 Apr 2004 21:36:52 +0000 (21:36 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Sat, 10 Apr 2004 21:36:52 +0000 (21:36 +0000)
binaries (you can test resident dynamic binaries by 'resident /tmp/exec2'
and then running /tmp/exec2).

test/sysperf/Makefile
test/sysperf/exec1.c [new file with mode: 0644]

index 765b976..08754c4 100644 (file)
@@ -1,5 +1,5 @@
 #
-# $DragonFly: src/test/sysperf/Makefile,v 1.6 2004/03/28 09:21:53 dillon Exp $
+# $DragonFly: src/test/sysperf/Makefile,v 1.7 2004/04/10 21:36:52 dillon Exp $
 #
 
 TARGETS=/tmp/sc1 /tmp/sc2 /tmp/sc3 /tmp/sc4 \
@@ -9,7 +9,8 @@ TARGETS=/tmp/sc1 /tmp/sc2 /tmp/sc3 /tmp/sc4 \
        /tmp/fork1 /tmp/pipe1 /tmp/pipe2 \
        /tmp/sw1 /tmp/sw2 /tmp/sw3 \
        /tmp/mbw1 \
-       /tmp/upc1
+       /tmp/upc1 \
+       /tmp/exec1 /tmp/exec2
 
 CFLAGS= -O2 -g -I/usr/src/sys
 
@@ -72,5 +73,11 @@ all: $(TARGETS)
 /tmp/upc1: upcall.S upcall1.c blib.c
        $(CC) $(CFLAGS) -DUSE_CALLU2 upcall.S upcall1.c blib.c -o /tmp/upc1
 
+/tmp/exec1: exec1.c blib.c
+       $(CC) $(CFLAGS) -static -DISSTATIC exec1.c blib.c -o /tmp/exec1
+
+/tmp/exec2: exec1.c blib.c
+       $(CC) $(CFLAGS) exec1.c blib.c -o /tmp/exec2
+
 clean:
        rm -f $(TARGETS)
diff --git a/test/sysperf/exec1.c b/test/sysperf/exec1.c
new file mode 100644 (file)
index 0000000..75d39ad
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * exec1.c
+ *
+ * $DragonFly: src/test/sysperf/exec1.c,v 1.1 2004/04/10 21:36:52 dillon Exp $
+ */
+
+#include "blib.h"
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+
+char *Av0;
+
+static
+void
+execltest(void)
+{
+    pid_t pid;
+    char *elm;
+
+    if ((elm = strrchr(Av0, '/')) == NULL)
+       elm = Av0;
+    else
+       ++elm;
+
+    if ((pid = vfork()) == 0) {
+       setpriority(PRIO_PROCESS, getpid(), -20);
+       execl(Av0, elm, "dummy", NULL);
+       _exit(1);
+    } else if (pid < 0) {
+       perror("vfork");
+       exit(1);
+    } else {
+       int status;
+
+       while(waitpid(pid, &status, 0) != pid)
+           ;
+       if (WEXITSTATUS(status)) {
+           fprintf(stderr, "execl in child failed\n");
+           exit(1);
+       }
+    }
+}
+
+int
+main(int ac, char **av)
+{
+    int i;
+    int count;
+
+    Av0 = av[0];
+    if (ac == 2)
+       exit(0);
+
+    count = 0;
+    start_timing();
+    while (stop_timing(0, NULL) == 0) {
+       for (i = 0; i < 100; ++i)
+           execltest();
+       count += 100;
+    }
+    start_timing();
+    for (i = 0; i < count; ++i)
+       execltest();
+#ifdef ISSTATIC
+    stop_timing(count, "execl static program:", count);
+#else
+    stop_timing(count, "execl dynamic program:", count);
+#endif
+    return(0);
+}
+