Bug 970412: Modify Telemetry.fileIOReports to include limited path information; r=froydnj

This commit is contained in:
Aaron Klotz 2014-02-11 14:24:49 -07:00
parent adf9ed6f0c
commit d00eac16ff

View File

@ -288,6 +288,20 @@ class TelemetryIOInterposeObserver : public IOInterposeObserver
double totalTime; /** Accumulated duration of all operations */
};
typedef nsBaseHashtableET<nsStringHashKey, FileStats> FileIOEntryType;
struct SafeDir {
SafeDir(const nsAString& aPath, const nsAString& aSubstName)
: mPath(aPath)
, mSubstName(aSubstName)
{}
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
return mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
mSubstName.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
nsString mPath; /** Path to the directory */
nsString mSubstName; /** Name to substitute with */
};
public:
TelemetryIOInterposeObserver(nsIFile* aXreDir);
@ -302,7 +316,12 @@ public:
*/
bool ReflectIntoJS(JSContext *cx, JS::Handle<JSObject*> rootObj);
void AddPath(const nsAString& aPath);
/**
* Adds a path for inclusion in main thread I/O report.
* @param aPath Directory path
* @param aSubstName Name to substitute for aPath for privacy reasons
*/
void AddPath(const nsAString& aPath, const nsAString& aSubstName);
/**
* Get size of hash table with file stats
@ -318,7 +337,7 @@ public:
mSafeDirs.SizeOfExcludingThis(aMallocSizeOf);
uint32_t safeDirsLen = mSafeDirs.Length();
for (uint32_t i = 0; i < safeDirsLen; ++i) {
size += mSafeDirs[i].SizeOfExcludingThisIfUnshared(aMallocSizeOf);
size += mSafeDirs[i].SizeOfExcludingThis(aMallocSizeOf);
}
return size;
}
@ -327,7 +346,7 @@ private:
// Statistics for each filename
AutoHashtable<FileIOEntryType> mFileStats;
// Container for whitelisted directories
nsTArray<nsString> mSafeDirs;
nsTArray<SafeDir> mSafeDirs;
/**
* Reflect a FileIOEntryType object to a Javascript property on obj with
@ -350,13 +369,14 @@ TelemetryIOInterposeObserver::TelemetryIOInterposeObserver(nsIFile* aXreDir)
nsAutoString xreDirPath;
nsresult rv = aXreDir->GetPath(xreDirPath);
if (NS_SUCCEEDED(rv)) {
AddPath(xreDirPath);
AddPath(xreDirPath, NS_LITERAL_STRING("{xre}"));
}
}
void TelemetryIOInterposeObserver::AddPath(const nsAString& aPath)
void TelemetryIOInterposeObserver::AddPath(const nsAString& aPath,
const nsAString& aSubstName)
{
mSafeDirs.AppendElement(aPath);
mSafeDirs.AppendElement(SafeDir(aPath, aSubstName));
}
void TelemetryIOInterposeObserver::Observe(Observation& aOb)
@ -374,40 +394,33 @@ void TelemetryIOInterposeObserver::Observe(Observation& aOb)
return;
}
bool report = false;
nsAutoString processedName;
nsDependentString filenameStr(filename);
uint32_t filenameStrLen = filenameStr.Length();
uint32_t safeDirsLen = mSafeDirs.Length();
for (uint32_t i = 0; i < safeDirsLen; ++i) {
uint32_t curSafeDirLen = mSafeDirs[i].Length();
uint32_t curSafeDirLen = mSafeDirs[i].mPath.Length();
if (curSafeDirLen <= filenameStrLen) {
#if defined(_MSC_VER)
if (!_wcsnicmp(filename, mSafeDirs[i].get(), curSafeDirLen)) {
if (!_wcsnicmp(filename, mSafeDirs[i].mPath.get(), curSafeDirLen)) {
#else
if (!std::char_traits<char16_t>::compare(filename, mSafeDirs[i].get(),
if (!std::char_traits<char16_t>::compare(filename,
mSafeDirs[i].mPath.get(),
curSafeDirLen)) {
#endif
report = true;
processedName = mSafeDirs[i].mSubstName;
processedName += Substring(filenameStr, curSafeDirLen);
break;
}
}
}
if (!report) {
if (processedName.IsEmpty()) {
return;
}
const char16_t* leaf = filename + filenameStrLen;
while (filename < leaf) {
char16_t c = *(leaf - 1);
if (c == MOZ_UTF16('\\') || c == MOZ_UTF16('/')) {
break;
}
--leaf;
}
// Create a new entry or retrieve the existing one
FileIOEntryType* entry = mFileStats.PutEntry(nsDependentString(leaf));
FileIOEntryType* entry = mFileStats.PutEntry(processedName);
if (entry) {
// Update the statistics
entry->mData.totalTime += (double) aOb.Duration().ToMilliseconds();
@ -2962,7 +2975,7 @@ SetProfileDir(nsIFile* aProfD)
if (NS_FAILED(rv)) {
return;
}
sTelemetryIOObserver->AddPath(profDirPath);
sTelemetryIOObserver->AddPath(profDirPath, NS_LITERAL_STRING("{profile}"));
}
void