Bug 1339695 (part 5) - Introduce PROFILE_JAVA. r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 15 Feb 2017 16:25:22 +1100
changeset 343217 6205142186156da59305508759cd08982e38ae1b
parent 343216 002e9c45f121f951f205cc3d3ec7fb563f5a831c
child 343218 eb3b5ef730656f41a31d5b537a83553337c4a549
push id31372
push usercbook@mozilla.com
push dateThu, 16 Feb 2017 12:16:10 +0000
treeherdermozilla-central@2737f66ad6ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1339695
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1339695 (part 5) - Introduce PROFILE_JAVA. r=mstange. This factors out some common preprocessor conditions.
tools/profiler/core/platform.cpp
tools/profiler/core/platform.h
tools/profiler/core/shared-libraries-linux.cc
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -39,22 +39,19 @@
 #include "mozilla/ProfileGatherer.h"
 #include "ProfilerMarkers.h"
 #include "shared-libraries.h"
 
 #ifdef MOZ_TASK_TRACER
 #include "GeckoTaskTracer.h"
 #endif
 
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
-  #include "FennecJNIWrappers.h"
-#endif
-
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
-#include "FennecJNINatives.h"
+#if defined(PROFILE_JAVA)
+# include "FennecJNINatives.h"
+# include "FennecJNIWrappers.h"
 #endif
 
 #if defined(MOZ_PROFILING) && (defined(XP_MACOSX) || defined(XP_WIN))
 # define USE_NS_STACKWALK
 #endif
 
 // This should also work on ARM Linux, but not tested there yet.
 #if defined(__arm__) && defined(ANDROID)
