atrace: don't use sendfile.
sendfile appears to have horrendous performance when used with the
ftrace output file, being up to 100x slower than the naive read/write
loop.
Switch to doing that instead, speeding up atrace from:
$ atrace --async_start sched freq; sleep 1; time atrace --async_stop > dummy
c apturing trace... 0m08.93s real 0m00.08s user 0m07.98s system
to:
$ atrace --async_start sched freq; sleep 1; time atrace --async_stop > dummy
capturing trace... 0m00.78s real 0m00.07s user 0m00.21s system
Bug: http://b/37164190
Test: atrace --async_start sched freq; sleep 1; time atrace --async_stop > dummy
Change-Id: I22fe1871e263867f9ac54c8f5b474df824b4bc69
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp
index acf63c3..add5285 100644
--- a/cmds/atrace/atrace.cpp
+++ b/cmds/atrace/atrace.cpp
@@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/sendfile.h>
#include <time.h>
#include <unistd.h>
#include <zlib.h>
@@ -974,11 +973,16 @@
fprintf(stderr, "error cleaning up zlib: %d\n", result);
}
} else {
- ssize_t sent = 0;
- while ((sent = sendfile(outFd, traceFD, NULL, 64*1024*1024)) > 0);
- if (sent == -1) {
- fprintf(stderr, "error dumping trace: %s (%d)\n", strerror(errno),
- errno);
+ char buf[4096];
+ ssize_t rc;
+ while ((rc = TEMP_FAILURE_RETRY(read(traceFD, buf, sizeof(buf)))) > 0) {
+ if (!android::base::WriteFully(outFd, buf, rc)) {
+ fprintf(stderr, "error writing trace: %s\n", strerror(errno));
+ break;
+ }
+ }
+ if (rc == -1) {
+ fprintf(stderr, "error dumping trace: %s\n", strerror(errno));
}
}