2015-09-15 18:38:10 +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 UIManagerStatTracker
|
|
|
|
* @flow
|
2017-09-25 05:57:35 +00:00
|
|
|
* @format
|
2015-09-15 18:38:10 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-11-27 13:39:00 +00:00
|
|
|
var UIManager = require('UIManager');
|
2015-09-15 18:38:10 +00:00
|
|
|
|
|
|
|
var installed = false;
|
|
|
|
var UIManagerStatTracker = {
|
|
|
|
install: function() {
|
|
|
|
if (installed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
installed = true;
|
|
|
|
var statLogHandle;
|
2015-10-06 00:20:02 +00:00
|
|
|
var stats = {};
|
2015-09-15 18:38:10 +00:00
|
|
|
function printStats() {
|
2015-10-06 00:20:02 +00:00
|
|
|
console.log({UIManagerStatTracker: stats});
|
2015-09-15 18:38:10 +00:00
|
|
|
statLogHandle = null;
|
|
|
|
}
|
|
|
|
function incStat(key: string, increment: number) {
|
2015-10-06 00:20:02 +00:00
|
|
|
stats[key] = (stats[key] || 0) + increment;
|
2015-09-15 18:38:10 +00:00
|
|
|
if (!statLogHandle) {
|
2015-10-06 00:20:02 +00:00
|
|
|
statLogHandle = setImmediate(printStats);
|
2015-09-15 18:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-27 13:39:00 +00:00
|
|
|
var createViewOrig = UIManager.createView;
|
|
|
|
UIManager.createView = function(tag, className, rootTag, props) {
|
2015-09-15 18:38:10 +00:00
|
|
|
incStat('createView', 1);
|
|
|
|
incStat('setProp', Object.keys(props || []).length);
|
|
|
|
createViewOrig(tag, className, rootTag, props);
|
|
|
|
};
|
2015-11-27 13:39:00 +00:00
|
|
|
var updateViewOrig = UIManager.updateView;
|
|
|
|
UIManager.updateView = function(tag, className, props) {
|
2015-09-15 18:38:10 +00:00
|
|
|
incStat('updateView', 1);
|
|
|
|
incStat('setProp', Object.keys(props || []).length);
|
|
|
|
updateViewOrig(tag, className, props);
|
|
|
|
};
|
2015-11-27 13:39:00 +00:00
|
|
|
var manageChildrenOrig = UIManager.manageChildren;
|
2017-09-25 05:57:35 +00:00
|
|
|
UIManager.manageChildren = function(
|
|
|
|
tag,
|
|
|
|
moveFrom,
|
|
|
|
moveTo,
|
|
|
|
addTags,
|
|
|
|
addIndices,
|
|
|
|
remove,
|
|
|
|
) {
|
2015-09-15 18:38:10 +00:00
|
|
|
incStat('manageChildren', 1);
|
|
|
|
incStat('move', Object.keys(moveFrom || []).length);
|
|
|
|
incStat('remove', Object.keys(remove || []).length);
|
|
|
|
manageChildrenOrig(tag, moveFrom, moveTo, addTags, addIndices, remove);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = UIManagerStatTracker;
|