code: function wrapMethod(target, targetType, signature, opt_generator) {
      // Parse signature.
      var parsedSignature = wtf.data.Variable.parseSignature(signature);
      var methodName = parsedSignature.name;
  
      // Define a custom event type at runtime.
      var customEvent = wtf.trace.events.createScope(
          targetType + '#' + signature);
      goog.asserts.assert(customEvent);
  
      // Grab the original method from the target.
      var rawFn = target[methodName];
      if (!rawFn) {
        goog.global.console.log(targetType + ' is missing ' + methodName);
        return;
      }
  
      // Generate a bound function.
      var instrumentedFn;
      if (opt_generator) {
        // Custom enter function generator.
        instrumentedFn = opt_generator(rawFn, customEvent);
      } else {
        // Default case of simple event.
        instrumentedFn = function() {
          // Always call setCurrentContext first to ensure proper event order.
          setCurrentContext(this);
  
          // Enter scope with the arguments of the call.
          var scope = customEvent.apply(null, arguments);
  
          // Call the original method.
          var result = rawFn.apply(this, arguments);
  
          // Return the result and leave the scope.
          return leaveScope(scope, result);
        };
      }
  
      // Swap the method and save a restore function so that we can swap it back.
      instrumentedFn['raw'] = rawFn;
      target[methodName] = instrumentedFn;
      contextRestoreFns.push(function() {
        target[methodName] = rawFn;
      });
    }
docs: Wraps a method on the target prototype with a scoped event.
  Optionally the method can provide a custom callback routine.
  @param {!Object} target Target object/prototype.
  @param {string} targetType Target type name.
  @param {string} signature Event signature.
  @param {Function=} opt_generator Generator function.