Atrace:use ReadFileToString to read file
Since wildcard support was added to atrace, it can happen
very easily that file size is large than 4096
resulting in bad status that atrace cannot find kernel function
This patch use android::base::ReadFileToString to read file
which doesn't have size limitation.
Signed-off-by: Stephane Gasparini <stephane.gasparini@intel.com>
Change-Id: Ic24a9267053302a03ff04c8b2afeb143e5b94c84
Signed-off-by: Zhiquan Liu <zhiquan.liu@intel.com>
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp
index 6549dde..d99b6fe 100644
--- a/cmds/atrace/atrace.cpp
+++ b/cmds/atrace/atrace.cpp
@@ -39,6 +39,7 @@
#include <utils/Timers.h>
#include <utils/Tokenizer.h>
#include <utils/Trace.h>
+#include <android-base/file.h>
using namespace android;
@@ -525,24 +526,14 @@
// kernel.
static bool verifyKernelTraceFuncs(const char* funcs)
{
- int fd = open(k_ftraceFilterPath, O_RDONLY);
- if (fd == -1) {
- fprintf(stderr, "error opening %s: %s (%d)\n", k_ftraceFilterPath,
+ std::string buf;
+ if (!android::base::ReadFileToString(k_ftraceFilterPath, &buf)) {
+ fprintf(stderr, "error opening %s: %s (%d)\n", k_ftraceFilterPath,
strerror(errno), errno);
- return false;
+ return false;
}
- char buf[4097];
- ssize_t n = read(fd, buf, 4096);
- close(fd);
- if (n == -1) {
- fprintf(stderr, "error reading %s: %s (%d)\n", k_ftraceFilterPath,
- strerror(errno), errno);
- return false;
- }
-
- buf[n] = '\0';
- String8 funcList = String8::format("\n%s", buf);
+ String8 funcList = String8::format("\n%s",buf.c_str());
// Make sure that every function listed in funcs is in the list we just
// read from the kernel, except for wildcard inputs.
@@ -562,7 +553,6 @@
func = strtok(NULL, ",");
}
free(myFuncs);
-
return ok;
}