diff options
author | Colin Cross <ccross@android.com> | 2014-08-21 00:41:24 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-20 12:26:29 +0000 |
commit | 61a4eecbe615bc94944161c4cf4aa590dfca1b2e (patch) | |
tree | 45a4e3375c0184b484cc95e5d3b2790a7bec46c5 | |
parent | 949ea0868de1df7e2f28a32d777cc41f901d6770 (diff) | |
parent | b1ce49b2ed9ea953a7f534b4f36b6acb56fc0749 (diff) | |
download | frameworks_native-61a4eecbe615bc94944161c4cf4aa590dfca1b2e.zip frameworks_native-61a4eecbe615bc94944161c4cf4aa590dfca1b2e.tar.gz frameworks_native-61a4eecbe615bc94944161c4cf4aa590dfca1b2e.tar.bz2 |
Merge "atrace: avoid unnecessary writes to trace_clock" into lmp-dev
-rw-r--r-- | cmds/atrace/atrace.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp index fb40193..9e5c910 100644 --- a/cmds/atrace/atrace.cpp +++ b/cmds/atrace/atrace.cpp @@ -341,11 +341,56 @@ static bool setTraceBufferSizeKB(int size) return writeStr(k_traceBufferSizePath, str); } +// Read the trace_clock sysfs file and return true if it matches the requested +// value. The trace_clock file format is: +// local [global] counter uptime perf +static bool isTraceClock(const char *mode) +{ + int fd = open(k_traceClockPath, O_RDONLY); + if (fd == -1) { + fprintf(stderr, "error opening %s: %s (%d)\n", k_traceClockPath, + 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_traceClockPath, + strerror(errno), errno); + return false; + } + buf[n] = '\0'; + + char *start = strchr(buf, '['); + if (start == NULL) { + return false; + } + start++; + + char *end = strchr(start, ']'); + if (end == NULL) { + return false; + } + *end = '\0'; + + return strcmp(mode, start) == 0; +} + // Enable or disable the kernel's use of the global clock. Disabling the global // clock will result in the kernel using a per-CPU local clock. +// Any write to the trace_clock sysfs file will reset the buffer, so only +// update it if the requested value is not the current value. static bool setGlobalClockEnable(bool enable) { - return writeStr(k_traceClockPath, enable ? "global" : "local"); + const char *clock = enable ? "global" : "local"; + + if (isTraceClock(clock)) { + return true; + } + + return writeStr(k_traceClockPath, clock); } static bool setPrintTgidEnableIfPresent(bool enable) |