Bug 711491. Switch profile export to StringBuilder.
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Fri, 16 Dec 2011 09:03:54 -0500
changeset 84750 c0f11bea9cff4d881250c4441ff10f9beefbecca
parent 84749 b22cb97847a74fc9a6af0c337e78d388b852aa7b
child 84751 8f6dbb41479e0824b039ae01f8004b87040319b9
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs711491
milestone12.0a1
Bug 711491. Switch profile export to StringBuilder. This should help performance some.
tools/profiler/sps/TableTicker.cpp
--- a/tools/profiler/sps/TableTicker.cpp
+++ b/tools/profiler/sps/TableTicker.cpp
@@ -39,18 +39,20 @@
 #include <string>
 #include <stdio.h>
 #include "sps_sampler.h"
 #include "platform.h"
 #include "nsXULAppAPI.h"
 #include "nsThreadUtils.h"
 #include "prenv.h"
 #include "shared-libraries.h"
+#include "mozilla/StringBuilder.h"
 
 using std::string;
+using namespace mozilla;
 
 #ifdef XP_WIN
 #include <windows.h>
 #define getpid GetCurrentProcessId
 #else
 #include <unistd.h>
 #endif
 
@@ -153,28 +155,27 @@ public:
     mWritePos = (mWritePos + 1) % mEntrySize;
     if (mWritePos == mReadPos) {
       // Keep one slot open
       mEntries[mReadPos] = ProfileEntry();
       mReadPos = (mReadPos + 1) % mEntrySize;
     }
   }
 
-  void ToString(string* profile)
+  void ToString(StringBuilder &profile)
   {
     if (mNeedsSharedLibraryInfo) {
       // Can't be called from signal because
       // getting the shared library information can call non-reentrant functions.
       mSharedLibraryInfo = SharedLibraryInfo::GetInfoForSelf();
     }
 
-    *profile = "";
     int oldReadPos = mReadPos;
     while (mReadPos != mWritePos) {
-      *profile += mEntries[mReadPos].TagToString(this);
+      profile.Append(mEntries[mReadPos].TagToString(this).c_str());
       mReadPos = (mReadPos + 1) % mEntrySize;
     }
     mReadPos = oldReadPos;
   }
 
   void WriteProfile(FILE* stream)
   {
     if (mNeedsSharedLibraryInfo) {
@@ -451,21 +452,21 @@ void mozilla_sampler_save() {
 }
 
 char* mozilla_sampler_get_profile() {
   TableTicker *t = mozilla::tls::get<TableTicker>(pkey_ticker);
   if (!t) {
     return NULL;
   }
 
-  string profile;
-  t->GetProfile()->ToString(&profile);
+  StringBuilder profile;
+  t->GetProfile()->ToString(profile);
 
-  char *rtn = (char*)malloc( (strlen(profile.c_str())+1) * sizeof(char) );
-  strcpy(rtn, profile.c_str());
+  char *rtn = (char*)malloc( (profile.Length()+1) * sizeof(char) );
+  strcpy(rtn, profile.Buffer());
   return rtn;
 }
 
 // Values are only honored on the first start
 void mozilla_sampler_start(int aProfileEntries, int aInterval)
 {
   Stack *stack = mozilla::tls::get<Stack>(pkey_stack);
   if (!stack) {