Bug 928476 - Add telemetry to measure cross-global adopts. r=mrbkap,nfroyd

This commit is contained in:
Bobby Holley 2013-10-23 14:02:42 +02:00
parent 7f3555c1cf
commit d23fe1a7b3
5 changed files with 62 additions and 2 deletions

View File

@ -1659,14 +1659,19 @@ ReparentWrapper(JSContext* aCx, JS::Handle<JSObject*> aObjArg)
JSAutoCompartment oldAc(aCx, oldParent);
if (js::GetObjectCompartment(oldParent) ==
js::GetObjectCompartment(newParent)) {
JSCompartment* oldCompartment = js::GetObjectCompartment(oldParent);
JSCompartment* newCompartment = js::GetObjectCompartment(newParent);
if (oldCompartment == newCompartment) {
if (!JS_SetParent(aCx, aObj, newParent)) {
MOZ_CRASH();
}
return NS_OK;
}
// Telemetry.
xpc::RecordDonatedNode(oldCompartment);
xpc::RecordAdoptedNode(newCompartment);
nsISupports* native = UnwrapDOMObjectToISupports(aObj);
if (!native) {
return NS_OK;

View File

@ -261,9 +261,32 @@ public:
namespace xpc {
static uint32_t kLivingAdopters = 0;
void
RecordAdoptedNode(JSCompartment *c)
{
CompartmentPrivate *priv = EnsureCompartmentPrivate(c);
if (!priv->adoptedNode) {
priv->adoptedNode = true;
++kLivingAdopters;
}
}
void
RecordDonatedNode(JSCompartment *c)
{
EnsureCompartmentPrivate(c)->donatedNode = true;
}
CompartmentPrivate::~CompartmentPrivate()
{
MOZ_COUNT_DTOR(xpc::CompartmentPrivate);
Telemetry::Accumulate(Telemetry::COMPARTMENT_ADOPTED_NODE, adoptedNode);
Telemetry::Accumulate(Telemetry::COMPARTMENT_DONATED_NODE, donatedNode);
if (adoptedNode)
--kLivingAdopters;
}
bool CompartmentPrivate::TryParseLocationURI()
@ -653,6 +676,13 @@ XPCJSRuntime::GCSliceCallback(JSRuntime *rt,
void
XPCJSRuntime::CustomGCCallback(JSGCStatus status)
{
// Record kLivingAdopters once per GC to approximate time sampling during
// periods of activity.
if (status == JSGC_BEGIN) {
Telemetry::Accumulate(Telemetry::COMPARTMENT_LIVING_ADOPTERS,
kLivingAdopters);
}
nsTArray<xpcGCCallback> callbacks(extraGCCallbacks);
for (uint32_t i = 0; i < callbacks.Length(); ++i)
callbacks[i](status);

View File

@ -3744,6 +3744,8 @@ public:
CompartmentPrivate()
: wantXrays(false)
, universalXPConnectEnabled(false)
, adoptedNode(false)
, donatedNode(false)
, scope(nullptr)
, locationWasParsed(false)
{
@ -3760,6 +3762,10 @@ public:
// the old scoping rules of enablePrivilege). Using it is inherently unsafe.
bool universalXPConnectEnabled;
// for telemetry. See bug 928476.
bool adoptedNode;
bool donatedNode;
// Our XPCWrappedNativeScope. This is non-null if and only if this is an
// XPConnect compartment.
XPCWrappedNativeScope *scope;

View File

@ -359,6 +359,12 @@ SystemErrorReporterExternal(JSContext *cx, const char *message,
NS_EXPORT_(void)
SimulateActivityCallback(bool aActive);
void
RecordAdoptedNode(JSCompartment *c);
void
RecordDonatedNode(JSCompartment *c);
} // namespace xpc
namespace mozilla {

View File

@ -28,6 +28,19 @@
"n_values": 21,
"description": "Maximum number of concurrent threads reached during a given download session"
},
"COMPARTMENT_DONATED_NODE": {
"kind": "boolean",
"description": "When a compartment is destroyed, we record whether one of its nodes was ever adopted into another compartment"
},
"COMPARTMENT_ADOPTED_NODE": {
"kind": "boolean",
"description": "When a compartment is destroyed, we record whether it had ever adopted a node from another compartment"
},
"COMPARTMENT_LIVING_ADOPTERS": {
"kind": "enumerated",
"n_values": 10,
"description": "The number of living compartments for which COMPARTMENT_ADOPTED_NODE is true"
},
"CYCLE_COLLECTOR": {
"kind": "exponential",
"high": "10000",