Bug 734691 - Part 1: Rename Stack/Profile to imply their thread specific. r=mstange
☠☠ backed out by 801514b8c35f ☠ ☠
authorBenoit Girard <b56girard@gmail.com>
Sat, 10 Mar 2012 23:08:11 -0500
changeset 88727 a76566398d36a8768f4c397bb2e835cbedbfbded
parent 88726 5f8a4ddce90061fd2524435b40f0980009b5c336
child 88728 5f5fc6a1133e42289efc32e32de6068d44c7b003
push id6981
push userb56girard@gmail.com
push dateSun, 11 Mar 2012 15:39:38 +0000
treeherdermozilla-inbound@5f5fc6a1133e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs734691
milestone13.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 734691 - Part 1: Rename Stack/Profile to imply their thread specific. r=mstange
tools/profiler/TableTicker.cpp
tools/profiler/sps_sampler.h
--- a/tools/profiler/TableTicker.cpp
+++ b/tools/profiler/TableTicker.cpp
@@ -99,17 +99,17 @@ mozilla::tls::key pkey_ticker;
 // We need to track whether we've been initialized otherwise
 // we end up using pkey_stack without initializing it.
 // Because pkey_stack is totally opaque to us we can't reuse
 // it as the flag itself.
 bool stack_key_initialized;
 
 TimeStamp sLastTracerEvent;
 
-class Profile;
+class ThreadProfile;
 
 class ProfileEntry
 {
 public:
   ProfileEntry()
     : mTagData(NULL)
     , mLeafAddress(0)
     , mTagName(0)
@@ -136,44 +136,44 @@ public:
   { }
 
   ProfileEntry(char aTagName, uintptr_t aTagOffset)
     : mTagOffset(aTagOffset)
     , mLeafAddress(0)
     , mTagName(aTagName)
   { }
 
-  string TagToString(Profile *profile);
+  string TagToString(ThreadProfile *profile);
 
 private:
-  friend class Profile;
+  friend class ThreadProfile;
   union {
     const char* mTagData;
     double mTagFloat;
     Address mTagAddress;
     uintptr_t mTagOffset;
   };
   Address mLeafAddress;
   char mTagName;
 };
 
 #define PROFILE_MAX_ENTRY 100000
