// Many native allocators have custom prefork and postfork functions. // Measure the fork call to make sure nothing takes too long. void BM_unistd_fork_call(benchmark::State& state) { for (auto _ : state) {
pid_t pid; if ((pid = fork()) == 0) { // Sleep for a little while so that the parent is not interrupted // right away when the process exits.
usleep(100);
_exit(1);
}
state.PauseTiming(); if (pid == -1) {
std::string err = android::base::StringPrintf("Fork failed: %m");
state.SkipWithError(err.c_str());
}
pid_t wait_pid = waitpid(pid, 0, 0); if (wait_pid != pid) { if (wait_pid == -1) {
std::string err = android::base::StringPrintf("waitpid call failed: %m");
state.SkipWithError(err.c_str());
} else {
std::string err = android::base::StringPrintf( "waitpid return an unknown pid, expected %d, actual %d", pid, wait_pid);
state.SkipWithError(err.c_str());
}
}
state.ResumeTiming();
}
}
BIONIC_BENCHMARK(BM_unistd_fork_call);
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.