Skip to content

Commit 4dca06b

Browse files
sahrensfacebook-github-bot-6
authored andcommitted
UIManagerStatTracker
Reviewed By: @astreet Differential Revision: D2442406
1 parent 178d275 commit 4dca06b

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Libraries/ReactNative/ReactNativeBaseComponent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type ReactNativeBaseComponentViewConfig = {
3535
uiViewClassName: string;
3636
}
3737

38+
// require('UIManagerStatTracker').install(); // uncomment to enable
39+
3840
/**
3941
* @constructor ReactNativeBaseComponent
4042
* @extends ReactComponent
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule UIManagerStatTracker
10+
* @flow
11+
*/
12+
'use strict';
13+
14+
var RCTUIManager = require('NativeModules').UIManager;
15+
16+
var installed = false;
17+
var UIManagerStatTracker = {
18+
install: function() {
19+
if (installed) {
20+
return;
21+
}
22+
installed = true;
23+
var statLogHandle;
24+
var stats = {};
25+
function printStats() {
26+
console.log({UIManagerStatTracker: stats});
27+
statLogHandle = null;
28+
}
29+
function incStat(key: string, increment: number) {
30+
stats[key] = (stats[key] || 0) + increment;
31+
if (!statLogHandle) {
32+
statLogHandle = setImmediate(printStats);
33+
}
34+
}
35+
var createViewOrig = RCTUIManager.createView;
36+
RCTUIManager.createView = function(tag, className, rootTag, props) {
37+
incStat('createView', 1);
38+
incStat('setProp', Object.keys(props || []).length);
39+
createViewOrig(tag, className, rootTag, props);
40+
};
41+
var updateViewOrig = RCTUIManager.updateView;
42+
RCTUIManager.updateView = function(tag, className, props) {
43+
incStat('updateView', 1);
44+
incStat('setProp', Object.keys(props || []).length);
45+
updateViewOrig(tag, className, props);
46+
};
47+
var manageChildrenOrig = RCTUIManager.manageChildren;
48+
RCTUIManager.manageChildren = function(tag, moveFrom, moveTo, addTags, addIndices, remove) {
49+
incStat('manageChildren', 1);
50+
incStat('move', Object.keys(moveFrom || []).length);
51+
incStat('remove', Object.keys(remove || []).length);
52+
manageChildrenOrig(tag, moveFrom, moveTo, addTags, addIndices, remove);
53+
};
54+
},
55+
};
56+
57+
module.exports = UIManagerStatTracker;

0 commit comments

Comments
 (0)