diff options
author | bjacob <benoitjacob@google.com> | 2020-11-26 22:33:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-26 22:33:54 +0300 |
commit | dfdf70aea35efb5b8aafc47025d1b1bce04ea9f4 (patch) | |
tree | 925c171bffd50e06cb0a8b79e27217e4cf0ea934 /extra | |
parent | 0073fd739f6054107667fa1496bda5bd69921c49 (diff) |
Fix shutdown with TRACY_NO_EXIT=1 on Android. (#134)
Diffstat (limited to 'extra')
-rwxr-xr-x | extra/systrace/build.sh | 33 | ||||
-rw-r--r-- | extra/systrace/tracy_systrace.c | 24 |
2 files changed, 48 insertions, 9 deletions
diff --git a/extra/systrace/build.sh b/extra/systrace/build.sh index 8d6b7a8e..1da097a9 100755 --- a/extra/systrace/build.sh +++ b/extra/systrace/build.sh @@ -1,4 +1,31 @@ #!/bin/sh -clang tracy_systrace.c -s -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-stack-protector -Wl,-z,norelro -Wl,--build-id=none -nostdlib -ldl -o tracy_systrace -strip --strip-all -R .note.gnu.gold-version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag -R .eh_frame -R .eh_frame_hdr -R .gnu.hash -R .gnu.version -R .got tracy_systrace -sstrip -z tracy_systrace + +# These may be passed as environment variables, or will use the following defaults. +: ${CC:=clang} +: ${STRIP:=strip} +: ${SSTRIP:=sstrip} + +if [ ! -x "$(command -v "${CC}")" ] +then + echo "Set the CC environment variable to a C compiler." + exit 1 +fi + +if [ ! -x "$(command -v "${STRIP}")" ] +then + echo "Set the STRIP environment variable to the strip utility." + exit 1 +fi + +if [ ! -x "$(command -v "${SSTRIP}")" ] +then + echo "Set the SSTRIP environment variable to the sstrip utility, which can be obtained from https://github.com/BR903/ELFkickers ." + exit 1 +fi + +$CC tracy_systrace.c -s -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-stack-protector -Wl,-z,norelro -Wl,--build-id=none -nostdlib -ldl -o tracy_systrace + +$STRIP --strip-all -R .note.gnu.gold-version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag -R .eh_frame -R .eh_frame_hdr -R .gnu.version -R .got tracy_systrace + +$SSTRIP -z tracy_systrace + diff --git a/extra/systrace/tracy_systrace.c b/extra/systrace/tracy_systrace.c index 530f05f5..58fcbfe8 100644 --- a/extra/systrace/tracy_systrace.c +++ b/extra/systrace/tracy_systrace.c @@ -33,18 +33,30 @@ void _start() int kernelFd = sym_open( "/sys/kernel/debug/tracing/trace_pipe", O_RDONLY ); if( kernelFd < 0 ) sym_exit( 0 ); - struct pollfd pfd; - pfd.fd = kernelFd; - pfd.events = POLLIN | POLLERR; + struct pollfd pfd_in; + pfd_in.fd = kernelFd; + pfd_in.events = POLLIN | POLLERR; + + struct pollfd pfd_out; + pfd_out.fd = STDOUT_FILENO; + pfd_out.events = POLLERR; struct timespec sleepTime; sleepTime.tv_sec = 0; sleepTime.tv_nsec = 1000 * 1000 * 10; - for(;;) + // While the pipe is open (no POLLERR on the output fd) + while( sym_poll( &pfd_out, 1, 0) <= 0 ) { - while( sym_poll( &pfd, 1, 0 ) <= 0 ) sym_nanosleep( &sleepTime, NULL ); - const int rd = sym_read( kernelFd, buf, BufSize ); + // If there is neither data (POLLIN) nor an error (POLLERR) on + // the read fd, sleep. This implements a blocking read without relying + // on the Linux kernel's implementation of blocking reads which causes + // a large number of context switches. + if( sym_poll( &pfd_in, 1, 0 ) <= 0 ) { + sym_nanosleep( &sleepTime, NULL ); + continue; // go back to the while condition polling the output fd + } + const ssize_t rd = sym_read( kernelFd, buf, BufSize ); if( rd <= 0 ) break; sym_write( STDOUT_FILENO, buf, rd ); } |