Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8419c29 authored by Stephane Gasparini's avatar Stephane Gasparini Committed by Zhiquan Liu
Browse files

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: default avatarStephane Gasparini <stephane.gasparini@intel.com>
Change-Id: Ic24a9267053302a03ff04c8b2afeb143e5b94c84
Signed-off-by: default avatarZhiquan Liu <zhiquan.liu@intel.com>
parent 33dcaf9b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ LOCAL_SHARED_LIBRARIES := \
    libcutils \
    libutils \
    libz \
    libbase

LOCAL_INIT_RC := atrace.rc

+6 −16
Original line number Diff line number Diff line
@@ -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 @@ static bool disableKernelTraceEvents() {
// kernel.
static bool verifyKernelTraceFuncs(const char* funcs)
{
    int fd = open(k_ftraceFilterPath, O_RDONLY);
    if (fd == -1) {
    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;
    }

    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 @@ static bool verifyKernelTraceFuncs(const char* funcs)
        func = strtok(NULL, ",");
    }
    free(myFuncs);

    return ok;
}