Bug 1167230 - Use nsCString instead of std::string in FrameKey in the profiler, a=sledru
authorShu-yu Guo <shu@rfrn.org>
Wed, 27 May 2015 20:46:00 -0700
changeset 274886 b104a8b24b279a8dbb44fdc7a8d21e17375af8d6
parent 274885 087c3f171562534ce7a4d55dcfce7bf2d567e32a
child 274887 5411dd3b6f670948d085fd13b1f909fe3b9c612b
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssledru
bugs1167230
milestone40.0a2
Bug 1167230 - Use nsCString instead of std::string in FrameKey in the profiler, a=sledru
tools/profiler/ProfileEntry.cpp
tools/profiler/ProfileEntry.h
--- a/tools/profiler/ProfileEntry.cpp
+++ b/tools/profiler/ProfileEntry.cpp
@@ -393,17 +393,20 @@ void UniqueStacks::Stack::AppendFrame(co
 
 uint32_t UniqueStacks::Stack::GetOrAddIndex() const
 {
   return mUniqueStacks.GetOrAddStackIndex(mStack);
 }
 
 uint32_t UniqueStacks::FrameKey::Hash() const
 {
-  uint32_t hash = mozilla::HashString(mLocation.c_str(), mLocation.length());
+  uint32_t hash = 0;
+  if (!mLocation.IsEmpty()) {
+    hash = mozilla::HashString(mLocation.get());
+  }
   if (mLine.isSome()) {
     hash = mozilla::AddToHash(hash, *mLine);
   }
   if (mCategory.isSome()) {
     hash = mozilla::AddToHash(hash, *mCategory);
   }
   if (mJITAddress.isSome()) {
     hash = mozilla::AddToHash(hash, *mJITAddress);
@@ -526,17 +529,17 @@ void UniqueStacks::StreamStack(const Sta
 
 void UniqueStacks::StreamFrame(const OnStackFrameKey& aFrame)
 {
   // Schema:
   //   [location, implementation, optimizations, line, category]
 
   mFrameTableWriter.StartArrayElement();
   if (!aFrame.mJITFrameHandle) {
-    mUniqueStrings.WriteElement(mFrameTableWriter, aFrame.mLocation.c_str());
+    mUniqueStrings.WriteElement(mFrameTableWriter, aFrame.mLocation.get());
     if (aFrame.mLine.isSome()) {
       mFrameTableWriter.NullElement(); // implementation
       mFrameTableWriter.NullElement(); // optimizations
       mFrameTableWriter.IntElement(*aFrame.mLine);
     }
     if (aFrame.mCategory.isSome()) {
       if (aFrame.mLine.isNothing()) {
         mFrameTableWriter.NullElement(); // line
--- a/tools/profiler/ProfileEntry.h
+++ b/tools/profiler/ProfileEntry.h
@@ -106,26 +106,34 @@ private:
   SpliceableChunkedJSONWriter mStringTableWriter;
   nsDataHashtable<nsCharPtrHashKey, uint32_t> mStringToIndexMap;
 };
 
 class UniqueStacks
 {
 public:
   struct FrameKey {
-    std::string mLocation;
+    nsCString mLocation;
     mozilla::Maybe<unsigned> mLine;
     mozilla::Maybe<unsigned> mCategory;
     mozilla::Maybe<void*> mJITAddress;
     mozilla::Maybe<uint32_t> mJITDepth;
 
     explicit FrameKey(const char* aLocation)
      : mLocation(aLocation)
     { }
 
+    FrameKey(const FrameKey& aToCopy)
+     : mLocation(aToCopy.mLocation)
+     , mLine(aToCopy.mLine)
+     , mCategory(aToCopy.mCategory)
+     , mJITAddress(aToCopy.mJITAddress)
+     , mJITDepth(aToCopy.mJITDepth)
+    { }
+
     FrameKey(void* aJITAddress, uint32_t aJITDepth)
      : mJITAddress(mozilla::Some(aJITAddress))
      , mJITDepth(mozilla::Some(aJITDepth))
     { }
 
     uint32_t Hash() const;
     bool operator==(const FrameKey& aOther) const;
   };
@@ -134,16 +142,21 @@ public:
   struct MOZ_STACK_CLASS OnStackFrameKey : public FrameKey {
     const JS::ForEachProfiledFrameOp::FrameHandle* mJITFrameHandle;
 
     explicit OnStackFrameKey(const char* aLocation)
       : FrameKey(aLocation)
       , mJITFrameHandle(nullptr)
     { }
 
+    OnStackFrameKey(const OnStackFrameKey& aToCopy)
+      : FrameKey(aToCopy)
+      , mJITFrameHandle(aToCopy.mJITFrameHandle)
+    { }
+
     OnStackFrameKey(void* aJITAddress, unsigned aJITDepth)
       : FrameKey(aJITAddress, aJITDepth)
       , mJITFrameHandle(nullptr)
     { }
 
     OnStackFrameKey(void* aJITAddress, unsigned aJITDepth,
                     const JS::ForEachProfiledFrameOp::FrameHandle& aJITFrameHandle)
       : FrameKey(aJITAddress, aJITDepth)