Bug 733792 - Add nsIProfiler::getSharedLibraryInformation. r=bgirard
authorMarkus Stange <mstange@themasta.com>
Fri, 09 Mar 2012 16:20:00 +0100
changeset 88641 d674eb1d1aa4f83bd0eb049c352784656f5104fb
parent 88640 e5fc3acf910de120648569a46fab46aa88878e3e
child 88642 34050c0da8444f5d21cc27bedb1b3582b8e8a073
push id6934
push usermstange@themasta.com
push dateFri, 09 Mar 2012 15:21:25 +0000
treeherdermozilla-inbound@34050c0da844 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgirard
bugs733792
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 733792 - Add nsIProfiler::getSharedLibraryInformation. r=bgirard
tools/profiler/nsIProfiler.idl
tools/profiler/nsProfiler.cpp
--- a/tools/profiler/nsIProfiler.idl
+++ b/tools/profiler/nsIProfiler.idl
@@ -41,10 +41,18 @@ interface nsIProfiler : nsISupports
   void StartProfiler(in PRUint32 aInterval, in PRUint32 aEntries,
                       [array, size_is(aFeatureCount)] in string aFeatures,
                       in PRUint32 aFeatureCount);
   void StopProfiler();
   string GetProfile();
   boolean IsActive();
   void GetResponsivenessTimes(out PRUint32 aCount, [retval, array, size_is(aCount)] out double aResult);
   void GetFeatures(out PRUint32 aCount, [retval, array, size_is(aCount)] out string aFeatures);
+
+  /**
+   * Returns a JSON string of an array of shared library objects.
+   * Every object has three properties: start, end, and name.
+   * start and end are integers describing the address range that the library
+   * occupies in memory. name is the path of the library as a string.
+   */
+  AString getSharedLibraryInformation();
 };
 
--- a/tools/profiler/nsProfiler.cpp
+++ b/tools/profiler/nsProfiler.cpp
@@ -30,22 +30,25 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <string>
+#include <sstream>
 #ifdef MOZ_INSTRUMENT_EVENT_LOOP
 #include "EventTracer.h"
 #endif
 #include "sampler.h"
 #include "nsProfiler.h"
 #include "nsMemory.h"
+#include "shared-libraries.h"
+#include "nsString.h"
 
 using std::string;
 
 NS_IMPL_ISUPPORTS1(nsProfiler, nsIProfiler)
 
 
 nsProfiler::nsProfiler()
 {
@@ -80,16 +83,53 @@ nsProfiler::GetProfile(char **aProfile)
                          (nsMemory::Clone(profile, (len + 1) * sizeof(char)));
     profileStr[len] = '\0';
     *aProfile = profileStr;
     free(profile);
   }
   return NS_OK;
 }
 
+static void
+AddSharedLibraryInfoToStream(std::ostream& aStream, SharedLibrary& aLib)
+{
+  aStream << "{";
+  aStream << "\"start\":" << aLib.GetStart();
+  aStream << ",\"end\":" << aLib.GetEnd();
+  aStream << ",\"name\":\"" << aLib.GetName() << "\"";
+  aStream << "}";
+}
+
+static std::string
+GetSharedLibraryInfoString()
+{
+  SharedLibraryInfo info = SharedLibraryInfo::GetInfoForSelf();
+  if (info.GetSize() == 0)
+    return "[]";
+
+  std::ostringstream os;
+  os << "[";
+  AddSharedLibraryInfoToStream(os, info.GetEntry(0));
+
+  for (size_t i = 1; i < info.GetSize(); i++) {
+    os << ",";
+    AddSharedLibraryInfoToStream(os, info.GetEntry(i));
+  }
+
+  os << "]";
+  return os.str();
+}
+
+NS_IMETHODIMP
+nsProfiler::GetSharedLibraryInformation(nsAString& aOutString)
+{
+  aOutString.Assign(NS_ConvertUTF8toUTF16(GetSharedLibraryInfoString().c_str()));
+  return NS_OK;
+}
+
 NS_IMETHODIMP
 nsProfiler::IsActive(bool *aIsActive)
 {
   *aIsActive = SAMPLER_IS_ACTIVE();
   return NS_OK;
 }
 
 NS_IMETHODIMP