Bug 1341023 - Take module name encoding into account for late writes and hangs. r=Dexter

This commit is contained in:
Marco Castelluccio
2017-02-21 22:44:42 +00:00
parent d1d320d7c1
commit 04e83173db
5 changed files with 31 additions and 21 deletions

View File

@@ -33,7 +33,8 @@ public:
struct Module
{
// The file name, /foo/bar/libxul.so for example.
std::string mName;
// It can contain unicode characters.
nsString mName;
std::string mBreakpadId;
bool operator==(const Module& other) const;

View File

@@ -1595,20 +1595,14 @@ CreateJSStackObject(JSContext *cx, const CombinedStacks &stacks) {
unsigned index = 0;
// Module name
JS::Rooted<JSString*> str(cx, JS_NewStringCopyZ(cx, module.mName.c_str()));
if (!str) {
return nullptr;
}
if (!JS_DefineElement(cx, moduleInfoArray, index++, str, JSPROP_ENUMERATE)) {
JS::Rooted<JSString*> str(cx, JS_NewUCStringCopyZ(cx, module.mName.get()));
if (!str || !JS_DefineElement(cx, moduleInfoArray, index++, str, JSPROP_ENUMERATE)) {
return nullptr;
}
// Module breakpad identifier
JS::Rooted<JSString*> id(cx, JS_NewStringCopyZ(cx, module.mBreakpadId.c_str()));
if (!id) {
return nullptr;
}
if (!JS_DefineElement(cx, moduleInfoArray, index++, id, JSPROP_ENUMERATE)) {
if (!id || !JS_DefineElement(cx, moduleInfoArray, index++, id, JSPROP_ENUMERATE)) {
return nullptr;
}
}
@@ -1900,7 +1894,7 @@ ReadStack(const char *aFileName, Telemetry::ProcessedStack &aStack)
}
Telemetry::ProcessedStack::Module module = {
moduleName,
NS_ConvertUTF8toUTF16(moduleName.c_str()),
breakpadId
};
stack.AddModule(module);
@@ -3224,14 +3218,14 @@ GetStackAndModules(const std::vector<uintptr_t>& aPCs)
#ifdef MOZ_GECKO_PROFILER
for (unsigned i = 0, n = rawModules.GetSize(); i != n; ++i) {
const SharedLibrary &info = rawModules.GetEntry(i);
std::string basename = info.GetNativeDebugName();
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.
size_t pos = basename.rfind('/');
if (pos != std::string::npos) {
basename = basename.substr(pos + 1);
int32_t pos = basename.RFindChar('/');
if (pos != kNotFound) {
basename.Cut(0, pos + 1);
}
#endif
mozilla::Telemetry::ProcessedStack::Module module = {

View File

@@ -301,6 +301,8 @@ Limits for captured stacks are the same as for chromeHangs (see below). Furtherm
* the key length is limited to 50 characters,
* keys are restricted to alpha-numeric characters and `-`.
The module names can contain unicode characters.
Structure:
.. code-block:: js
@@ -336,6 +338,8 @@ Some limits are applied:
* Reported chrome hang stacks are limited in depth to 50 entries.
* The maximum number of reported stacks is 50.
The module names can contain unicode characters.
Structure:
.. code-block:: js
@@ -561,7 +565,9 @@ Structure:
lateWrites
----------
This sections reports writes to the file system that happen during shutdown. The reported data contains the stack and the loaded libraries at the time the writes happened.
This sections reports writes to the file system that happen during shutdown. The reported data contains the stack and the file names of the loaded libraries at the time the writes happened.
The file names of the loaded libraries can contain unicode characters.
Structure:

View File

@@ -20,7 +20,8 @@ const LATE_WRITE_PREFIX = "Telemetry.LateWriteFinal-";
const LOADED_MODULES = {
"4759A7E6993548C89CAF716A67EC242D00": "libtest.so",
"F77AF15BB8D6419FA875954B4A3506CA00": "libxul.so",
"1E2F7FB590424E8F93D60BB88D66B8C500": "libc.so"
"1E2F7FB590424E8F93D60BB88D66B8C500": "libc.so",
"E4D6D70CC09A63EF8B88D532F867858800": "libmodμles.so",
};
const N_MODULES = Object.keys(LOADED_MODULES).length;
@@ -28,12 +29,14 @@ const N_MODULES = Object.keys(LOADED_MODULES).length;
const STACK1 = [
[ 0, 0 ],
[ 1, 1 ],
[ 2, 2 ]
[ 2, 2 ],
[ 3, 3 ],
];
const STACK2 = [
[ 0, 0 ],
[ 1, 5 ],
[ 2, 10 ],
[ 3, 15 ],
];
// XXX The only error checking is for a zero-sized stack.
const STACK_BOGUS = [];
@@ -42,8 +45,14 @@ function write_string_to_file(file, contents) {
let ostream = Cc["@mozilla.org/network/safe-file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
ostream.init(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
RW_OWNER, ostream.DEFER_OPEN);
ostream.write(contents, contents.length);
RW_OWNER, ostream.DEFER_OPEN);
var bos = Cc["@mozilla.org/binaryoutputstream;1"]
.createInstance(Ci.nsIBinaryOutputStream);
bos.setOutputStream(ostream);
let utf8 = new TextEncoder("utf-8").encode(contents);
bos.writeByteArray(utf8, utf8.length);
ostream.QueryInterface(Ci.nsISafeOutputStream).finish();
ostream.close();
}

View File

@@ -168,7 +168,7 @@ LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
for (size_t i = 0; i < numModules; ++i) {
Telemetry::ProcessedStack::Module module = stack.GetModule(i);
sha1Stream.Printf("%s %s\n", module.mBreakpadId.c_str(),
module.mName.c_str());
NS_ConvertUTF16toUTF8(module.mName).get());
}
size_t numFrames = stack.GetStackSize();