Bug 785440 - Add profiler labels to WebIDL bindings: getters / setters / method calls. r?bz draft
authorMarkus Stange <mstange@themasta.com>
Tue, 01 Aug 2017 16:07:10 -0400
changeset 619367 e7679ed58bc95609592b9888b4a2cbdc8e29b3a4
parent 619366 2fbd17ef75fdded231e791eab3329b90e10314ae
child 640367 bd5eb4382f9dbe20232fd878b53cfa17a6705f19
push id71647
push userbmo:mstange@themasta.com
push dateTue, 01 Aug 2017 21:50:39 +0000
reviewersbz
bugs785440
milestone56.0a1
Bug 785440 - Add profiler labels to WebIDL bindings: getters / setters / method calls. r?bz MozReview-Commit-ID: IyhXzv0Chye
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -7623,17 +7623,17 @@ class CGPerSignatureCall(CGThing):
     # XXXbz For now each entry in the argument list is either an
     # IDLArgument or a FakeArgument, but longer-term we may want to
     # have ways of flagging things like JSContext* or optional_argc in
     # there.
 
     def __init__(self, returnType, arguments, nativeMethodName, static,
                  descriptor, idlNode, argConversionStartsAt=0, getter=False,
                  setter=False, isConstructor=False, useCounterName=None,
-                 resultVar=None, objectName="obj"):
+                 resultVar=None, objectName="obj", profilerLabel=None):
         assert idlNode.isMethod() == (not getter and not setter)
         assert idlNode.isAttr() == (getter or setter)
         # Constructors are always static
         assert not isConstructor or static
 
         CGThing.__init__(self)
         self.returnType = returnType
         self.descriptor = descriptor
@@ -7641,16 +7641,19 @@ class CGPerSignatureCall(CGThing):
         self.extendedAttributes = descriptor.getExtendedAttributes(idlNode,
                                                                    getter=getter,
                                                                    setter=setter)
         self.arguments = arguments
         self.argCount = len(arguments)
         self.isConstructor = isConstructor
         cgThings = []
 