-class Profile
+class ThreadProfile
 {
 public:
-  Profile(int aEntrySize)
+  ThreadProfile(int aEntrySize)
     : mWritePos(0)
     , mLastFlushPos(0)
     , mReadPos(0)
     , mEntrySize(aEntrySize)
   {
     mEntries = new ProfileEntry[mEntrySize];
   }
 
-  ~Profile()
+  ~ThreadProfile()
   {
     delete[] mEntries;
   }
 
   void addTag(ProfileEntry aTag)
   {
     // Called from signal, call only reentrant functions
     mEntries[mWritePos] = aTag;
@@ -326,27 +326,27 @@ hasFeature(const char** aFeatures, uint3
     if (strcmp(aFeatures[i], aFeature) == 0)
       return true;
   }
   return false;
 }
 
 class TableTicker: public Sampler {
  public:
-  TableTicker(int aInterval, int aEntrySize, Stack *aStack,
+  TableTicker(int aInterval, int aEntrySize, ProfileStack *aStack,
               const char** aFeatures, uint32_t aFeatureCount)
     : Sampler(aInterval, true)
-    , mProfile(aEntrySize)
+    , mPrimaryThreadProfile(aEntrySize)
     , mStack(aStack)
     , mSaveRequested(false)
   {
     mUseStackWalk = hasFeature(aFeatures, aFeatureCount, "stackwalk");
     //XXX: It's probably worth splitting the jank profiler out from the regular profiler at some point
     mJankOnly = hasFeature(aFeatures, aFeatureCount, "jank");
-    mProfile.addTag(ProfileEntry('m', "Start"));
+    mPrimaryThreadProfile.addTag(ProfileEntry('m', "Start"));
   }
 
   ~TableTicker() { if (IsActive()) Stop(); }
 
   virtual void SampleStack(TickSample* sample) {}
 
   // Called within a signal. This function must be reentrant
   virtual void Tick(TickSample* sample);
@@ -354,33 +354,34 @@ class TableTicker: public Sampler {
   // Called within a signal. This function must be reentrant
   virtual void RequestSave()
   {
     mSaveRequested = true;
   }
 
   virtual void HandleSaveRequest();
 
-  Stack* GetStack()
+  ProfileStack* GetStack()
   {
     return mStack;
   }
 
-  Profile* GetProfile()
+  ThreadProfile* GetPrimaryThreadProfile()
   {
-    return &mProfile;
+    return &mPrimaryThreadProfile;
   }
 
 private:
   // Not implemented on platforms which do not support backtracing
-  void doBacktrace(Profile &aProfile, Address pc);
+  void doBacktrace(ThreadProfile &aProfile, Address pc);
 
 private:
-  Profile mProfile;
-  Stack *mStack;
+  // This represent the application's main thread (SAMPLER_INIT)
+  ThreadProfile mPrimaryThreadProfile;
+  ProfileStack *mStack;
   bool mSaveRequested;
   bool mUseStackWalk;
   bool mJankOnly;
 };
 
 /**
  * This is an event used to save the profile on the main thread
  * to be sure that it is not being modified while saving.
@@ -409,17 +410,17 @@ public:
       char tmp[MAXPATHLEN];
       ExpandEnvironmentStringsA(buff, tmp, mozilla::ArrayLength(tmp));
       strcpy(buff, tmp);
     }
 #endif
 
     FILE* stream = ::fopen(buff, "w");
     if (stream) {
-      t->GetProfile()->WriteProfile(stream);
+      t->GetPrimaryThreadProfile()->WriteProfile(stream);
       ::fclose(stream);
       LOG("Saved to " FOLDER "profile_TYPE_PID.txt");
     } else {
       LOG("Fail to open profile log file.");
     }
 
     return NS_OK;
   }
@@ -434,17 +435,17 @@ void TableTicker::HandleSaveRequest()
   // TODO: Use use the ipc/chromium Tasks here to support processes
   // without XPCOM.
   nsCOMPtr<nsIRunnable> runnable = new SaveProfileTask();
   NS_DispatchToMainThread(runnable);
 }
 
 
 #ifdef USE_BACKTRACE
-void TableTicker::doBacktrace(Profile &aProfile, Address pc)
+void TableTicker::doBacktrace(ThreadProfile &aProfile, Address pc)
 {
   void *array[100];
   int count = backtrace (array, 100);
 
   aProfile.addTag(ProfileEntry('s', "(root)", 0));
 
   for (int i = 0; i < count; i++) {
     if( (intptr_t)array[i] == -1 ) break;
@@ -467,17 +468,17 @@ void StackWalkCallback(void* aPC, void* 
   PCArray* array = static_cast<PCArray*>(aClosure);
   if (array->count >= array->size) {
     // too many frames, ignore
     return;
   }
   array->array[array->count++] = aPC;
 }
 
-void TableTicker::doBacktrace(Profile &aProfile, Address fp)
+void TableTicker::doBacktrace(ThreadProfile &aProfile, Address fp)
 {
 #ifndef XP_MACOSX
   uintptr_t thread = GetThreadHandle(platform_data());
   MOZ_ASSERT(thread);
 #endif
   void* pc_array[1000];
   PCArray array = {
     pc_array,
@@ -499,17 +500,17 @@ void TableTicker::doBacktrace(Profile &a
     for (size_t i = array.count; i > 0; --i) {
       aProfile.addTag(ProfileEntry('l', (const char*)array.array[i - 1]));
     }
   }
 }
 #endif
 
 static
-void doSampleStackTrace(Stack *aStack, Profile &aProfile, TickSample *sample)
+void doSampleStackTrace(ProfileStack *aStack, ThreadProfile &aProfile, TickSample *sample)
 {
   // Sample
   // 's' tag denotes the start of a sample block
   // followed by 0 or more 'c' tags.
   for (int i = 0; i < aStack->mStackPointer; i++) {
     if (i == 0) {
       Address pc = 0;
       if (sample) {
@@ -533,27 +534,27 @@ unsigned int sCurrentEventGeneration = 0
  * case of them being the same as special. i.e. we only run into
  * a problem if 2^32 events happen between samples that we need
  * to know are associated with different events */
 
 void TableTicker::Tick(TickSample* sample)
 {
   // Marker(s) come before the sample
   for (int i = 0; mStack->getMarker(i) != NULL; i++) {
-    mProfile.addTag(ProfileEntry('m', mStack->getMarker(i)));
+    mPrimaryThreadProfile.addTag(ProfileEntry('m', mStack->getMarker(i)));
   }
   mStack->mQueueClearMarker = true;
 
   // if we are on a different event we can discard any temporary samples
   // we've kept around
   if (sLastSampledEventGeneration != sCurrentEventGeneration) {
     // XXX: we also probably want to add an entry to the profile to help
     // distinguish which samples are part of the same event. That, or record
     // the event generation in each sample
-    mProfile.erase();
+    mPrimaryThreadProfile.erase();
   }
   sLastSampledEventGeneration = sCurrentEventGeneration;
 
   bool recordSample = true;
   if (mJankOnly) {
     recordSample = false;
     // only record the events when we have a we haven't seen a tracer event for 100ms
     if (!sLastTracerEvent.IsNull()) {
@@ -561,34 +562,34 @@ void TableTicker::Tick(TickSample* sampl
       if (delta.ToMilliseconds() > 100.0) {
           recordSample = true;
       }
     }
   }
 
 #if defined(USE_BACKTRACE) || defined(USE_NS_STACKWALK)
   if (mUseStackWalk) {
-    doBacktrace(mProfile, sample->fp);
+    doBacktrace(mPrimaryThreadProfile, sample->fp);
   } else {
-    doSampleStackTrace(mStack, mProfile, sample);
+    doSampleStackTrace(mStack, mPrimaryThreadProfile, sample);
   }
 #else
-  doSampleStackTrace(mStack, mProfile, sample);
+  doSampleStackTrace(mStack, mPrimaryThreadProfile, sample);
 #endif
 
   if (recordSample)
-    mProfile.flush();
+    mPrimaryThreadProfile.flush();
 
   if (!mJankOnly && !sLastTracerEvent.IsNull() && sample) {
     TimeDuration delta = sample->timestamp - sLastTracerEvent;
-    mProfile.addTag(ProfileEntry('r', delta.ToMilliseconds()));
+    mPrimaryThreadProfile.addTag(ProfileEntry('r', delta.ToMilliseconds()));
   }
 }
 
-string ProfileEntry::TagToString(Profile *profile)
+string ProfileEntry::TagToString(mPrimaryThreadProfile *profile)
 {
   string tag = "";
   if (mTagName == 'r') {
     char buff[50];
     snprintf(buff, 50, "%-40f", mTagFloat);
     tag += string(1, mTagName) + string("-") + string(buff) + string("\n");
   } else if (mTagName == 'l') {
     char tagBuff[1024];
@@ -620,17 +621,17 @@ void mozilla_sampler_init()
   // TODO linux port: Use TLS with ifdefs
   if (!mozilla::tls::create(&pkey_stack) ||
       !mozilla::tls::create(&pkey_ticker)) {
     LOG("Failed to init.");
     return;
   }
   stack_key_initialized = true;
 
-  Stack *stack = new Stack();
+  ProfileStack *stack = new ProfileStack();
   mozilla::tls::set(pkey_stack, stack);
 
   // We can't open pref so we use an environment variable
   // to know if we should trigger the profiler on startup
   // NOTE: Default
   const char *val = PR_GetEnv("MOZ_PROFILER_STARTUP");
   if (!val || !*val) {
     return;
@@ -664,31 +665,31 @@ void mozilla_sampler_save()
 char* mozilla_sampler_get_profile()
 {
   TableTicker *t = mozilla::tls::get<TableTicker>(pkey_ticker);
   if (!t) {
     return NULL;
   }
 
   StringBuilder profile;
-  t->GetProfile()->ToString(profile);
+  t->GetPrimaryThreadProfile()->ToString(profile);
 
   char *rtn = (char*)malloc( (profile.Length()+1) * sizeof(char) );
   strcpy(rtn, profile.Buffer());
   return rtn;
 }
 
 JSObject *mozilla_sampler_get_profile_data(JSContext *aCx)
 {
   TableTicker *t = mozilla::tls::get<TableTicker>(pkey_ticker);
   if (!t) {
     return NULL;
   }
 
-  return t->GetProfile()->ToJSObject(aCx);
+  return t->GetPrimaryThreadProfile()->ToJSObject(aCx);
 }
 
 
 const char** mozilla_sampler_get_features()
 {
   static const char* features[] = {
 #if defined(MOZ_PROFILING) && (defined(USE_BACKTRACE) || defined(USE_NS_STACKWALK))
     "stackwalk",
@@ -699,17 +700,17 @@ const char** mozilla_sampler_get_feature
 
   return features;
 }
 
 // Values are only honored on the first start
 void mozilla_sampler_start(int aProfileEntries, int aInterval,
                            const char** aFeatures, uint32_t aFeatureCount)
 {
-  Stack *stack = mozilla::tls::get<Stack>(pkey_stack);
+  ProfileStack *stack = mozilla::tls::get<ProfileStack>(pkey_stack);
   if (!stack) {
     ASSERT(false);
     return;
   }
 
   mozilla_sampler_stop();
 
   TableTicker *t = new TableTicker(aInterval, aProfileEntries, stack,
@@ -721,17 +722,17 @@ void mozilla_sampler_start(int aProfileE
 void mozilla_sampler_stop()
 {
   TableTicker *t = mozilla::tls::get<TableTicker>(pkey_ticker);
   if (!t) {
     return;
   }
 
   t->Stop();
-  mozilla::tls::set(pkey_ticker, (Stack*)NULL);
+  mozilla::tls::set(pkey_ticker, (ProfileStack*)NULL);
 }
 
 bool mozilla_sampler_is_active()
 {
   TableTicker *t = mozilla::tls::get<TableTicker>(pkey_ticker);
   if (!t) {
     return false;
   }
--- a/tools/profiler/sps_sampler.h
+++ b/tools/profiler/sps_sampler.h
@@ -160,20 +160,20 @@ public:
 private:
   void* mHandle;
 };
 
 } //mozilla
 
 // the SamplerStack members are read by signal
 // handlers, so the mutation of them needs to be signal-safe.
-struct Stack
+struct ProfileStack
 {
 public:
-  Stack()
+  ProfileStack()
     : mStackPointer(0)
     , mMarkerPointer(0)
     , mDroppedStackEntries(0)
     , mQueueClearMarker(false)
   { }
 
   void addMarker(const char *aMarker)
   {
@@ -251,17 +251,17 @@ public:
 
 inline void* mozilla_sampler_call_enter(const char *aInfo)
 {
   // check if we've been initialized to avoid calling pthread_getspecific
   // with a null pkey_stack which will return undefined results.
   if (!stack_key_initialized)
     return NULL;
 
-  Stack *stack = mozilla::tls::get<Stack>(pkey_stack);
+  ProfileStack *stack = mozilla::tls::get<ProfileStack>(pkey_stack);
   // we can't infer whether 'stack' has been initialized
   // based on the value of stack_key_intiailized because
   // 'stack' is only intialized when a thread is being
   // profiled.
   if (!stack) {
     return stack;
   }
   stack->push(aInfo);
@@ -274,21 +274,21 @@ inline void* mozilla_sampler_call_enter(
   return stack;
 }
 
 inline void mozilla_sampler_call_exit(void *aHandle)
 {
   if (!aHandle)
     return;
 
-  Stack *stack = (Stack*)aHandle;
+  ProfileStack *stack = (ProfileStack*)aHandle;
   stack->pop();
 }
 
 inline void mozilla_sampler_add_marker(const char *aMarker)
 {
-  Stack *stack = mozilla::tls::get<Stack>(pkey_stack);
+  ProfileStack *stack = mozilla::tls::get<ProfileStack>(pkey_stack);
   if (!stack) {
     return;
   }
   stack->addMarker(aMarker);
 }