b65f8e7605
* Update perfetto args.gn.in
- remove enable_perfetto_tools_trace_to_text (unused)
* core timeout implementation
- requires OMNITRACE_CI=ON
- requires OMNITRACE_CI_TIMEOUT=<sec>
- adds pthread_self and std::this_thread::get_id to thread info
- pthread_create_gotcha stores native handles (pthread_self)
* Testing updates
- improve detection of segfault/failures with PASS_REGEX exists
- add OMNITRACE_CI_TIMEOUT env variable to all tests
* Line-info in releases
- e.g. -g1 + more options to minimize size of debug info
* Fix typo in config exit action message
* OMNITRACE_UNLIKELY around debug/verbose messages
* format fixes
* Overflow tests + capability check
* transpose example update
- link to threads library
* roctracer/rocprofiler update
- in ROCm 5.5.0, cannot include rocprofiler.h and roctracer.h in same file due to conflicting enum defs
- Moved HSA tracing setup/shutdown to component::roctracer
* roctracer update
- fix definition of roctracer::setup when disabled
* Update fork example
- detach threads on main PID
- flush io outputs when printing info
* Update overflow tests
- pass regular expressions
- overflow on PERF_COUNT_SW_CPU_CLOCK event
* fork gotcha update
- use getpid() instead of getppid()
* update fork example
- wait on threads calling fork
* timeout update
- wait on timeout thread to launch before proceeding
[ROCm/rocprofiler-systems commit: 3e2fa69a14]
95 lines
2.2 KiB
C++
95 lines
2.2 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>
|
|
#include <vector>
|
|
|
|
void
|
|
print_info(const char* _name)
|
|
{
|
|
fflush(stdout);
|
|
fflush(stderr);
|
|
printf("[%s] pid = %i, ppid = %i\n", _name, getpid(), getppid());
|
|
fflush(stdout);
|
|
fflush(stderr);
|
|
}
|
|
|
|
int
|
|
run(const char* _name, int nchildren)
|
|
{
|
|
auto _threads = std::vector<std::thread>{};
|
|
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);
|
|
}
|
|
};
|
|
_threads.emplace_back(_run);
|
|
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");
|
|
}
|
|
}
|
|
|
|
for(auto& itr : _threads)
|
|
itr.join();
|
|
|
|
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);
|
|
}
|