summaryrefslogtreecommitdiffstats
path: root/core/jni/android_util_Binder.cpp
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-03-25 02:01:32 -0700
committerBrad Fitzpatrick <bradfitz@android.com>2010-03-25 02:01:32 -0700
commitad8fd282dde705ad090b2ecdc5b363df399230ab (patch)
tree572d26f8dd412f6de7cd2dba062cc7e89df17880 /core/jni/android_util_Binder.cpp
parent8f26b323d8f78c6a183e74c464864ef7da457267 (diff)
downloadframeworks_base-ad8fd282dde705ad090b2ecdc5b363df399230ab.zip
frameworks_base-ad8fd282dde705ad090b2ecdc5b363df399230ab.tar.gz
frameworks_base-ad8fd282dde705ad090b2ecdc5b363df399230ab.tar.bz2
Hopefully fix the sim-eng build, part 2.
This is kinda gross, but I can't find a good way to check for the existence of gettid(), except by finding its syscall number. Then might as well just use it rather than hope gettid's around, as it's not in sim-eng. Change-Id: Ieb7b39426dec08bd715b6fe1a9ab5b2801bdf775
Diffstat (limited to 'core/jni/android_util_Binder.cpp')
-rw-r--r--core/jni/android_util_Binder.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp
index 2fd68b8..901be58 100644
--- a/core/jni/android_util_Binder.cpp
+++ b/core/jni/android_util_Binder.cpp
@@ -21,9 +21,10 @@
#include "JNIHelp.h"
#include <fcntl.h>
+#include <stdio.h>
#include <sys/stat.h>
+#include <sys/syscall.h>
#include <sys/types.h>
-#include <stdio.h>
#include <unistd.h>
#include <utils/Atomic.h>
@@ -844,6 +845,19 @@ static void conditionally_log_binder_call(int64_t start_millis,
android_bWriteLog(LOGTAG_BINDER_OPERATION, buf, pos - buf);
}
+// We only measure binder call durations to potentially log them if
+// we're on the main thread. Unfortunately sim-eng doesn't seem to
+// have gettid, so we just ignore this and don't log if we can't
+// get the thread id.
+static bool should_time_binder_calls() {
+#ifdef __NR_gettid
+ return (getpid() == syscall(__NR_gettid));
+#else
+#warning no gettid(), so not logging Binder calls...
+ return false;
+#endif
+}
+
static jboolean android_os_BinderProxy_transact(JNIEnv* env, jobject obj,
jint code, jobject dataObj,
jobject replyObj, jint flags)
@@ -873,15 +887,17 @@ static jboolean android_os_BinderProxy_transact(JNIEnv* env, jobject obj,
target, obj, code);
// Only log the binder call duration for things on the Java-level main thread.
- const bool is_main_thread = (getpid() == gettid());
+ // But if we don't
+ const bool time_binder_calls = should_time_binder_calls();
+
int64_t start_millis;
- if (is_main_thread) {
+ if (time_binder_calls) {
start_millis = uptimeMillis();
}
//printf("Transact from Java code to %p sending: ", target); data->print();
status_t err = target->transact(code, *data, reply, flags);
//if (reply) printf("Transact from Java code to %p received: ", target); reply->print();
- if (is_main_thread) {
+ if (time_binder_calls) {
conditionally_log_binder_call(start_millis, target, code);
}