Add RS watchdog.

Change-Id: I4c912beb84fa8a37ada0088049f7776132e994b6
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index e3a9cf8..948d51c 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -86,7 +86,9 @@
 uint32_t Context::runRootScript() {
     timerSet(RS_TIMER_SCRIPT);
     mStateFragmentStore.mLast.clear();
+    watchdog.inRoot = true;
     uint32_t ret = runScript(mRootScript.get());
+    watchdog.inRoot = false;
 
     return ret;
 }
@@ -317,6 +319,13 @@
     mExit = true;
 }
 
+void Context::printWatchdogInfo(void *ctx) {
+    Context *rsc = (Context *)ctx;
+    LOGE("RS watchdog timeout: %i  %s  line %i %s", rsc->watchdog.inRoot,
+         rsc->watchdog.command, rsc->watchdog.line, rsc->watchdog.file);
+}
+
+
 void Context::setPriority(int32_t p) {
     // Note: If we put this in the proper "background" policy
     // the wallpapers can become completly unresponsive at times.
@@ -368,6 +377,7 @@
     pthread_mutex_lock(&gInitMutex);
 
     mIO.init();
+    mIO.setTimoutCallback(printWatchdogInfo, this, 2e9);
 
     dev->addContext(this);
     mDev = dev;