mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 06:34:36 +00:00
Helper for reading data from kernel more efficiently.
This commit is contained in:
parent
c09f3c0676
commit
6f5dd44f1f
36
extra/systrace/tracy_systrace.c
Normal file
36
extra/systrace/tracy_systrace.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
enum { BufSize = 64*1024 };
|
||||
|
||||
int main()
|
||||
{
|
||||
char buf[BufSize];
|
||||
|
||||
int kernelFd = open( "/sys/kernel/debug/tracing/trace_pipe", O_RDONLY );
|
||||
if( kernelFd == -1 ) return -1;
|
||||
|
||||
struct pollfd pfd;
|
||||
pfd.fd = kernelFd;
|
||||
pfd.events = POLLIN | POLLERR;
|
||||
|
||||
struct timespec sleepTime;
|
||||
sleepTime.tv_sec = 0;
|
||||
sleepTime.tv_nsec = 1000 * 1000 * 10;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
while( poll( &pfd, 1, 0 ) <= 0 ) nanosleep( &sleepTime, NULL );
|
||||
const int rd = read( kernelFd, buf, BufSize );
|
||||
if( rd <= 0 ) break;
|
||||
write( STDOUT_FILENO, buf, rd );
|
||||
}
|
||||
|
||||
close( kernelFd );
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user