Bug 693101 - Unbreak about:memory's parsing of /proc/smaps entries which live in /dev/ashmem on Android. r=khuey

This commit is contained in:
Justin Lebar 2011-10-10 11:10:50 -04:00
parent e58e0cde34
commit cbc4216a44

View File

@ -100,13 +100,24 @@ void GetDirname(const nsCString &aPath, nsACString &aOut)
void GetBasename(const nsCString &aPath, nsACString &aOut)
{
nsCString out;
PRInt32 idx = aPath.RFind("/");
if (idx == -1) {
aOut.Assign(aPath);
out.Assign(aPath);
}
else {
aOut.Assign(Substring(aPath, idx + 1));
out.Assign(Substring(aPath, idx + 1));
}
// On Android, some entries in /dev/ashmem end with "(deleted)" (e.g.
// "/dev/ashmem/libxul.so(deleted)"). We don't care about this modifier, so
// cut it off when getting the entry's basename.
if (EndsWithLiteral(out, "(deleted)")) {
out.Assign(Substring(out, 0, out.RFind("(deleted)")));
}
out.StripChars(" ");
aOut.Assign(out);
}
// MapsReporter::CollectReports uses this stuct to keep track of whether it's
@ -226,8 +237,9 @@ MapsReporter::FindLibxul()
// Note that we're scanning /proc/self/*maps*, not smaps, here.
FILE *f = fopen("/proc/self/maps", "r");
if (!f)
if (!f) {
return NS_ERROR_FAILURE;
}
while (true) {
// Skip any number of non-slash characters, then capture starting with the
@ -266,9 +278,9 @@ MapsReporter::ParseMapping(
PR_STATIC_ASSERT(sizeof(long long) == sizeof(PRInt64));
PR_STATIC_ASSERT(sizeof(int) == sizeof(PRInt32));
if (mLibxulDir.IsEmpty()) {
NS_ENSURE_SUCCESS(FindLibxul(), NS_ERROR_FAILURE);
}
// Don't bail if FindLibxul fails. We can still gather meaningful stats
// here.
FindLibxul();
// The first line of an entry in /proc/self/smaps looks just like an entry
// in /proc/maps:
@ -362,8 +374,6 @@ MapsReporter::GetReporterNameAndDescription(
"syscall.");
}
else if (!basename.IsEmpty()) {
NS_ASSERTION(!mLibxulDir.IsEmpty(), "mLibxulDir should not be empty.");
nsCAutoString dirname;
GetDirname(absPath, dirname);
@ -372,7 +382,8 @@ MapsReporter::GetReporterNameAndDescription(
if (EndsWithLiteral(basename, ".so") ||
(basename.Find(".so") != -1 && dirname.Find("/lib") != -1)) {
aName.Append("shared-libraries/");
if (dirname.Equals(mLibxulDir) || mMozillaLibraries.Contains(basename)) {
if ((!mLibxulDir.IsEmpty() && dirname.Equals(mLibxulDir)) ||
mMozillaLibraries.Contains(basename)) {
aName.Append("shared-libraries-mozilla/");
}
else {