@@ -78,17 +75,17 @@
 typedef CONTEXT tickcontext_t;
 #elif defined(LINUX)
 #include <ucontext.h>
 typedef ucontext_t tickcontext_t;
 #endif
 
 using namespace mozilla;
 
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
+#if defined(PROFILE_JAVA)
 class GeckoJavaSampler : public mozilla::java::GeckoJavaSampler::Natives<GeckoJavaSampler>
 {
 private:
   GeckoJavaSampler();
 
 public:
   static double GetProfilerTime() {
     if (!profiler_is_active()) {
@@ -1071,17 +1068,17 @@ SubProcessCallback(const char* aProfile,
 {
   // Called by the observer to get their profile data included as a sub profile.
   SubprocessClosure* closure = (SubprocessClosure*)aClosure;
 
   // Add the string profile into the profile.
   closure->mWriter->StringElement(aProfile);
 }
 
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
+#if defined(PROFILE_JAVA)
 static void
 BuildJavaThreadJSObject(SpliceableJSONWriter& aWriter)
 {
   aWriter.StringProperty("name", "Java Main Thread");
 
   aWriter.StartArrayProperty("samples");
   {
     for (int sampleId = 0; true; sampleId++) {
@@ -1188,17 +1185,17 @@ StreamJSON(SpliceableJSONWriter& aWriter
           mozilla::services::GetObserverService();
         if (os) {
           RefPtr<ProfileSaveEvent> pse =
             new ProfileSaveEvent(SubProcessCallback, &closure);
           os->NotifyObservers(pse, "profiler-subprocess", nullptr);
         }
       }
 
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
+#if defined(PROFILE_JAVA)
       if (gProfileJava) {
         java::GeckoJavaSampler::Pause();
 
         aWriter.Start();
         {
           BuildJavaThreadJSObject(aWriter);
         }
         aWriter.End();
@@ -1664,17 +1661,17 @@ profiler_init(void* stackTop)
   // threshhold from MOZ_PROFILER_STACK_SCAN.
   read_profiler_env_vars();
 
   // platform specific initialization
   OS::Startup();
 
   set_stderr_callback(profiler_log);
 
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
+#if defined(PROFILE_JAVA)
   if (mozilla::jni::IsFennec()) {
     GeckoJavaSampler::Init();
   }
 #endif
 
   // We can't open pref so we use an environment variable
   // to know if we should trigger the profiler on startup
   // NOTE: Default
@@ -1686,17 +1683,17 @@ profiler_init(void* stackTop)
   const char* features[] = {"js"
                          , "leaf"
                          , "threads"
 #if defined(XP_WIN) || defined(XP_MACOSX) \
     || (defined(SPS_ARCH_arm) && defined(linux)) \
     || defined(SPS_PLAT_amd64_linux) || defined(SPS_PLAT_x86_linux)
                          , "stackwalk"
 #endif
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
+#if defined(PROFILE_JAVA)
                          , "java"
 #endif
                          };
 
   const char* threadFilters[] = { "GeckoMain", "Compositor" };
 
   profiler_start(PROFILE_DEFAULT_ENTRY, PROFILE_DEFAULT_INTERVAL,
                          features, MOZ_ARRAY_LENGTH(features),
@@ -2039,21 +2036,19 @@ profiler_start(int aProfileEntries, doub
   }
 #endif
 
   gGatherer = new mozilla::ProfileGatherer(gSampler);
 
   bool mainThreadIO = hasFeature(aFeatures, aFeatureCount, "mainthreadio");
   bool privacyMode  = hasFeature(aFeatures, aFeatureCount, "privacy");
 
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
+#if defined(PROFILE_JAVA)
   gProfileJava = mozilla::jni::IsFennec() &&
                       hasFeature(aFeatures, aFeatureCount, "java");
-#else
-  gProfileJava = false;
 #endif
   gProfileJS   = hasFeature(aFeatures, aFeatureCount, "js");
   gTaskTracer  = hasFeature(aFeatures, aFeatureCount, "tasktracer");
 
   gAddLeafAddresses = hasFeature(aFeatures, aFeatureCount, "leaf");
   gDisplayListDump  = hasFeature(aFeatures, aFeatureCount, "displaylistdump");
   gLayersDump       = hasFeature(aFeatures, aFeatureCount, "layersdump");
   gProfileGPU       = hasFeature(aFeatures, aFeatureCount, "gpu");
@@ -2082,17 +2077,17 @@ profiler_start(int aProfileEntries, doub
         info->Stack()->enableJSSampling();
       }
       if (privacyMode) {
         info->Stack()->mPrivacyMode = true;
       }
     }
   }
 
-#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
+#if defined(PROFILE_JAVA)
   if (gProfileJava) {
     int javaInterval = aInterval;
     // Java sampling doesn't accuratly keep up with 1ms sampling
     if (javaInterval < 10) {
       aInterval = 10;
     }
     mozilla::java::GeckoJavaSampler::Start(javaInterval, 1000);
   }
--- a/tools/profiler/core/platform.h
+++ b/tools/profiler/core/platform.h
@@ -100,16 +100,20 @@ bool profiler_verbose();
     } while (0)
 
 #endif
 
 #if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_LINUX)
 #define ENABLE_LEAF_DATA
 #endif
 
+#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
+#define PROFILE_JAVA
+#endif
+
 extern mozilla::TimeStamp gStartTime;
 
 typedef uint8_t* Address;
 
 // ----------------------------------------------------------------------------
 // OS
 //
 // This class has static methods for the different platform specific
--- a/tools/profiler/core/shared-libraries-linux.cc
+++ b/tools/profiler/core/shared-libraries-linux.cc
@@ -127,21 +127,22 @@ SharedLibraryInfo SharedLibraryInfo::Get
     if (!strchr(perm, 'x')) {
       // Ignore non executable entries
       continue;
     }
     if (ret != 5 && ret != 4) {
       LOG("Get maps line failed");
       continue;
     }
-#if defined(ANDROID) && !defined(MOZ_WIDGET_GONK)
+#if defined(PROFILE_JAVA)
     // Use proc/pid/maps to get the dalvik-jit section since it has
     // no associated phdrs
-    if (strcmp(name, "/dev/ashmem/dalvik-jit-code-cache") != 0)
+    if (strcmp(name, "/dev/ashmem/dalvik-jit-code-cache") != 0) {
       continue;
+    }
 #else
     if (strcmp(perm, "r-xp") != 0) {
       // Ignore entries that are writable and/or shared.
       // At least one graphics driver uses short-lived "rwxs" mappings
       // (see bug 926734 comment 5), so just checking for 'x' isn't enough.
       continue;
     }
 #endif