Bug 1013326 - Distinguish chrome and content scripts in pseudostack; r=snorp

This commit is contained in:
Jim Chen
2014-06-06 18:39:40 -04:00
parent 1838e1be0e
commit 23291c8c8f
3 changed files with 57 additions and 0 deletions

View File

@@ -5,6 +5,9 @@
#include "ThreadStackHelper.h"
#include "MainThreadUtils.h"
#include "nsJSPrincipals.h"
#include "nsScriptSecurityManager.h"
#include "jsfriendapi.h"
#include "mozilla/Assertions.h"
#include "mozilla/Move.h"
@@ -208,6 +211,51 @@ ThreadStackHelper::PrepareStackBuffer(Stack& aStack)
#endif
}
#ifdef MOZ_ENABLE_PROFILER_SPS
namespace {
bool
IsChromeJSScript(JSScript* aScript)
{
// May be called from another thread or inside a signal handler.
// We assume querying the script is safe but we must not manipulate it.
nsIScriptSecurityManager* const secman =
nsScriptSecurityManager::GetScriptSecurityManager();
NS_ENSURE_TRUE(secman, false);
JSPrincipals* const principals = JS_GetScriptPrincipals(aScript);
return secman->IsSystemPrincipal(nsJSPrincipals::get(principals));
}
} // namespace
const char*
ThreadStackHelper::AppendJSEntry(const volatile StackEntry* aEntry,
const char* aPrevLabel)
{
// May be called from another thread or inside a signal handler.
// We assume querying the script is safe but we must not manupulate it.
MOZ_ASSERT(aEntry->isJs());
MOZ_ASSERT(aEntry->script());
const char* label;
if (IsChromeJSScript(aEntry->script())) {
label = "(chrome script)";
} else {
label = "(content script)";
}
if (label == aPrevLabel) {
return aPrevLabel;
}
mStackBuffer.infallibleAppend(label);
return label;
}
#endif // MOZ_ENABLE_PROFILER_SPS
void
ThreadStackHelper::FillStackBuffer()
{
@@ -225,6 +273,10 @@ ThreadStackHelper::FillStackBuffer()
if (entry->isCopyLabel()) {
continue;
}
if (entry->isJs()) {
prevLabel = AppendJSEntry(entry, prevLabel);
continue;
}
const char* const label = entry->label();
if (label == prevLabel) {
continue;