Add the name of the forEach functions to the tracing output

Instead of showing up as 'runForEach', kernels are now e.g. printed as
'runForEach_createAntLookup'.

The String8 is carefully constructed here, such that we only pay
the string processing overhead in case tracing is actually enabled.

Change-Id: Id18319e271a02cbe888bcb9fe806794007d00fca
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 4ba60d3..6f605c2 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -493,6 +493,7 @@
     // Copy info over to runtime
     script->mHal.info.exportedFunctionCount = info->getExportFuncNames().size();
     script->mHal.info.exportedVariableCount = info->getExportVarNames().size();
+    script->mHal.info.exportedForeachFuncList = info->getExportForeachFuncs().array();
     script->mHal.info.exportedPragmaCount = info->getPragmas().size();
     script->mHal.info.exportedPragmaKeyList =
         const_cast<const char**>(mExecutable->getPragmaKeys().array());
diff --git a/rsScript.h b/rsScript.h
index a1360b5..c868aaa 100644
--- a/rsScript.h
+++ b/rsScript.h
@@ -19,6 +19,7 @@
 
 #include "rsAllocation.h"
 
+#include <utility>
 
 // ---------------------------------------------------------------------------
 namespace android {
@@ -72,6 +73,7 @@
             size_t exportedPragmaCount;
             char const **exportedPragmaKeyList;
             char const **exportedPragmaValueList;
+            const std::pair<const char *, uint32_t> *exportedForeachFuncList;
 
             int (* root)();
         };
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 3d9cd11..632dca8 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -29,6 +29,8 @@
 #include "utils/StopWatch.h"
 #endif
 
+#include "cutils/trace.h"
+
 #include <sys/stat.h>
 
 using namespace android;
@@ -167,14 +169,27 @@
                          const void * usr,
                          size_t usrBytes,
                          const RsScriptCall *sc) {
-
-    ATRACE_CALL();
+    // Trace this function call.
+    // To avoid overhead, we only build the string, if tracing is actually
+    // enabled.
+    String8 *AString = NULL;
+    const char *String = "";
+    if (ATRACE_ENABLED()) {
+        AString = new String8("runForEach_");
+        AString->append(mHal.info.exportedForeachFuncList[slot].first);
+        String = AString->string();
+    }
+    ATRACE_NAME(String);
+    (void)String;
 
     Context::PushState ps(rsc);
 
     setupGLState(rsc);
     setupScript(rsc);
     rsc->mHal.funcs.script.invokeForEach(rsc, this, slot, ain, aout, usr, usrBytes, sc);
+
+    if (AString)
+        delete AString;
 }
 
 void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {