|
| 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