diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index e1eb67b9e756..06ac72920f00 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -1694,6 +1694,22 @@ public: for (unsigned int i = 0, n = mRawModules.GetSize(); i != n; i++) { const SharedLibrary &info = mRawModules.GetEntry(i); + nsString basename = info.GetName(); +#if defined(XP_MACOSX) || defined(XP_LINUX) + int32_t pos = basename.RFindChar('/'); + if (pos != kNotFound) { + basename.Cut(0, pos + 1); + } +#endif + + nsString debug_basename = info.GetDebugName(); +#if defined(XP_MACOSX) || defined(XP_LINUX) + pos = debug_basename.RFindChar('/'); + if (pos != kNotFound) { + debug_basename.Cut(0, pos + 1); + } +#endif + JS::RootedObject moduleObj(cx, JS_NewPlainObject(cx)); if (!moduleObj) { mPromise->MaybeReject(NS_ERROR_FAILURE); @@ -1701,7 +1717,7 @@ public: } // Module name. - JS::RootedString moduleName(cx, JS_NewUCStringCopyZ(cx, info.GetModuleName().get())); + JS::RootedString moduleName(cx, JS_NewUCStringCopyZ(cx, basename.get())); if (!moduleName || !JS_DefineProperty(cx, moduleObj, "name", moduleName, JSPROP_ENUMERATE)) { mPromise->MaybeReject(NS_ERROR_FAILURE); return NS_OK; @@ -1710,8 +1726,8 @@ public: // Module debug name. JS::RootedValue moduleDebugName(cx); - if (!info.GetDebugName().IsEmpty()) { - JS::RootedString str_moduleDebugName(cx, JS_NewUCStringCopyZ(cx, info.GetDebugName().get())); + if (!debug_basename.IsEmpty()) { + JS::RootedString str_moduleDebugName(cx, JS_NewUCStringCopyZ(cx, debug_basename.get())); if (!str_moduleDebugName) { mPromise->MaybeReject(NS_ERROR_FAILURE); return NS_OK; @@ -3212,8 +3228,18 @@ GetStackAndModules(const std::vector& aPCs) #ifdef MOZ_GECKO_PROFILER for (unsigned i = 0, n = rawModules.GetSize(); i != n; ++i) { const SharedLibrary &info = rawModules.GetEntry(i); + nsString basename = info.GetDebugName(); +#if defined(XP_MACOSX) || defined(XP_LINUX) + // We want to use just the basename as the libname, but the + // current profiler addon needs the full path name, so we compute the + // basename in here. + int32_t pos = basename.RFindChar('/'); + if (pos != kNotFound) { + basename.Cut(0, pos + 1); + } +#endif mozilla::Telemetry::ProcessedStack::Module module = { - info.GetDebugName(), + basename, info.GetBreakpadId() }; Ret.AddModule(module); diff --git a/tools/profiler/core/shared-libraries-linux.cc b/tools/profiler/core/shared-libraries-linux.cc index 3e14aafe2bc1..5ca440bea091 100644 --- a/tools/profiler/core/shared-libraries-linux.cc +++ b/tools/profiler/core/shared-libraries-linux.cc @@ -81,17 +81,12 @@ dl_iterate_callback(struct dl_phdr_info *dl_info, size_t size, void *data) if (end > libEnd) libEnd = end; } - const char *path = dl_info->dlpi_name; + const char *name = dl_info->dlpi_name; nsAutoString nameStr; - mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(path), nameStr))); + mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(name), nameStr))); - int32_t pos = nameStr.RFindChar('/'); - if (pos != kNotFound) { - nameStr.Cut(0, pos + 1); - } - - SharedLibrary shlib(libStart, libEnd, 0, getId(path), nameStr, nameStr, ""); + SharedLibrary shlib(libStart, libEnd, 0, getId(name), nameStr, nameStr, ""); info.AddSharedLibrary(shlib); return 0; @@ -131,10 +126,10 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() unsigned long end; char perm[6] = ""; unsigned long offset; - char modulePath[PATH_MAX] = ""; + char name[PATH_MAX] = ""; ret = sscanf(line.c_str(), "%lx-%lx %6s %lx %*s %*x %" PATH_MAX_STRING(PATH_MAX) "s\n", - &start, &end, perm, &offset, modulePath); + &start, &end, perm, &offset, name); if (!strchr(perm, 'x')) { // Ignore non executable entries continue; @@ -146,7 +141,7 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() #if defined(PROFILE_JAVA) // Use proc/pid/maps to get the dalvik-jit section since it has // no associated phdrs - if (strcmp(modulePath, "/dev/ashmem/dalvik-jit-code-cache") != 0) { + if (strcmp(name, "/dev/ashmem/dalvik-jit-code-cache") != 0) { continue; } #else @@ -159,12 +154,7 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() #endif nsAutoString nameStr; - mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(modulePath), nameStr))); - - int32_t pos = nameStr.RFindChar('/'); - if (pos != kNotFound) { - nameStr.Cut(0, pos + 1); - } + mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(name), nameStr))); SharedLibrary shlib(start, end, offset, getId(name), nameStr, nameStr, ""); info.AddSharedLibrary(shlib); diff --git a/tools/profiler/core/shared-libraries-macos.cc b/tools/profiler/core/shared-libraries-macos.cc index 90d785a1dd99..b5ddfca299ea 100644 --- a/tools/profiler/core/shared-libraries-macos.cc +++ b/tools/profiler/core/shared-libraries-macos.cc @@ -35,7 +35,7 @@ typedef segment_command_64 mach_segment_command_type; #endif static -void addSharedLibrary(const platform_mach_header* header, char *path, SharedLibraryInfo &info) { +void addSharedLibrary(const platform_mach_header* header, char *name, SharedLibraryInfo &info) { const struct load_command *cmd = reinterpret_cast(header + 1); @@ -73,12 +73,7 @@ void addSharedLibrary(const platform_mach_header* header, char *path, SharedLibr } nsAutoString nameStr; - mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(path), nameStr))); - - int32_t pos = nameStr.RFindChar('/'); - if (pos != kNotFound) { - nameStr.Cut(0, pos + 1); - } + mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(name), nameStr))); info.AddSharedLibrary(SharedLibrary(start, start + size, 0, uuid.str(), nameStr, nameStr, "")); diff --git a/tools/profiler/core/shared-libraries-win32.cc b/tools/profiler/core/shared-libraries-win32.cc index 62e2d6cf67a8..b8308128b53d 100644 --- a/tools/profiler/core/shared-libraries-win32.cc +++ b/tools/profiler/core/shared-libraries-win32.cc @@ -182,17 +182,17 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() } } - nsAutoString moduleNameStr(modulePath); - int32_t pos = moduleNameStr.RFindChar('\\'); + nsAutoString moduleName(modulePath); + int32_t pos = moduleName.RFindChar('\\'); if (pos != kNotFound) { - moduleNameStr.Cut(0, pos + 1); + moduleName.Cut(0, pos + 1); } SharedLibrary shlib((uintptr_t)module.lpBaseOfDll, (uintptr_t)module.lpBaseOfDll + module.SizeOfImage, 0, // DLLs are always mapped at offset 0 on Windows breakpadId, - moduleNameStr, + moduleName, pdbNameStr, GetVersion(modulePath)); sharedLibraryInfo.AddSharedLibrary(shlib); diff --git a/tools/profiler/public/shared-libraries.h b/tools/profiler/public/shared-libraries.h index e9ffa0f321d6..ca40715930f4 100644 --- a/tools/profiler/public/shared-libraries.h +++ b/tools/profiler/public/shared-libraries.h @@ -27,14 +27,14 @@ public: uintptr_t aEnd, uintptr_t aOffset, const std::string& aBreakpadId, - const nsString& aModuleName, + const nsString& aName, const nsString& aDebugName, const std::string& aVersion) : mStart(aStart) , mEnd(aEnd) , mOffset(aOffset) , mBreakpadId(aBreakpadId) - , mModuleName(aModuleName) + , mName(aName) , mDebugName(aDebugName) , mVersion(aVersion) {} @@ -44,7 +44,7 @@ public: , mEnd(aEntry.mEnd) , mOffset(aEntry.mOffset) , mBreakpadId(aEntry.mBreakpadId) - , mModuleName(aEntry.mModuleName) + , mName(aEntry.mName) , mDebugName(aEntry.mDebugName) , mVersion(aEntry.mVersion) {} @@ -58,7 +58,7 @@ public: mEnd = aEntry.mEnd; mOffset = aEntry.mOffset; mBreakpadId = aEntry.mBreakpadId; - mModuleName = aEntry.mModuleName; + mName = aEntry.mName; mDebugName = aEntry.mDebugName; mVersion = aEntry.mVersion; return *this; @@ -69,7 +69,7 @@ public: return (mStart == other.mStart) && (mEnd == other.mEnd) && (mOffset == other.mOffset) && - (mModuleName == other.mModuleName) && + (mName == other.mName) && (mDebugName == other.mDebugName) && (mBreakpadId == other.mBreakpadId) && (mVersion == other.mVersion); @@ -79,7 +79,7 @@ public: uintptr_t GetEnd() const { return mEnd; } uintptr_t GetOffset() const { return mOffset; } const std::string &GetBreakpadId() const { return mBreakpadId; } - const nsString &GetModuleName() const { return mModuleName; } + const nsString &GetName() const { return mName; } const std::string GetNativeDebugName() const { nsAutoCString debugNameStr; @@ -97,7 +97,7 @@ private: uintptr_t mEnd; uintptr_t mOffset; std::string mBreakpadId; - nsString mModuleName; + nsString mName; nsString mDebugName; std::string mVersion; };