+        if profilerLabel is not None:
+            cgThings.append(CGGeneric(profilerLabel))
+
         # Here, we check if the current getter, setter, method, interface or
         # inherited interfaces have the UnsafeInPrerendering extended attribute
         # and if so, we add a check to make sure it is safe.
         if (idlNode.getExtendedAttribute("UnsafeInPrerendering") or
             descriptor.interface.getExtendedAttribute("UnsafeInPrerendering") or
             any(i.getExtendedAttribute("UnsafeInPrerendering")
                 for i in descriptor.interface.getInheritedInterfaces())):
                 cgThings.append(CGGeneric(dedent(
@@ -8111,16 +8114,22 @@ class CGMethodCall(CGThing):
 
         if method.isStatic():
             nativeType = descriptor.nativeType
             staticTypeOverride = PropertyDefiner.getStringAttr(method, "StaticClassOverride")
             if (staticTypeOverride):
                 nativeType = staticTypeOverride
             nativeMethodName = "%s::%s" % (nativeType, nativeMethodName)
 
+        profilerLabel = fill(
+            """
+            AUTO_PROFILER_LABEL_JSCONTEXT(cx, "${methodName}", OTHER);
+            """,
+            methodName=methodName)
+
         def requiredArgCount(signature):
             arguments = signature[1]
             if len(arguments) == 0:
                 return 0
             requiredArgs = len(arguments)
             while requiredArgs and arguments[requiredArgs-1].optional:
                 requiredArgs -= 1
             return requiredArgs
@@ -8150,16 +8159,18 @@ class CGMethodCall(CGThing):
                     """
                     if (MOZ_UNLIKELY(args.length() < ${requiredArgs})) {
                       return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "${methodName}");
                     }
                     """,
                     requiredArgs=requiredArgs,
                     methodName=methodName)
                 self.cgRoot.prepend(CGGeneric(code))
+
+            self.cgRoot.prepend(CGGeneric(profilerLabel))
             return
 
         # Need to find the right overload
         maxArgCount = method.maxArgCount
         allowedArgCounts = method.allowedArgCounts
 
         argCountCases = []
         for argCountIdx, argCount in enumerate(allowedArgCounts):
@@ -8479,16 +8490,17 @@ class CGMethodCall(CGThing):
                 # do with this.
                 caseBody.append(CGGeneric(
                     'return ThrowErrorMessage(cx, MSG_OVERLOAD_RESOLUTION_FAILED, "%d", "%d", "%s");\n' %
                     (distinguishingIndex + 1, argCount, methodName)))
 
             argCountCases.append(CGCase(str(argCount), CGList(caseBody)))
 
         overloadCGThings = []
+        overloadCGThings.append(CGGeneric(profilerLabel))
         overloadCGThings.append(
             CGGeneric("unsigned argcount = std::min(args.length(), %du);\n" %
                       maxArgCount))
         overloadCGThings.append(
             CGSwitch("argcount",
                      argCountCases,
                      CGGeneric('return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "%s");\n' %
                                methodName)))
@@ -8509,19 +8521,26 @@ class CGGetterCall(CGPerSignatureCall):
     def __init__(self, returnType, nativeMethodName, descriptor, attr):
         if attr.getExtendedAttribute("UseCounter"):
             useCounterName = "%s_%s_getter" % (descriptor.interface.identifier.name,
                                                attr.identifier.name)
         else:
             useCounterName = None
         if attr.isStatic():
             nativeMethodName = "%s::%s" % (descriptor.nativeType, nativeMethodName)
+        profilerLabel = fill(
+            """
+            AUTO_PROFILER_LABEL_JSCONTEXT(cx, "${interfaceName}.${attributeName}", OTHER);
+            """,
+            interfaceName=descriptor.interface.identifier.name,
+            attributeName=attr.identifier.name)
         CGPerSignatureCall.__init__(self, returnType, [], nativeMethodName,
                                     attr.isStatic(), descriptor, attr,
-                                    getter=True, useCounterName=useCounterName)
+                                    getter=True, useCounterName=useCounterName,
+                                    profilerLabel=profilerLabel)
 
 
 class CGNavigatorGetterCall(CGPerSignatureCall):
     """
     A class to generate a native object getter call for an IDL getter for a
     property generated by NavigatorProperty.
     """
     def __init__(self, returnType, _, descriptor, attr):
@@ -8585,20 +8604,27 @@ class CGSetterCall(CGPerSignatureCall):
     def __init__(self, argType, nativeMethodName, descriptor, attr):
         if attr.getExtendedAttribute("UseCounter"):
             useCounterName = "%s_%s_setter" % (descriptor.interface.identifier.name,
                                                attr.identifier.name)
         else:
             useCounterName = None
         if attr.isStatic():
             nativeMethodName = "%s::%s" % (descriptor.nativeType, nativeMethodName)
+        profilerLabel = fill(
+            """
+            AUTO_PROFILER_LABEL_JSCONTEXT(cx, "${interfaceName}.${attributeName}", OTHER);
+            """,
+            interfaceName=descriptor.interface.identifier.name,
+            attributeName=attr.identifier.name)
         CGPerSignatureCall.__init__(self, None,
                                     [FakeArgument(argType, attr, allowTreatNonCallableAsNull=True)],
                                     nativeMethodName, attr.isStatic(),
-                                    descriptor, attr, setter=True, useCounterName=useCounterName)
+                                    descriptor, attr, setter=True, useCounterName=useCounterName,
+                                    profilerLabel=profilerLabel)
 
     def wrap_return_value(self):
         attr = self.idlNode
         if self.descriptor.wrapperCache and attr.slotIndices is not None:
             if attr.getExtendedAttribute("StoreInSlot"):
                 args = "cx, self"
             else:
                 args = "self"
@@ -14140,16 +14166,17 @@ class CGBindingRoot(CGThing):
         bindingHeaders = dict.fromkeys((
             'mozilla/dom/NonRefcountedDOMObject.h',
             ),
             True)
         bindingDeclareHeaders = dict.fromkeys((
             'mozilla/dom/BindingDeclarations.h',
             'mozilla/dom/Nullable.h',
             'mozilla/ErrorResult.h',
+            'GeckoProfiler.h'
             ),
             True)
 
         descriptors = config.getDescriptors(webIDLFile=webIDLFile,
                                             hasInterfaceOrInterfacePrototypeObject=True)
 
         unionTypes = UnionsForFile(config, webIDLFile)