846301bcaf
* Address and thread sanitizer fixes - Fix compilation with clang - Tweak perfetto copy to build tree - Added suppression files to scripts - fix LD_PRELOAD support in omnitrace-causal and omnitrace-sample - use spin_mutex and spin_lock from timemory instead of atomic_mutex and atomic_lock - state uses atomic - fix some memory leaks - tweak testing - mpi tests do not use preload - increase timeout when using sanitizers - add env LD_PRELOAD when using sanitizers * Tweak perfetto build * Update timemory submodule * Update version to 1.8.1 * Update omnitrace-leak.supp * Update timemory submodule - fixed spin_mutex implementation * Remove previously added addr_space->allowTraps(instr_traps) - this appears to cause errors during binary rewrite * causal testing updates - relaxed causal validation on CI systems (to account for hyperthreading decreasing prediction) - improved impact calculation - other general improvements to validate-causal-json.py * Improve fork handling for perfetto - numerous updates changing perfetto:: to ::perfetto:: - added perfetto_fwd.hpp * Updated fork example - user API for validation that stopping/starting perfetto is valid * Misc fixes to perfetto + fork support - tweak regions in fork example - handle disabling tmp files - get rid of stop/start with perfetto before/after fork - fixed sampling support during fork - tweak env of fork test * Fix find_package in build-tree * Fix buildtree export * Fix buildtree export * Restructured ConfigInstall before adding examples * Guard against creating tmp file in sampling when disabled * Fix buildtree package * formatting * exit handlers on child processes - quick exit to avoid perfetto cleanup * Further tweaking of causal tests for reliability - enable PROCESSOR_AFFINITY - decrease to 5 iterations * Further tweaking of causal tests for reliability - disable PROCESSOR_AFFINITY for fast func e2e tests - enabling affinity results in (valid) speedup predictions greater than zero * Fixes to fork handling - use pthread_atfork for redundancy if fork_gotcha fails * cmake formatting * Fix fork init settings + install components - remove dl from PROJECT_BUILD_TARGETS * Testing tweaks - fix mpi-binary-rewrite-run regex when OMNITRACE_VERBOSE set > 1 in env - increase causal e2e iterations to 8 * Fix "Test User API" - test-find-package.sh included dl component * Further tweaks to causal validation - further considerations of variance
86 righe
2.0 KiB
C++
86 righe
2.0 KiB
C++
|
|
#include <omnitrace/user.h>
|
|
|
|
#include <chrono>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <string>
|
|
#include <sys/wait.h>
|
|
#include <thread>
|
|
#include <unistd.h>
|
|
|
|
void
|
|
print_info(const char* _name)
|
|
{
|
|
printf("[%s] pid = %i, ppid = %i\n", _name, getpid(), getppid());
|
|
}
|
|
|
|
int
|
|
run(const char* _name, int nchildren)
|
|
{
|
|
for(int i = 0; i < nchildren; ++i)
|
|
{
|
|
omnitrace_user_push_region("launch_child");
|
|
auto _run = [i, _name]() {
|
|
pid_t _pid = fork();
|
|
if(_pid == 0)
|
|
{
|
|
// child code
|
|
print_info(_name);
|
|
auto _sleep = [=]() {
|
|
std::this_thread::sleep_for(std::chrono::seconds{ i + 1 });
|
|
};
|
|
std::thread{ _sleep }.join();
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
};
|
|
std::thread{ _run }.join();
|
|
omnitrace_user_pop_region("launch_child");
|
|
}
|
|
|
|
omnitrace_user_push_region("wait_for_children");
|
|
|
|
int _status = 0;
|
|
pid_t _wait_pid = 0;
|
|
// parent waits for all the child processes
|
|
while((_wait_pid = wait(&_status)) > 0)
|
|
{
|
|
printf("[%s][%i] returned from wait with pid = %i :: ", _name, getpid(),
|
|
_wait_pid);
|
|
if(WIFEXITED(_status))
|
|
{
|
|
printf("exited, status=%d\n", WEXITSTATUS(_status));
|
|
}
|
|
else if(WIFSIGNALED(_status))
|
|
{
|
|
printf("killed by signal %d\n", WTERMSIG(_status));
|
|
}
|
|
else if(WIFSTOPPED(_status))
|
|
{
|
|
printf("stopped by signal %d\n", WSTOPSIG(_status));
|
|
}
|
|
else if(WIFCONTINUED(_status))
|
|
{
|
|
printf("continued\n");
|
|
}
|
|
else
|
|
{
|
|
printf("unknown\n");
|
|
}
|
|
}
|
|
|
|
omnitrace_user_pop_region("wait_for_children");
|
|
return _status;
|
|
}
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
int _n = 4;
|
|
if(argc > 1) _n = std::stoi(argv[1]);
|
|
|
|
print_info(argv[0]);
|
|
return run(argv[0], _n);
|
|
}
|