1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Fix shutdown with TRACY_NO_EXIT=1 on Android. (#134)

This commit is contained in:
bjacob
2020-11-26 14:33:54 -05:00
committed by GitHub
parent 0073fd739f
commit dfdf70aea3
4 changed files with 106 additions and 67 deletions
+30 -3
View File
@@ -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
+18 -6
View File
@@ -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 );
}