2015-06-02 13:15:53 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @providesModule BridgeProfiling
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var GLOBAL = GLOBAL || this;
|
|
|
|
|
|
|
|
var BridgeProfiling = {
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
profile(profileName?: any, args?: any) {
|
2015-06-02 13:15:53 +00:00
|
|
|
if (GLOBAL.__BridgeProfilingIsProfiling) {
|
|
|
|
if (args) {
|
|
|
|
try {
|
|
|
|
args = JSON.stringify(args);
|
|
|
|
} catch(err) {
|
|
|
|
args = err.message;
|
|
|
|
}
|
|
|
|
}
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
profileName = typeof profileName === 'function' ?
|
|
|
|
profileName() : profileName;
|
2015-06-02 13:15:53 +00:00
|
|
|
console.profile(profileName, args);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-15 20:05:05 +00:00
|
|
|
profileEnd(profileName?: string) {
|
2015-06-02 13:15:53 +00:00
|
|
|
if (GLOBAL.__BridgeProfilingIsProfiling) {
|
2015-06-15 20:05:05 +00:00
|
|
|
console.profileEnd(profileName);
|
2015-06-02 13:15:53 +00:00
|
|
|
}
|
|
|
|
},
|
2015-06-15 20:05:05 +00:00
|
|
|
|
|
|
|
swizzleReactPerf() {
|
|
|
|
var ReactPerf = require('ReactPerf');
|
|
|
|
var originalMeasure = ReactPerf.measure;
|
|
|
|
ReactPerf.measure = function (objName, fnName, func) {
|
|
|
|
func = originalMeasure.call(ReactPerf, objName, fnName, func);
|
|
|
|
return function (component) {
|
|
|
|
BridgeProfiling.profile();
|
|
|
|
var ret = func.apply(this, arguments);
|
|
|
|
if (GLOBAL.__BridgeProfilingIsProfiling) {
|
|
|
|
var name = this._instance && this._instance.constructor &&
|
|
|
|
(this._instance.constructor.displayName ||
|
|
|
|
this._instance.constructor.name);
|
|
|
|
BridgeProfiling.profileEnd(`${objName}.${fnName}(${name})`);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
2015-06-02 13:15:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = BridgeProfiling;
|