#!/usr/bin/env dub
/+ dub.sdl:
name "android-research-start-bench"
platforms "linux"
dflags "-betterC"
targetPath "build"
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}
+/
/**
E7's bounded process-start microbenchmark: five trials of 1,000 fork/exec/waits.
Default invocation does nothing. --run PROGRAM [ARGS...] runs that exact argv
under the caller's actual app domain, stopping on the first failed child.
See ../index.md#current-target-experiments. Run only with owner approval.
*/
module (module) start_benchE7's bounded process-start microbenchmark: five trials of 1,000 fork/exec/waits.
Default invocation does nothing. --run PROGRAM [ARGS...] runs that exact argv
under the caller's actual app domain, stopping on the first failed child.
See ../index.md#current-target-experiments. Run only with owner approval.
start_bench;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.errnoD header file for C99.
pubs.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html, errno.h
Source
core/stdc/errno.d
errno : (alias) start_bench.errno = int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno, (alias constant) start_bench.EINTR = int core.stdc.errno.EINTR = 4EINTR;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stdioD header file for C99 <stdio.h>
pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h
Source
core/stdc/stdio.d
stdio : (alias) start_bench.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf, (alias) start_bench.fflush = int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trustedfflush;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stringD header file for C99.
pubs.opengroup.org/onlinepubs/009695399/basedefs/string.h.html, string.h
Source
core/stdc/string.d
string : (alias) start_bench.strcmp = int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogcstrcmp;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(package) core.sys.posix.syssys.(module) core.sys.posix.sys.waitD header file for POSIX.
wait : (alias) start_bench.waitpid = int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogcwaitpid;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.timeD header file for POSIX.
time : (alias) start_bench.clock_gettime = int core.sys.posix.time.clock_gettime(int, core.sys.posix.time.timespec*) nothrow @nogcclock_gettime, (alias constant) start_bench.CLOCK_MONOTONIC = int core.sys.posix.time.CLOCK_MONOTONIC = 1CLOCK_MONOTONIC, (struct) core.sys.posix.time.timespectimespec;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.unistdD header file for POSIX.
unistd : (alias) start_bench.fork = int core.sys.posix.unistd.fork() nothrow @nogc @trustedfork, (alias) start_bench.execve = int core.sys.posix.unistd.execve(scope const(char*), scope const(char**), scope const(char**)) nothrow @nogcexecve, (alias) start_bench._exit = noreturn core.sys.posix.unistd._exit(int) nothrow @nogc @trusted_exit;
extern(C) extern __gshared char** (__gshared global) char** start_bench.environenviron;
extern(C) int int start_bench.main(int argc, char** argv) nothrow @nogc @systemmain(int (parameter) int argcargc, char** (parameter) char** argvargv) @system nothrow @nogc
{
if ((parameter) int argcargc < 3 || int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogcstrcmp((parameter) char** argvargv[1], "--run") != 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("SKIP: pass --run PROGRAM [ARGS...] for an approved benchmark.\n");
return 0;
}
enum (constant) int start_bench.main.count = 1000count = 1000;
foreach ((local variable) int trialtrial; 0 .. 5)
{
(struct) core.sys.posix.time.timespectimespec (local variable) core.sys.posix.time.timespec startstart, (local variable) core.sys.posix.time.timespec endend;
if (int core.sys.posix.time.clock_gettime(int, core.sys.posix.time.timespec*) nothrow @nogcclock_gettime((constant) int core.sys.posix.time.CLOCK_MONOTONIC = 1CLOCK_MONOTONIC, &(local variable) core.sys.posix.time.timespec startstart) != 0)
return 1;
foreach ((local variable) int ii; 0 .. (constant) int start_bench.main.count = 1000count)
{
const (local variable) const(int) childchild = int core.sys.posix.unistd.fork() nothrow @nogc @trustedfork();
if ((local variable) const(int) childchild < 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("fork: errno=%d\n", int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno);
return 1;
}
if ((local variable) const(int) childchild == 0)
{
int core.sys.posix.unistd.execve(scope const(char*), scope const(char**), scope const(char**)) nothrow @nogcexecve((parameter) char** argvargv[2], cast(const(char)**) ((parameter) char** argvargv + 2), cast(const(char)**) (__gshared global) char** start_bench.environenviron);
noreturn core.sys.posix.unistd._exit(int) nothrow @nogc @trusted_exit(127);
}
int (local variable) int statusstatus;
int (local variable) int resultresult;
do
(local variable) int resultresult = int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogcwaitpid((local variable) const(int) childchild, &(local variable) int statusstatus, 0);
while ((local variable) int resultresult < 0 && int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno == int core.stdc.errno.__errno_location() nothrow @nogc ref @trustedEINTR);
if ((local variable) int resultresult != (local variable) const(int) childchild || (local variable) int statusstatus != 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("trial=%d iteration=%d wait=%d status=%d\n", (local variable) int trialtrial + 1, (local variable) int ii, (local variable) int resultresult, (local variable) int statusstatus);
return 1;
}
}
if (int core.sys.posix.time.clock_gettime(int, core.sys.posix.time.timespec*) nothrow @nogcclock_gettime((constant) int core.sys.posix.time.CLOCK_MONOTONIC = 1CLOCK_MONOTONIC, &(local variable) core.sys.posix.time.timespec endend) != 0)
return 1;
const (local variable) const(long) nsns = ((local variable) core.sys.posix.time.timespec endend.(field) long core.sys.posix.time.timespec.tv_sectv_sec - (local variable) core.sys.posix.time.timespec startstart.(field) long core.sys.posix.time.timespec.tv_sectv_sec) * 1_000_000_000L + (local variable) core.sys.posix.time.timespec endend.(field) long core.sys.posix.time.timespec.tv_nsectv_nsec - (local variable) core.sys.posix.time.timespec startstart.(field) long core.sys.posix.time.timespec.tv_nsectv_nsec;
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("trial=%d successful=%d elapsed-ns=%lld ns-per-start=%lld\n",
(local variable) int trialtrial + 1, (constant) int start_bench.main.count = 1000count, cast(long) (local variable) const(long) nsns, cast(long) ((local variable) const(long) nsns / (constant) int start_bench.main.count = 1000count));
int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trustedfflush(null);
}
return 0;
}