remove old heap capture in preparation for pull from tracery-prerelease

Reviewed By: bnham

Differential Revision: D4250926

fbshipit-source-id: 7cfbb8d8aae5ef150f0260c92e946d569e41f7fb
This commit is contained in:
Charles Dick authored and Facebook Github Bot committed 2016-11-30 12:58:35 -08:00
1 parent bed9087191
commit 3094c36c81
6 files changed
-3363

No files matched your search

@@ -1,762 +0,0 @@
/**
* Copyright (c) 2016-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.
*/
'use strict';
/*eslint no-bitwise: "off"*/
/*eslint no-console-disallow: "off"*/
// TODO: future features
// put in a module.exports
// filtering / search
// pivot around frames in the middle of a stack by callers / callees
// graphing?
function StringInterner(){// eslint-disable-line no-unused-vars
var strings=[];
var ids={};
return{
intern:function internString(s){
var find=ids[s];
if(find===undefined){
var id=strings.length;
ids[s]=id;
strings.push(s);
return id;
}else{
return find;
}
},
get:function getString(id){
return strings[id];
}};
}
function StackRegistry(){// eslint-disable-line no-unused-vars
return{
root:{id:0},
nodeCount:1,
maxDepth:-1,
stackIdMap:null,
insert:function insertNode(parent,frameId){
if(this.stackIdMap!==null){
throw'stacks already flattened';
}
var node=parent[frameId];
if(node===undefined){
node={id:this.nodeCount};
this.nodeCount++;
parent[frameId]=node;
}
return node;
},
get:function getStackArray(id){
return this.stackIdMap[id];
},
flatten:function flattenStacks(){
if(this.stackIdMap!==null){
return;
}
var stackFrameCount=0;
function countStacks(tree,depth){
var leaf=true;
for(var frameId in tree){
if(frameId!=='id'){
leaf=countStacks(tree[frameId],depth+1);
}
}
if(leaf){
stackFrameCount+=depth;
}
return false;
}
countStacks(this.root,0);
console.log('size needed to store stacks: '+(stackFrameCount*4).toString()+'B');
var stackIdMap=new Array(this.nodeCount);
var stackArray=new Int32Array(stackFrameCount);
var maxStackDepth=0;
stackFrameCount=0;
function flattenStacksImpl(tree,stack){
var childStack=void 0;
maxStackDepth=Math.max(maxStackDepth,stack.length);
for(var frameId in tree){
if(frameId!=='id'){
stack.push(Number(frameId));
childStack=flattenStacksImpl(tree[frameId],stack);
stack.pop();
}
}
var id=tree.id;
if(id<0||id>=stackIdMap.length||stackIdMap[id]!==undefined){
throw'invalid stack id!';
}
if(childStack!==undefined){
// each child must have our stack as a prefix, so just use that
stackIdMap[id]=childStack.subarray(0,stack.length);
}else{
var newStack=stackArray.subarray(stackFrameCount,stackFrameCount+stack.length);
stackFrameCount+=stack.length;
for(var i=0;i<stack.length;i++){
newStack[i]=stack[i];
}
stackIdMap[id]=newStack;
}
return stackIdMap[id];
}
flattenStacksImpl(this.root,[]);
this.root=null;
this.stackIdMap=stackIdMap;
this.maxDepth=maxStackDepth;
}};
}
function AggrowData(columns){// eslint-disable-line no-unused-vars
var columnCount=columns.length;
var columnConverter=columns.map(function(c){
switch(c.type){
case'int':// stores raw value
return function(i){return i;};
case'string':// stores interned id of string
return function(s){return c.strings.intern(s);};
case'stack':// stores id of stack node
return function(s){return s.id;};
default:
throw'unknown AggrowData column type';}
});
return{
data:new Int32Array(0),
columns:columns,
rowCount:0,
rowInserter:function rowInserter(numRows){
console.log(
'increasing row data from '+(this.data.length*4).toLocaleString()+' B to '+
(this.data.length*4+numRows*columnCount*4).toLocaleString()+' B');
var newData=new Int32Array(this.data.length+numRows*columnCount);
newData.set(this.data);
var currOffset=this.data.length;
var endOffset=newData.length;
this.data=newData;
this.rowCount=newData.length/columnCount;
return{
insertRow:function insertRow(){
if(currOffset>=endOffset){
throw'tried to insert data off end of added range';
}
if(arguments.length!==columnCount){
throw'expected data for '+columnCount.toString()+' columns, got'+
arguments.length.toString()+' columns';
}
for(var i=0;i<arguments.length;i++){
newData[currOffset+i]=columnConverter[i](arguments[i]);
}
currOffset+=columnCount;
},
done:function done(){
if(currOffset!==endOffset){
throw'unfilled rows';
}
}};
}};
}
function Aggrow(aggrowData){
var columns=aggrowData.columns;
var columnCount=columns.length;
var data=aggrowData.data;
function columnIndex(columnName,columnType){
var index=columns.findIndex(function(c){return c.name===columnName&&c.type===columnType;});
if(index<0){
throw'did not find data column '+columnName+' with type '+columnType;
}
return index;
}
for(var i=0;i<columns.length;i++){
if(columns[i].type==='stack'){
columns[i].stacks.flatten();
}
}
return{
expander:new AggrowExpander(aggrowData.rowCount),
addSumAggregator:function addSumAggregator(aggregatorName,columnName){
var index=columnIndex(columnName,'int');
return this.expander.addAggregator(
aggregatorName,
function aggregateSize(indices){
var size=0;
for(var _i=0;_i<indices.length;_i++){
var row=indices[_i];
size+=data[row*columnCount+index];
}
return size;
},
function(value){return value.toLocaleString();},
function(a,b){return b-a;});
},
addCountAggregator:function addCountAggregator(aggregatorName){
return this.expander.addAggregator(
aggregatorName,
function aggregateCount(indices){
return indices.length;
},
function(value){return value.toLocaleString();},
function(a,b){return b-a;});
},
addStringExpander:function addStringExpander(expanderName,columnName){
var index=columnIndex(columnName,'string');
var strings=columns[index].strings;
return this.expander.addFieldExpander(
expanderName,
function(row){return strings.get(data[row*columnCount+index]);},
function(rowA,rowB){return data[rowA*columnCount+index]-data[rowB*columnCount+index];});
},
addNumberExpander:function addNumberExpander(expanderName,columnName){
var index=columnIndex(columnName,'int');
return this.expander.addFieldExpander(
expanderName,
function(row){return data[row*columnCount+index].toLocaleString();},
function(rowA,rowB){return data[rowA*columnCount+index]-data[rowB*columnCount+index];});
},
addPointerExpander:function addPointerExpander(expanderName,columnName){
var index=columnIndex(columnName,'int');
return this.expander.addFieldExpander(
expanderName,
function(row){return'0x'+(data[row*columnCount+index]>>>0).toString();},
function(rowA,rowB){return data[rowA*columnCount+index]-data[rowB*columnCount+index];});
},
addStackExpander:function addStackExpander(expanderName,columnName,formatter){
// TODO: options for caller/callee, pivoting
var index=columnIndex(columnName,'stack');
var stacks=columns[index].stacks;
return this.expander.addCalleeStackExpander(
expanderName,
stacks.maxDepth,
function(row){return stacks.get(data[row*columnCount+index]);},
formatter);
}};
}
function AggrowExpander(numRows){// eslint-disable-line no-unused-vars
// expander ID definitions
var FIELD_EXPANDER_ID_MIN=0x0000;
var FIELD_EXPANDER_ID_MAX=0x7fff;
var STACK_EXPANDER_ID_MIN=0x8000;
var STACK_EXPANDER_ID_MAX=0xffff;
// used for row.expander which reference state.activeExpanders (with frame index masked in)
var INVALID_ACTIVE_EXPANDER=-1;
var ACTIVE_EXPANDER_MASK=0xffff;
var ACTIVE_EXPANDER_FRAME_SHIFT=16;
// aggregator ID definitions
var AGGREGATOR_ID_MAX=0xffff;
// active aggragators can have sort order changed in the reference
var ACTIVE_AGGREGATOR_MASK=0xffff;
var ACTIVE_AGGREGATOR_ASC_BIT=0x10000;
// tree node state definitions
var NODE_EXPANDED_BIT=0x0001;// this row is expanded
var NODE_REAGGREGATE_BIT=0x0002;// children need aggregates
var NODE_REORDER_BIT=0x0004;// children need to be sorted
var NODE_REPOSITION_BIT=0x0008;// children need position
var NODE_INDENT_SHIFT=16;
function calleeFrameIdGetter(stack,depth){
return stack[depth];
}
function callerFrameIdGetter(stack,depth){
return stack[stack.length-depth-1];
}
function createStackComparers(stackGetter,frameIdGetter,maxStackDepth){
var comparers=new Array(maxStackDepth);var _loop=function _loop(
depth){
var captureDepth=depth;// NB: to capture depth per loop iteration
comparers[depth]=function calleeStackComparer(rowA,rowB){
var a=stackGetter(rowA);
var b=stackGetter(rowB);
// NB: we put the stacks that are too short at the top,
// so they can be grouped into the '<exclusive>' bucket
if(a.length<=captureDepth&&b.length<=captureDepth){
return 0;
}else if(a.length<=captureDepth){
return-1;
}else if(b.length<=captureDepth){
return 1;
}
return frameIdGetter(a,captureDepth)-frameIdGetter(b,captureDepth);
};};for(var depth=0;depth<maxStackDepth;depth++){_loop(depth);
}
return comparers;
}
function createTreeNode(parent,label,indices,expander){
var indent=parent===null?0:(parent.state>>>NODE_INDENT_SHIFT)+1;
var state=NODE_REPOSITION_BIT|
NODE_REAGGREGATE_BIT|
NODE_REORDER_BIT|
indent<<NODE_INDENT_SHIFT;
return{
parent:parent,// null if root
children:null,// array of children nodes
label:label,// string to show in UI
indices:indices,// row indices under this node
aggregates:null,// result of aggregate on indices
expander:expander,// index into state.activeExpanders
top:0,// y position of top row (in rows)
height:1,// number of rows including children
state:state};
}
function noSortOrder(a,b){
return 0;
}
var indices=new Int32Array(numRows);
for(var i=0;i<numRows;i++){
indices[i]=i;
}
var state={
fieldExpanders:[],// tree expanders that expand on simple values
stackExpanders:[],// tree expanders that expand stacks
activeExpanders:[],// index into field or stack expanders, hierarchy of tree
aggregators:[],// all available aggregators, might not be used
activeAggregators:[],// index into aggregators, to actually compute
sorter:noSortOrder,// compare function that uses sortOrder to sort row.children
root:createTreeNode(null,'<root>',indices,INVALID_ACTIVE_EXPANDER)};
function evaluateAggregate(row){
var activeAggregators=state.activeAggregators;
var aggregates=new Array(activeAggregators.length);
for(var j=0;j<activeAggregators.length;j++){
var aggregator=state.aggregators[activeAggregators[j]];
aggregates[j]=aggregator.aggregator(row.indices);
}
row.aggregates=aggregates;
row.state|=NODE_REAGGREGATE_BIT;
}
function evaluateAggregates(row){
if((row.state&NODE_EXPANDED_BIT)!==0){
var children=row.children;
for(var _i2=0;_i2<children.length;_i2++){
evaluateAggregate(children[_i2]);
}
row.state|=NODE_REORDER_BIT;
}
row.state^=NODE_REAGGREGATE_BIT;
}
function evaluateOrder(row){
if((row.state&NODE_EXPANDED_BIT)!==0){
var children=row.children;
for(var _i3=0;_i3<children.length;_i3++){
var child=children[_i3];
child.state|=NODE_REORDER_BIT;
}
children.sort(state.sorter);
row.state|=NODE_REPOSITION_BIT;
}
row.state^=NODE_REORDER_BIT;
}
function evaluatePosition(row){
if((row.state&NODE_EXPANDED_BIT)!==0){
var children=row.children;
var childTop=row.top+1;
for(var _i4=0;_i4<children.length;_i4++){
var child=children[_i4];
if(child.top!==childTop){
child.top=childTop;
child.state|=NODE_REPOSITION_BIT;
}
childTop+=child.height;
}
}
row.state^=NODE_REPOSITION_BIT;
}
function getRowsImpl(row,top,height,result){
if((row.state&NODE_REAGGREGATE_BIT)!==0){
evaluateAggregates(row);
}
if((row.state&NODE_REORDER_BIT)!==0){
evaluateOrder(row);
}
if((row.state&NODE_REPOSITION_BIT)!==0){
evaluatePosition(row);
}
if(row.top>=top&&row.top<top+height){
if(result[row.top-top]!=null){
throw'getRows put more than one row at position '+row.top+' into result';
}
result[row.top-top]=row;
}
if((row.state&NODE_EXPANDED_BIT)!==0){
var children=row.children;
for(var _i5=0;_i5<children.length;_i5++){
var child=children[_i5];
if(child.top<top+height&&top<child.top+child.height){
getRowsImpl(child,top,height,result);
}
}
}
}
function updateHeight(row,heightChange){
while(row!==null){
row.height+=heightChange;
row.state|=NODE_REPOSITION_BIT;
row=row.parent;
}
}
function addChildrenWithFieldExpander(row,expander,nextActiveIndex){
var rowIndices=row.indices;
var comparer=expander.comparer;
rowIndices.sort(comparer);
var begin=0;
var end=1;
row.children=[];
while(end<rowIndices.length){
if(comparer(rowIndices[begin],rowIndices[end])!==0){
row.children.push(createTreeNode(
row,
expander.name+': '+expander.formatter(rowIndices[begin]),
rowIndices.subarray(begin,end),
nextActiveIndex));
begin=end;
}
end++;
}
row.children.push(createTreeNode(
row,
expander.name+': '+expander.formatter(rowIndices[begin]),
rowIndices.subarray(begin,end),
nextActiveIndex));
}
function addChildrenWithStackExpander(row,expander,activeIndex,depth,nextActiveIndex){
var rowIndices=row.indices;
var stackGetter=expander.stackGetter;
var frameIdGetter=expander.frameIdGetter;
var frameGetter=expander.frameGetter;
var comparer=expander.comparers[depth];
var expandNextFrame=activeIndex|depth+1<<ACTIVE_EXPANDER_FRAME_SHIFT;
rowIndices.sort(comparer);
var columnName='';
if(depth===0){
columnName=expander.name+': ';
}
// put all the too-short stacks under <exclusive>
var begin=0;
var beginStack=null;
row.children=[];
while(begin<rowIndices.length){
beginStack=stackGetter(rowIndices[begin]);
if(beginStack.length>depth){
break;
}
begin++;
}
if(begin>0){
row.children.push(createTreeNode(
row,
columnName+'<exclusive>',
rowIndices.subarray(0,begin),
nextActiveIndex));
}
// aggregate the rest under frames
if(begin<rowIndices.length){
var end=begin+1;
while(end<rowIndices.length){
var endStack=stackGetter(rowIndices[end]);
if(frameIdGetter(beginStack,depth)!==frameIdGetter(endStack,depth)){
row.children.push(createTreeNode(
row,
columnName+frameGetter(frameIdGetter(beginStack,depth)),
rowIndices.subarray(begin,end),
expandNextFrame));
begin=end;
beginStack=endStack;
}
end++;
}
row.children.push(createTreeNode(
row,
columnName+frameGetter(frameIdGetter(beginStack,depth)),
rowIndices.subarray(begin,end),
expandNextFrame));
}
}
function contractRow(row){
if((row.state&NODE_EXPANDED_BIT)===0){
throw'can not contract row, already contracted';
}
row.state^=NODE_EXPANDED_BIT;
var heightChange=1-row.height;
updateHeight(row,heightChange);
}
function pruneExpanders(row,oldExpander,newExpander){
row.state|=NODE_REPOSITION_BIT;
if(row.expander===oldExpander){
row.state|=NODE_REAGGREGATE_BIT|NODE_REORDER_BIT|NODE_REPOSITION_BIT;
if((row.state&NODE_EXPANDED_BIT)!==0){
contractRow(row);
}
row.children=null;
row.expander=newExpander;
}else{
row.state|=NODE_REPOSITION_BIT;
var children=row.children;
if(children!=null){
for(var _i6=0;_i6<children.length;_i6++){
var child=children[_i6];
pruneExpanders(child,oldExpander,newExpander);
}
}
}
}
return{
addFieldExpander:function addFieldExpander(name,formatter,comparer){
if(FIELD_EXPANDER_ID_MIN+state.fieldExpanders.length>=FIELD_EXPANDER_ID_MAX){
throw'too many field expanders!';
}
state.fieldExpanders.push({
name:name,// name for column
formatter:formatter,// row index -> display string
comparer:comparer});
return FIELD_EXPANDER_ID_MIN+state.fieldExpanders.length-1;
},
addCalleeStackExpander:function addCalleeStackExpander(name,maxStackDepth,stackGetter,frameGetter){
if(STACK_EXPANDER_ID_MIN+state.fieldExpanders.length>=STACK_EXPANDER_ID_MAX){
throw'too many stack expanders!';
}
state.stackExpanders.push({
name:name,// name for column
stackGetter:stackGetter,// row index -> stack array
comparers:createStackComparers(stackGetter,calleeFrameIdGetter,maxStackDepth),// depth -> comparer
frameIdGetter:calleeFrameIdGetter,// (stack, depth) -> string id
frameGetter:frameGetter});
return STACK_EXPANDER_ID_MIN+state.stackExpanders.length-1;
},
addCallerStackExpander:function addCallerStackExpander(name,maxStackDepth,stackGetter,frameGetter){
if(STACK_EXPANDER_ID_MIN+state.fieldExpanders.length>=STACK_EXPANDER_ID_MAX){
throw'too many stack expanders!';
}
state.stackExpanders.push({
name:name,
stackGetter:stackGetter,
comparers:createStackComparers(stackGetter,callerFrameIdGetter,maxStackDepth),
frameIdGetter:callerFrameIdGetter,
frameGetter:frameGetter});
return STACK_EXPANDER_ID_MIN+state.stackExpanders.length-1;
},
getExpanders:function getExpanders(){
var expanders=[];
for(var _i7=0;_i7<state.fieldExpanders.length;_i7++){
expanders.push(FIELD_EXPANDER_ID_MIN+_i7);
}
for(var _i8=0;_i8<state.stackExpanders.length;_i8++){
expanders.push(STACK_EXPANDER_ID_MIN+_i8);
}
return expanders;
},
getExpanderName:function getExpanderName(id){
if(id>=FIELD_EXPANDER_ID_MIN&&id<=FIELD_EXPANDER_ID_MAX){
return state.fieldExpanders[id-FIELD_EXPANDER_ID_MIN].name;
}else if(id>=STACK_EXPANDER_ID_MIN&&id<=STACK_EXPANDER_ID_MAX){
return state.stackExpanders[id-STACK_EXPANDER_ID_MIN].name;
}
throw'Unknown expander ID '+id.toString();
},
setActiveExpanders:function setActiveExpanders(ids){
for(var _i9=0;_i9<ids.length;_i9++){
var id=ids[_i9];
if(id>=FIELD_EXPANDER_ID_MIN&&id<=FIELD_EXPANDER_ID_MAX){
if(id-FIELD_EXPANDER_ID_MIN>=state.fieldExpanders.length){
throw'field expander for id '+id.toString()+' does not exist!';
}
}else if(id>=STACK_EXPANDER_ID_MIN&&id<=STACK_EXPANDER_ID_MAX){
if(id-STACK_EXPANDER_ID_MIN>=state.stackExpanders.length){
throw'stack expander for id '+id.toString()+' does not exist!';
}
}
}
for(var _i10=0;_i10<ids.length;_i10++){
if(state.activeExpanders.length<=_i10){
pruneExpanders(state.root,INVALID_ACTIVE_EXPANDER,_i10);
break;
}else if(ids[_i10]!==state.activeExpanders[_i10]){
pruneExpanders(state.root,_i10,_i10);
break;
}
}
// TODO: if ids is prefix of activeExpanders, we need to make an expander invalid
state.activeExpanders=ids.slice();
},
getActiveExpanders:function getActiveExpanders(){
return state.activeExpanders.slice();
},
addAggregator:function addAggregator(name,aggregator,formatter,sorter){
if(state.aggregators.length>=AGGREGATOR_ID_MAX){
throw'too many aggregators!';
}
state.aggregators.push({
name:name,// name for column
aggregator:aggregator,// index array -> aggregate value
formatter:formatter,// aggregate value -> display string
sorter:sorter});
return state.aggregators.length-1;
},
getAggregators:function getAggregators(){
var aggregators=[];
for(var _i11=0;_i11<state.aggregators.length;_i11++){
aggregators.push(_i11);
}
return aggregators;
},
getAggregatorName:function getAggregatorName(id){
return state.aggregators[id&ACTIVE_AGGREGATOR_MASK].name;
},
setActiveAggregators:function setActiveAggregators(ids){
for(var _i12=0;_i12<ids.length;_i12++){
var id=ids[_i12]&ACTIVE_AGGREGATOR_MASK;
if(id<0||id>state.aggregators.length){
throw'aggregator id '+id.toString()+' not valid';
}
}
state.activeAggregators=ids.slice();
// NB: evaluate root here because dirty bit is for children
// so someone has to start with root, and it might as well be right away
evaluateAggregate(state.root);
var sorter=noSortOrder;var _loop2=function _loop2(
_i13){
var ascending=(ids[_i13]&ACTIVE_AGGREGATOR_ASC_BIT)!==0;
var id=ids[_i13]&ACTIVE_AGGREGATOR_MASK;
var comparer=state.aggregators[id].sorter;
var captureSorter=sorter;
var captureIndex=_i13;
sorter=function sorter(a,b){
var c=comparer(a.aggregates[captureIndex],b.aggregates[captureIndex]);
if(c===0){
return captureSorter(a,b);
}
return ascending?-c:c;
};};for(var _i13=ids.length-1;_i13>=0;_i13--){_loop2(_i13);
}
state.sorter=sorter;
state.root.state|=NODE_REORDER_BIT;
},
getActiveAggregators:function getActiveAggregators(){
return state.activeAggregators.slice();
},
getRows:function getRows(top,height){
var result=new Array(height);
for(var _i14=0;_i14<height;_i14++){
result[_i14]=null;
}
getRowsImpl(state.root,top,height,result);
return result;
},
getRowLabel:function getRowLabel(row){
return row.label;
},
getRowIndent:function getRowIndent(row){
return row.state>>>NODE_INDENT_SHIFT;
},
getRowAggregate:function getRowAggregate(row,index){
var aggregator=state.aggregators[state.activeAggregators[index]];
return aggregator.formatter(row.aggregates[index]);
},
getHeight:function getHeight(){
return state.root.height;
},
canExpand:function canExpand(row){
return(row.state&NODE_EXPANDED_BIT)===0&&row.expander!==INVALID_ACTIVE_EXPANDER;
},
canContract:function canContract(row){
return(row.state&NODE_EXPANDED_BIT)!==0;
},
expand:function expand(row){
if((row.state&NODE_EXPANDED_BIT)!==0){
throw'can not expand row, already expanded';
}
if(row.height!==1){
throw'unexpanded row has height '+row.height.toString()+' != 1';
}
if(row.children===null){// first expand, generate children
var activeIndex=row.expander&ACTIVE_EXPANDER_MASK;
var nextActiveIndex=activeIndex+1;// NB: if next is stack, frame is 0
if(nextActiveIndex>=state.activeExpanders.length){
nextActiveIndex=INVALID_ACTIVE_EXPANDER;
}
if(activeIndex>=state.activeExpanders.length){
throw'invalid active expander index '+activeIndex.toString();
}
var exId=state.activeExpanders[activeIndex];
if(exId>=FIELD_EXPANDER_ID_MIN&&
exId<FIELD_EXPANDER_ID_MIN+state.fieldExpanders.length){
var expander=state.fieldExpanders[exId-FIELD_EXPANDER_ID_MIN];
addChildrenWithFieldExpander(row,expander,nextActiveIndex);
}else if(exId>=STACK_EXPANDER_ID_MIN&&
exId<STACK_EXPANDER_ID_MIN+state.stackExpanders.length){
var depth=row.expander>>>ACTIVE_EXPANDER_FRAME_SHIFT;
var _expander=state.stackExpanders[exId-STACK_EXPANDER_ID_MIN];
addChildrenWithStackExpander(row,_expander,activeIndex,depth,nextActiveIndex);
}else{
throw'state.activeIndex '+activeIndex.toString()+
' has invalid expander'+exId.toString();
}
}
row.state|=NODE_EXPANDED_BIT|
NODE_REAGGREGATE_BIT|NODE_REORDER_BIT|NODE_REPOSITION_BIT;
var heightChange=0;
for(var _i15=0;_i15<row.children.length;_i15++){
heightChange+=row.children[_i15].height;
}
updateHeight(row,heightChange);
// if children only contains one node, then expand it as well
if(row.children.length===1&&this.canExpand(row.children[0])){
this.expand(row.children[0]);
}
},
contract:function contract(row){
contractRow(row);
}};
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9hZ2dyb3cuanMiXSwibmFtZXMiOlsiU3RyaW5nSW50ZXJuZXIiLCJzdHJpbmdzIiwiaWRzIiwiaW50ZXJuIiwiaW50ZXJuU3RyaW5nIiwicyIsImZpbmQiLCJ1bmRlZmluZWQiLCJpZCIsImxlbmd0aCIsInB1c2giLCJnZXQiLCJnZXRTdHJpbmciLCJTdGFja1JlZ2lzdHJ5Iiwicm9vdCIsIm5vZGVDb3VudCIsIm1heERlcHRoIiwic3RhY2tJZE1hcCIsImluc2VydCIsImluc2VydE5vZGUiLCJwYXJlbnQiLCJmcmFtZUlkIiwibm9kZSIsImdldFN0YWNrQXJyYXkiLCJmbGF0dGVuIiwiZmxhdHRlblN0YWNrcyIsInN0YWNrRnJhbWVDb3VudCIsImNvdW50U3RhY2tzIiwidHJlZSIsImRlcHRoIiwibGVhZiIsImNvbnNvbGUiLCJsb2ciLCJ0b1N0cmluZyIsIkFycmF5Iiwic3RhY2tBcnJheSIsIkludDMyQXJyYXkiLCJtYXhTdGFja0RlcHRoIiwiZmxhdHRlblN0YWNrc0ltcGwiLCJzdGFjayIsImNoaWxkU3RhY2siLCJNYXRoIiwibWF4IiwiTnVtYmVyIiwicG9wIiwic3ViYXJyYXkiLCJuZXdTdGFjayIsImkiLCJBZ2dyb3dEYXRhIiwiY29sdW1ucyIsImNvbHVtbkNvdW50IiwiY29sdW1uQ29udmVydGVyIiwibWFwIiwiYyIsInR5cGUiLCJkYXRhIiwicm93Q291bnQiLCJyb3dJbnNlcnRlciIsIm51bVJvd3MiLCJ0b0xvY2FsZVN0cmluZyIsIm5ld0RhdGEiLCJzZXQi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GLENBWEk7QUFZTEssSUFBSyxRQUFTQyxVQUFULENBQW1CSixFQUFuQixDQUF1QjtBQUMxQixNQUFPUCxTQUFRTyxFQUFSLENBQVA7QUFDRCxDQWRJLENBQVA7O0FBZ0JEOztBQUVELFFBQVNLLGNBQVQsRUFBeUIsQ0FBRTtBQUN6QixNQUFPO0FBQ0xDLEtBQU0sQ0FBRU4sR0FBSSxDQUFOLENBREQ7QUFFTE8sVUFBVyxDQUZOO0FBR0xDLFNBQVUsQ0FBQyxDQUhOO0FBSUxDLFdBQVksSUFKUDtBQUtMQyxPQUFRLFFBQVNDLFdBQVQsQ0FBb0JDLE1BQXBCLENBQTRCQyxPQUE1QixDQUFxQztBQUMzQyxHQUFJLEtBQUtKLFVBQUwsR0FBb0IsSUFBeEIsQ0FBOEI7QUFDNUIsS0FBTSwwQkFBTjtBQUNEO0FBQ0QsR0FBSUssTUFBT0YsT0FBT0MsT0FBUCxDQUFYO0FBQ0EsR0FBSUMsT0FBU2YsU0FBYixDQUF3QjtBQUN0QmUsS0FBTyxDQUFFZCxHQUFJLEtBQUtPLFNBQVgsQ0FBUDtBQUNBLEtBQUtBLFNBQUw7QUFDQUssT0FBT0MsT0FBUCxFQUFrQkMsSUFBbEI7QUFDRDtBQUNELE1BQU9BLEtBQVA7QUFDRCxDQWhCSTtBQWlCTFgsSUFBSyxRQUFTWSxjQUFULENBQXVCZixFQUF2QixDQUEyQjtBQUM5QixNQUFPLE1BQUtTLFVBQUwsQ0FBZ0JULEVBQWhCLENBQVA7QUFDRCxDQW5CSTtBQW9CTGdCLFFBQVMsUUFBU0MsY0FBVCxFQUF5QjtBQUNoQyxHQUFJLEtBQUtSLFVBQ Line truncated
// @generated
@@ -1,381 +0,0 @@
/**
* Copyright (c) 2016-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.
*/
'use strict';
/*eslint no-console-disallow: "off"*/
/*global React ReactDOM Table StringInterner StackRegistry AggrowData Aggrow preLoadedCapture:true*/
function RefVisitor(refs,id){
this.refs=refs;
this.id=id;
}
RefVisitor.prototype={
moveToEdge:function moveToEdge(name){
var ref=this.refs[this.id];
if(ref&&ref.edges){
var edges=ref.edges;
for(var edgeId in edges){
if(edges[edgeId]===name){
this.id=edgeId;
return this;
}
}
}
this.id=undefined;
return this;
},
moveToFirst:function moveToFirst(callback){
var ref=this.refs[this.id];
if(ref&&ref.edges){
var edges=ref.edges;
for(var edgeId in edges){
this.id=edgeId;
if(callback(edges[edgeId],this)){
return this;
}
}
}
this.id=undefined;
return this;
},
forEachEdge:function forEachEdge(callback){
var ref=this.refs[this.id];
if(ref&&ref.edges){
var edges=ref.edges;
var visitor=new RefVisitor(this.refs,undefined);
for(var edgeId in edges){
visitor.id=edgeId;
callback(edges[edgeId],visitor);
}
}
},
getType:function getType(){
var ref=this.refs[this.id];
if(ref){
return ref.type;
}
return undefined;
},
getRef:function getRef(){
return this.refs[this.id];
},
clone:function clone(){
return new RefVisitor(this.refs,this.id);
},
isDefined:function isDefined(){
return!!this.id;
},
getValue:function getValue(){var _this=this;
var ref=this.refs[this.id];
if(ref){
if(ref.type==='string'){
if(ref.value){
return ref.value;
}else{var _ret=function(){
var rope=[];
_this.forEachEdge(function(name,visitor){
if(name&&name.startsWith('[')&&name.endsWith(']')){
var index=parseInt(name.substring(1,name.length-1),10);
rope[index]=visitor.getValue();
}
});
return{v:rope.join('')};}();if(typeof _ret==="object")return _ret.v;
}
}else if(ref.type==='ScriptExecutable'||
ref.type==='EvalExecutable'||
ref.type==='ProgramExecutable'){
return ref.value.url+':'+ref.value.line+':'+ref.value.col;
}else if(ref.type==='FunctionExecutable'){
return ref.value.name+'@'+ref.value.url+':'+ref.value.line+':'+ref.value.col;
}else if(ref.type==='NativeExecutable'){
return ref.value.function+' '+ref.value.constructor+' '+ref.value.name;
}else if(ref.type==='Function'){
var executable=this.clone().moveToEdge('@Executable');
if(executable.id){
return executable.getRef().type+' '+executable.getValue();
}
}
}
return'#none';
}};
function forEachRef(refs,callback){
var visitor=new RefVisitor(refs,undefined);
for(var id in refs){
visitor.id=id;
callback(visitor);
}
}
function firstRef(refs,callback){
for(var id in refs){
var ref=refs[id];
if(callback(id,ref)){
return new RefVisitor(refs,id);
}
}
return new RefVisitor(refs,undefined);
}
function getInternalInstanceName(visitor){
var type=visitor.clone().moveToEdge('_currentElement').moveToEdge('type');
if(type.getType()==='string'){// element.type is string
return type.getValue();
}else if(type.getType()==='Function'){// element.type is function
var displayName=type.clone().moveToEdge('displayName');
if(displayName.isDefined()){
return displayName.getValue();// element.type.displayName
}
var name=type.clone().moveToEdge('name');
if(name.isDefined()){
return name.getValue();// element.type.name
}
type.moveToEdge('@Executable');
if(type.getType()==='FunctionExecutable'){
return type.getRef().value.name;// element.type symbolicated name
}
}
return'#unknown';
}
function buildReactComponentTree(visitor,registry,strings){
var ref=visitor.getRef();
if(ref.reactTree||ref.reactParent===undefined){
return;// has one or doesn't need one
}
var parentVisitor=ref.reactParent;
if(parentVisitor===null){
ref.reactTree=registry.insert(registry.root,strings.intern(getInternalInstanceName(visitor)));
}else if(parentVisitor){
var parentRef=parentVisitor.getRef();
buildReactComponentTree(parentVisitor,registry,strings);
var relativeName=getInternalInstanceName(visitor);
if(ref.reactKey){
relativeName=ref.reactKey+': '+relativeName;
}
ref.reactTree=registry.insert(parentRef.reactTree,strings.intern(relativeName));
}else{
throw'non react instance parent of react instance';
}
}
function markReactComponentTree(refs,registry,strings){
// annotate all refs that are react internal instances with their parent and name
// ref.reactParent = visitor that points to parent instance,
// null if we know it's an instance, but don't have a parent yet
// ref.reactKey = if a key is used to distinguish siblings
forEachRef(refs,function(visitor){
var visitorClone=visitor.clone();// visitor will get stomped on next iteration
var ref=visitor.getRef();
visitor.forEachEdge(function(edgeName,edgeVisitor){
var edgeRef=edgeVisitor.getRef();
if(edgeRef){
if(edgeName==='_renderedChildren'){
if(ref.reactParent===undefined){
// ref is react component, even if we don't have a parent yet
ref.reactParent=null;
}
edgeVisitor.forEachEdge(function(childName,childVisitor){
var childRef=childVisitor.getRef();
if(childRef&&childName.startsWith('.')){
childRef.reactParent=visitorClone;
childRef.reactKey=childName;
}
});
}else if(edgeName==='_renderedComponent'){
if(ref.reactParent===undefined){
ref.reactParent=null;
}
edgeRef.reactParent=visitorClone;
}
}
});
});
// build tree of react internal instances (since that's what has the structure)
// fill in ref.reactTree = path registry node
forEachRef(refs,function(visitor){
buildReactComponentTree(visitor,registry,strings);
});
// hook in components by looking at their _reactInternalInstance fields
forEachRef(refs,function(visitor){
var ref=visitor.getRef();
var instanceRef=visitor.moveToEdge('_reactInternalInstance').getRef();
if(instanceRef){
ref.reactTree=instanceRef.reactTree;
}
});
}
function functionUrlFileName(visitor){
var executable=visitor.clone().moveToEdge('@Executable');
var ref=executable.getRef();
if(ref&&ref.value&&ref.value.url){
var url=ref.value.url;
var file=url.substring(url.lastIndexOf('/')+1);
if(file.endsWith('.js')){
file=file.substring(0,file.length-3);
}
return file;
}
return undefined;
}
function markModules(refs){
var modules=firstRef(refs,function(id,ref){return ref.type==='CallbackGlobalObject';});
modules.moveToEdge('require');
modules.moveToFirst(function(name,visitor){return visitor.getType()==='JSActivation';});
modules.moveToEdge('modules');
modules.forEachEdge(function(name,visitor){
var ref=visitor.getRef();
visitor.moveToEdge('exports');
if(visitor.getType()==='Object'){
visitor.moveToFirst(function(memberName,member){return member.getType()==='Function';});
if(visitor.isDefined()){
ref.module=functionUrlFileName(visitor);
}
}else if(visitor.getType()==='Function'){
var displayName=visitor.clone().moveToEdge('displayName');
if(displayName.isDefined()){
ref.module=displayName.getValue();
}
ref.module=functionUrlFileName(visitor);
}
if(ref&&!ref.module){
ref.module='#unknown '+name;
}
});
}
function registerPathToRoot(refs,registry,strings){
markReactComponentTree(refs,registry,strings);
markModules(refs);
var breadth=[];
forEachRef(refs,function(visitor){
var ref=visitor.getRef();
if(ref.type==='CallbackGlobalObject'){
ref.rootPath=registry.insert(registry.root,strings.intern(ref.type));
breadth.push(visitor.clone());
}
});var _loop=function _loop(){
var nextBreadth=[];var _loop2=function _loop2(
i){
var visitor=breadth[i];
var ref=visitor.getRef();
visitor.forEachEdge(function(edgeName,edgeVisitor){
var edgeRef=edgeVisitor.getRef();
if(edgeRef&&edgeRef.rootPath===undefined){
var pathName=edgeRef.type;
if(edgeName){
pathName=edgeName+': '+pathName;
}
edgeRef.rootPath=registry.insert(ref.rootPath,strings.intern(pathName));
nextBreadth.push(edgeVisitor.clone());
// copy module and react tree forward
if(edgeRef.module===undefined){
edgeRef.module=ref.module;
}
if(edgeRef.reactTree===undefined){
edgeRef.reactTree=ref.reactTree;
}
}
});};for(var i=0;i<breadth.length;i++){_loop2(i);
}
breadth=nextBreadth;};while(breadth.length>0){_loop();
}
}
function registerCapture(data,captureId,capture,stacks,strings){
// NB: capture.refs is potentially VERY large, so we try to avoid making
// copies, even if iteration is a bit more annoying.
var rowCount=0;
for(var id in capture.refs){// eslint-disable-line no-unused-vars
rowCount++;
}
for(var _id in capture.markedBlocks){// eslint-disable-line no-unused-vars
rowCount++;
}
var inserter=data.rowInserter(rowCount);
registerPathToRoot(capture.refs,stacks,strings);
var noneString=strings.intern('#none');
var noneStack=stacks.insert(stacks.root,noneString);
forEachRef(capture.refs,function(visitor){
// want to data.append(value, value, value), not IDs
var ref=visitor.getRef();
var id=visitor.id;
inserter.insertRow(
parseInt(id,16),
ref.type,
ref.size,
captureId,
ref.rootPath===undefined?noneStack:ref.rootPath,
ref.reactTree===undefined?noneStack:ref.reactTree,
visitor.getValue(),
ref.module===undefined?'#none':ref.module);
});
for(var _id2 in capture.markedBlocks){
var block=capture.markedBlocks[_id2];
inserter.insertRow(
parseInt(_id2,16),
'Marked Block Overhead',
block.capacity-block.size,
captureId,
noneStack,
noneStack,
'capacity: '+block.capacity+', size: '+block.size+', granularity: '+block.cellSize,
'#none');
}
inserter.done();
}
if(preLoadedCapture){
var strings=StringInterner();
var stacks=new StackRegistry();
var columns=[
{name:'id',type:'int'},
{name:'type',type:'string',strings:strings},
{name:'size',type:'int'},
{name:'trace',type:'string',strings:strings},
{name:'path',type:'stack',stacks:stacks},
{name:'react',type:'stack',stacks:stacks},
{name:'value',type:'string',strings:strings},
{name:'module',type:'string',strings:strings}];
var data=new AggrowData(columns);
registerCapture(data,'trace',preLoadedCapture,stacks,strings);
preLoadedCapture=undefined;// let GG clean up the capture
var aggrow=new Aggrow(data);
aggrow.addPointerExpander('Id','id');
var typeExpander=aggrow.addStringExpander('Type','type');
aggrow.addNumberExpander('Size','size');
aggrow.addStringExpander('Trace','trace');
var pathExpander=aggrow.addStackExpander('Path','path',strings.get);
var reactExpander=aggrow.addStackExpander('React Tree','react',strings.get);
var valueExpander=aggrow.addStringExpander('Value','value');
var moduleExpander=aggrow.addStringExpander('Module','module');
aggrow.expander.setActiveExpanders([
pathExpander,
reactExpander,
moduleExpander,
typeExpander,
valueExpander]);
var sizeAggregator=aggrow.addSumAggregator('Size','size');
var countAggregator=aggrow.addCountAggregator('Count');
aggrow.expander.setActiveAggregators([
sizeAggregator,
countAggregator]);
ReactDOM.render(React.createElement(Table,{aggrow:aggrow.expander}),document.body);
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9oZWFwQ2FwdHVyZS5qcyJdLCJuYW1lcyI6WyJSZWZWaXNpdG9yIiwicmVmcyIsImlkIiwicHJvdG90eXBlIiwibW92ZVRvRWRnZSIsIm5hbWUiLCJyZWYiLCJlZGdlcyIsImVkZ2VJZCIsInVuZGVmaW5lZCIsIm1vdmVUb0ZpcnN0IiwiY2FsbGJhY2siLCJmb3JFYWNoRWRnZSIsInZpc2l0b3IiLCJnZXRUeXBlIiwidHlwZSIsImdldFJlZiIsImNsb25lIiwiaXNEZWZpbmVkIiwiZ2V0VmFsdWUiLCJ2YWx1ZSIsInJvcGUiLCJzdGFydHNXaXRoIiwiZW5kc1dpdGgiLCJpbmRleCIsInBh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UFDbEMsR0FBSVIsTUFBUUEsS0FBS2lCLFVBQUwsQ0FBZ0IsR0FBaEIsQ0FBUixFQUFnQ2pCLEtBQUtrQixRQUFMLENBQWMsR0FBZCxDQUFwQyxDQUF3RDtBQUN0RCxHQUFNQyxPQUFRQyxTQUFTcEIsS0FBS3FCLFNBQUwsQ0FBZSxDQUFmLENBQWtCckIsS0FBS3NCLE1BQUwsQ0FBYyxDQUFoQyxDQUFULENBQTZDLEVBQTdDLENBQWQ7QUFDQU4sS0FBS0csS0FBTCxFQUFjWCxRQUFRTSxRQUFSLEVBQWQ7QUFDRDtBQUNGLENBTEQ7QUFNQ Line truncated
// @generated
@@ -1,541 +0,0 @@
/**
* Copyright (c) 2016-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.
*/
'use strict';
/*eslint no-console-disallow: "off"*/
/*global React:true*/
// TODO:
// selection and arrow keys for navigating
var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}
var rowHeight=20;
var treeIndent=16;var
Draggable=function(_React$Component){_inherits(Draggable,_React$Component);// eslint-disable-line no-unused-vars
function Draggable(props){_classCallCheck(this,Draggable);return _possibleConstructorReturn(this,(Draggable.__proto__||Object.getPrototypeOf(Draggable)).call(this,
props));
}_createClass(Draggable,[{key:'render',value:function render()
{
var id=this.props.id;
return React.cloneElement(
this.props.children,
{
draggable:'true',
onDragStart:function onDragStart(e){
e.dataTransfer.setData('text',id);
}});
}}]);return Draggable;}(React.Component);
Draggable.propTypes={
children:React.PropTypes.element.isRequired,
id:React.PropTypes.string.isRequired};var
DropTarget=function(_React$Component2){_inherits(DropTarget,_React$Component2);// eslint-disable-line no-unused-vars
function DropTarget(props){_classCallCheck(this,DropTarget);return _possibleConstructorReturn(this,(DropTarget.__proto__||Object.getPrototypeOf(DropTarget)).call(this,
props));
}_createClass(DropTarget,[{key:'render',value:function render()
{
var thisId=this.props.id;
var dropAction=this.props.dropAction;
return React.cloneElement(
this.props.children,
{
onDragOver:function onDragOver(e){return e.preventDefault();},
onDrop:function onDrop(e){
var sourceId=e.dataTransfer.getData('text');
e.preventDefault();
dropAction(sourceId,thisId);
}});
}}]);return DropTarget;}(React.Component);
DropTarget.propTypes={
children:React.PropTypes.element.isRequired,
id:React.PropTypes.string.isRequired,
dropAction:React.PropTypes.func.isRequired};var
ExpanderConfiguration=function(_React$Component3){_inherits(ExpanderConfiguration,_React$Component3);
function ExpanderConfiguration(props){_classCallCheck(this,ExpanderConfiguration);return _possibleConstructorReturn(this,(ExpanderConfiguration.__proto__||Object.getPrototypeOf(ExpanderConfiguration)).call(this,
props));
}_createClass(ExpanderConfiguration,[{key:'render',value:function render()
{
var aggrow=this.props.aggrow;
var expander=this.props.expander;
return(
React.createElement(Draggable,{id:'expander:add:'+expander.toString()},
React.createElement('div',{
style:{
width:'auto',
height:'26px',
border:'1px solid darkGray',
margin:'2px'}},
aggrow.getExpanderName(expander))));
}}]);return ExpanderConfiguration;}(React.Component);var
TableConfiguration=function(_React$Component4){_inherits(TableConfiguration,_React$Component4);
function TableConfiguration(props){_classCallCheck(this,TableConfiguration);var _this4=_possibleConstructorReturn(this,(TableConfiguration.__proto__||Object.getPrototypeOf(TableConfiguration)).call(this,
props));
_this4.state={
expanded:false};return _this4;
}_createClass(TableConfiguration,[{key:'renderExpander',value:function renderExpander(
ex){
return React.createElement(ExpanderConfiguration,{aggrow:this.props.aggrow,expander:ex});
}},{key:'render',value:function render()
{var _this5=this;
var expanderText=this.state.expanded?'>>':'<<';
var aggrow=this.props.aggrow;
var config=[];
if(this.state.expanded){
config=aggrow.getExpanders().map(function(ex){return _this5.renderExpander(ex);});
}
return(
React.createElement('div',{style:{
width:this.state.expanded?'512px':'26px',
height:'100%',
display:'flex',
flexDirection:'column',
overflow:'hidden',
borderLeft:'2px solid black'}},
React.createElement('div',{style:{
width:'100%',
height:'26px',
border:'1px solid darkGray'},
onClick:function onClick(e){return _this5.setState({expanded:!_this5.state.expanded});}},
expanderText),
config));
}}]);return TableConfiguration;}(React.Component);
TableConfiguration.propTypes={
aggrow:React.PropTypes.object.isRequired};var
TableHeader=function(_React$Component5){_inherits(TableHeader,_React$Component5);
function TableHeader(props){_classCallCheck(this,TableHeader);return _possibleConstructorReturn(this,(TableHeader.__proto__||Object.getPrototypeOf(TableHeader)).call(this,
props));
}_createClass(TableHeader,[{key:'render',value:function render()
{
var aggrow=this.props.aggrow;
var aggregators=aggrow.getActiveAggregators();
var expanders=aggrow.getActiveExpanders();
var headers=[];
for(var i=0;i<aggregators.length;i++){
var name=aggrow.getAggregatorName(aggregators[i]);
headers.push(
React.createElement(DropTarget,{
id:'aggregate:insert:'+i.toString(),
dropAction:this.props.dropAction},
React.createElement('div',{style:{
width:'16px',
height:'inherit',
backgroundColor:'darkGray',
flexShrink:'0'}})));
headers.push(React.createElement(Draggable,{id:'aggregate:active:'+i.toString()},
React.createElement('div',{style:{width:'128px',textAlign:'center',flexShrink:'0'}},name)));
}
headers.push(
React.createElement(DropTarget,{
id:'divider:insert',
dropAction:this.props.dropAction},
React.createElement('div',{style:{
width:'16px',
height:'inherit',
backgroundColor:'gold',
flexShrink:'0'}})));
for(var _i=0;_i<expanders.length;_i++){
var _name=aggrow.getExpanderName(expanders[_i]);
var bg=_i%2===0?'white':'lightGray';
headers.push(React.createElement(Draggable,{id:'expander:active:'+_i.toString()},
React.createElement('div',{style:{
width:'128px',
textAlign:'center',
backgroundColor:bg,
flexShrink:'0'}},
_name)));
var sep=_i+1<expanders.length?'->':'...';
headers.push(
React.createElement(DropTarget,{
id:'expander:insert:'+(_i+1).toString(),
dropAction:this.props.dropAction},
React.createElement('div',{style:{
height:'inherit',
backgroundColor:'darkGray',
flexShrink:'0'}},
sep)));
}
return(
React.createElement('div',{style:{
width:'100%',
height:'26px',
display:'flex',
flexDirection:'row',
alignItems:'center',
borderBottom:'2px solid black'}},
headers));
}}]);return TableHeader;}(React.Component);
TableHeader.propTypes={
aggrow:React.PropTypes.object.isRequired,
dropAction:React.PropTypes.func.isRequired};var
Table=function(_React$Component6){_inherits(Table,_React$Component6);// eslint-disable-line no-unused-vars
function Table(props){_classCallCheck(this,Table);var _this7=_possibleConstructorReturn(this,(Table.__proto__||Object.getPrototypeOf(Table)).call(this,
props));
_this7.state={
aggrow:props.aggrow,
viewport:{top:0,height:100},
cursor:0};return _this7;
}_createClass(Table,[{key:'scroll',value:function scroll(
e){
var viewport=e.target;
var top=Math.floor((viewport.scrollTop-viewport.clientHeight*1.0)/rowHeight);
var height=Math.ceil(viewport.clientHeight*3.0/rowHeight);
if(top!==this.state.viewport.top||height!==this.state.viewport.height){
this.setState({viewport:{top:top,height:height}});
}
}},{key:'_contractRow',value:function _contractRow(
row){
var newCursor=this.state.cursor;
if(newCursor>row.top&&newCursor<row.top+row.height){// in contracted section
newCursor=row.top;
}else if(newCursor>=row.top+row.height){// below contracted section
newCursor-=row.height-1;
}
this.state.aggrow.contract(row);
this.setState({cursor:newCursor});
console.log('-'+row.top);
}},{key:'_expandRow',value:function _expandRow(
row){
var newCursor=this.state.cursor;
this.state.aggrow.expand(row);
if(newCursor>row.top){// below expanded section
newCursor+=row.height-1;
}
this.setState({cursor:newCursor});
console.log('+'+row.top);
}},{key:'_keepCursorInViewport',value:function _keepCursorInViewport()
{
if(this._scrollDiv){
var cursor=this.state.cursor;
var scrollDiv=this._scrollDiv;
if(cursor*rowHeight<scrollDiv.scrollTop+scrollDiv.clientHeight*0.1){
scrollDiv.scrollTop=cursor*rowHeight-scrollDiv.clientHeight*0.1;
}else if((cursor+1)*rowHeight>scrollDiv.scrollTop+scrollDiv.clientHeight*0.9){
scrollDiv.scrollTop=(cursor+1)*rowHeight-scrollDiv.clientHeight*0.9;
}
}
}},{key:'keydown',value:function keydown(
e){
var aggrow=this.state.aggrow;
var cursor=this.state.cursor;
var row=aggrow.getRows(cursor,1)[0];
switch(e.keyCode){
case 38:// up
if(cursor>0){
this.setState({cursor:cursor-1});
this._keepCursorInViewport();
}
e.preventDefault();
break;
case 40:// down
if(cursor<aggrow.getHeight()-1){
this.setState({cursor:cursor+1});
this._keepCursorInViewport();
}
e.preventDefault();
break;
case 37:// left
if(aggrow.canContract(row)){
this._contractRow(row);
}else if(aggrow.getRowIndent(row)>0){
var indent=aggrow.getRowIndent(row)-1;
while(aggrow.getRowIndent(row)>indent){
cursor--;
row=aggrow.getRows(cursor,1)[0];
}
this.setState({cursor:cursor});
this._keepCursorInViewport();
}
e.preventDefault();
break;
case 39:// right
if(aggrow.canExpand(row)){
this._expandRow(row);
}else if(cursor<aggrow.getHeight()-1){
this.setState({cursor:cursor+1});
this._keepCursorInViewport();
}
e.preventDefault();
break;}
}},{key:'dropAction',value:function dropAction(
s,d){
var aggrow=this.state.aggrow;
console.log('dropped '+s+' to '+d);
if(s.startsWith('aggregate:active:')){
var sIndex=parseInt(s.substr(17),10);
var dIndex=-1;
var active=aggrow.getActiveAggregators();
var dragged=active[sIndex];
if(d.startsWith('aggregate:insert:')){
dIndex=parseInt(d.substr(17),10);
}else if(d==='divider:insert'){
dIndex=active.length;
}else{
throw'not allowed to drag '+s+' to '+d;
}
if(dIndex>sIndex){
dIndex--;
}
active.splice(sIndex,1);
active.splice(dIndex,0,dragged);
aggrow.setActiveAggregators(active);
this.setState({cursor:0});
}else if(s.startsWith('expander:active:')){
var _sIndex=parseInt(s.substr(16),10);
var _dIndex=-1;
var _active=aggrow.getActiveExpanders();
var _dragged=_active[_sIndex];
if(d.startsWith('expander:insert:')){
_dIndex=parseInt(d.substr(16),10);
}else if(d==='divider:insert'){
_dIndex=0;
}else{
throw'not allowed to drag '+s+' to '+d;
}
if(_dIndex>_sIndex){
_dIndex--;
}
_active.splice(_sIndex,1);
_active.splice(_dIndex,0,_dragged);
aggrow.setActiveExpanders(_active);
this.setState({cursor:0});
}else if(s.startsWith('expander:add:')){
var _dIndex2=-1;
var sExpander=parseInt(s.substring(13),10);
if(d.startsWith('expander:insert:')){
_dIndex2=parseInt(d.substr(16),10);
}else if(d==='divider:insert'){
_dIndex2=0;
}else{
throw'not allowed to drag '+s+' to '+d;
}
var _active2=aggrow.getActiveExpanders();
_active2.splice(_dIndex2,0,sExpander);
aggrow.setActiveExpanders(_active2);
this.setState({cursor:0});
}
}},{key:'render',value:function render()
{var _this8=this;
return(
React.createElement('div',{style:{width:'100%',height:'100%',display:'flex',flexDirection:'row'}},
React.createElement('div',{style:{width:'100%',height:'100%',display:'flex',flexDirection:'column',overflow:'hidden'}},
React.createElement(TableHeader,{aggrow:this.state.aggrow,dropAction:function dropAction(s,d){return _this8.dropAction(s,d);}}),
React.createElement('div',{
style:{
width:'100%',
flexGrow:'1',
overflow:'scroll'},
onScroll:function onScroll(e){return _this8.scroll(e);},
ref:function ref(div){_this8._scrollDiv=div;}},
React.createElement('div',{style:{position:'relative'}},
this.renderVirtualizedRows()))),
React.createElement(TableConfiguration,{aggrow:this.state.aggrow})));
}},{key:'renderVirtualizedRows',value:function renderVirtualizedRows()
{var _this9=this;
var aggrow=this.state.aggrow;
var viewport=this.state.viewport;
var rows=aggrow.getRows(viewport.top,viewport.height);
return(
React.createElement('div',{style:{
position:'absolute',
width:'100%',
height:(rowHeight*(aggrow.getHeight()+20)).toString()+'px'}},
rows.map(function(child){return _this9.renderRow(child);})));
}},{key:'renderRow',value:function renderRow(
row){var _this10=this;
if(row===null){
return null;
}
var bg='lightGray';
var aggrow=this.state.aggrow;
var columns=[];
var rowText='';
var indent=4+aggrow.getRowIndent(row)*treeIndent;
var aggregates=aggrow.getActiveAggregators();
if(row.parent!==null&&row.parent.expander%2===0){
bg='white';
}
if(row.top===this.state.cursor){
bg='lightblue';
}
for(var i=0;i<aggregates.length;i++){
var aggregate=aggrow.getRowAggregate(row,i);
columns.push(
React.createElement('div',{style:{
width:'16px',
height:'inherit',
backgroundColor:'darkGray',
flexShrink:'0'}}));
columns.push(
React.createElement('div',{style:{
width:'128px',
textAlign:'right',
flexShrink:'0'}},
aggregate));
}
columns.push(
React.createElement('div',{style:{
width:'16px',
height:'inherit',
backgroundColor:'gold',
flexShrink:'0'}}));
if(aggrow.canExpand(row)){
columns.push(
React.createElement('div',{
style:{
marginLeft:indent.toString()+'px',
flexShrink:'0',
width:'12px',
textAlign:'center',
border:'1px solid gray'},
onClick:function onClick(){return _this10._expandRow(row);}},'+'));
}else if(aggrow.canContract(row)){
columns.push(
React.createElement('div',{
style:{
marginLeft:indent.toString()+'px',
flexShrink:'0',
width:'12px',
textAlign:'center',
border:'1px solid gray'},
onClick:function onClick(){return _this10._contractRow(row);}},'-'));
}else{
columns.push(
React.createElement('div',{
style:{
marginLeft:indent.toString()+'px'}}));
}
rowText+=aggrow.getRowLabel(row);
columns.push(
React.createElement('div',{style:{
flexShrink:'0',
whiteSpace:'nowrap',
marginRight:'20px'}},
rowText));
return(
React.createElement('div',{
key:row.top,
style:{
position:'absolute',
height:(rowHeight-1).toString()+'px',
top:(rowHeight*row.top).toString()+'px',
display:'flex',
flexDirection:'row',
alignItems:'center',
backgroundColor:bg,
borderBottom:'1px solid gray'},
onClick:function onClick(){
_this10.setState({cursor:row.top});
}},
columns));
}},{key:'componentDidMount',value:function componentDidMount()
{
this.keydown=this.keydown.bind(this);
document.body.addEventListener('keydown',this.keydown);
}},{key:'componentWillUnmount',value:function componentWillUnmount()
{
document.body.removeEventListener('keydown',this.keydown);
}}]);return Table;}(React.Component);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy90YWJsZS5qcyJdLCJuYW1lcyI6WyJyb3dIZWlnaHQiLCJ0cmVlSW5kZW50IiwiRHJhZ2dhYmxlIiwicHJvcHMiLCJpZCIsIlJlYWN0IiwiY2xvbmVFbGVtZW50IiwiY2hpbGRyZW4iLCJkcmFnZ2FibGUiLCJvbkRyYWdTdGFydCIsImUiLCJkYXRhVHJhbnNmZXIiLCJzZXREYXRhIiwiQ29tcG9uZW50IiwicHJvcFR5cGVzIiwiUHJvcFR5cGVzIiwiZWxlbWVudCIsImlzUmVxdWlyZWQiLCJzdHJpbmciLCJEcm9wVGFyZ2V0IiwidGhpc0lkIiwiZHJvcEFjdGlvbiIsIm9uRHJhZ092ZXIiLCJwcmV2ZW50RGVmYXVsdCIsIm9uRHJvcCIsInNvdXJjZUlkIiwiZ2V0RGF0YSIsImZ1bmMiLCJFeHBhbmRlckNvbmZpZ3VyYXRpb24iLCJhZ2dyb3ciLCJleHBhbmRlciIsInRvU3RyaW5nIiwid2lkdGgiLCJoZWlnaHQiLCJib3JkZXIiLCJtYXJnaW4iLCJnZXRFeHBhbmRlck5hbWUiLCJUYWJsZUNvbmZpZ3VyYXRpb24iLCJzdGF0ZSIsImV4cGFuZGVkIiwiZXgiLCJleHBhbmRlclRleHQiLCJjb25maWciLCJnZXRFeHBhbmRlcnMiLCJtYXAiLCJyZW5kZXJFeHBhbmRlciIsImRpc3BsYXkiLCJmbGV4RGlyZWN0aW9uIiwib3ZlcmZsb3ciLCJib3JkZXJMZWZ0Iiwic2V0U3RhdGUiLCJvYmplY3QiLCJUY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QUhIO0FBSUxDLE9BQVEsS0FKSCxDQURUOztBQU9HTixPQUFPTyxlQUFQLENBQXVCTixRQUF2QixDQVBILENBREYsQ0FERjs7OztBQWFELEMsbUNBcEJpQ3pCLE1BQU1RLFM7OztBQXVCcEN3QixrQjtBQUNKLDRCQUFZbEMsS0FBWixDQUFtQjtBQUNYQSxLQURXO0FBRWpCLE9BQUttQyxLQUFMLENBQWE7QUFDWEMsU0FBVSxLQURDLENBQWIsQ0FGaUI7O0FBS2xCLEM7QUFDY0MsRSxDQUFJO0FBQ2pCLE1BQVEscUJBQUMscUJBQUQsRUFBdUIsT0FBUSxLQUFLckMsS0FBTCxDQUFXMEIsTUFBMUMsQ0FBa0QsU0FBVVcsRUFBNUQsRUFBUjtBQUNELEM7QUFDUTtBQUNQLEdBQU1DLGNBQWUsS0FBS0gsS0FBTCxDQUFXQyxRQUFYLENBQXNCLElBQXRCLENBQTZCLElBQWxEO0FBQ0EsR0FBTVYsUUFBUyxLQUFLMUIsS0FBTCxDQUFXMEIsTUFBMUI7QUFDQSxHQUFJYSxRQUFTLEVBQWI7QUFDQSxHQUFJLEtBQUtKLEtBQUwsQ0FBV0MsUUFBZixDQUF5QjtBQUN2QkcsT0FBU2IsT0FBT2MsWUFBUCxHQUFzQkMsR0FBdEIsQ0FBMEIsU0FBQ0osRUFBRCxRQUFRLFFBQUtLLGNBQUwsQ0FBb0JMLEVBQXBCLENBQVIsRUFBMUIsQ0FBVDtBQUNEO0FBQ0Q7QUFDRSwyQkFBSyxNQUFPO0FBQ1JSLE1BQU8sS0FBS00sS0FBTCxDQUFXQyxRQUFYLENBQXNCLE9BQXRCLENBQWdDLE1BRC9CO0FBRVJOLE9BQVEsTUFGQTtBQUdSYSxRQUFTL Line truncated
// @generated
@@ -1,760 +0,0 @@
/**
* Copyright (c) 2016-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.
*/
'use strict';
/*eslint no-bitwise: "off"*/
/*eslint no-console-disallow: "off"*/
// TODO: future features
// put in a module.exports
// filtering / search
// pivot around frames in the middle of a stack by callers / callees
// graphing?
function StringInterner() { // eslint-disable-line no-unused-vars
const strings = [];
const ids = {};
return {
intern: function internString(s) {
const find = ids[s];
if (find === undefined) {
const id = strings.length;
ids[s] = id;
strings.push(s);
return id;
} else {
return find;
}
},
get: function getString(id) {
return strings[id];
},
};
}
function StackRegistry() { // eslint-disable-line no-unused-vars
return {
root: { id: 0 },
nodeCount: 1,
maxDepth: -1,
stackIdMap: null,
insert: function insertNode(parent, frameId) {
if (this.stackIdMap !== null) {
throw 'stacks already flattened';
}
let node = parent[frameId];
if (node === undefined) {
node = { id: this.nodeCount };
this.nodeCount++;
parent[frameId] = node;
}
return node;
},
get: function getStackArray(id) {
return this.stackIdMap[id];
},
flatten: function flattenStacks() {
if (this.stackIdMap !== null) {
return;
}
let stackFrameCount = 0;
function countStacks(tree, depth) {
let leaf = true;
for (const frameId in tree) {
if (frameId !== 'id') {
leaf = countStacks(tree[frameId], depth + 1);
}
}
if (leaf) {
stackFrameCount += depth;
}
return false;
}
countStacks(this.root, 0);
console.log('size needed to store stacks: ' + (stackFrameCount * 4).toString() + 'B');
const stackIdMap = new Array(this.nodeCount);
const stackArray = new Int32Array(stackFrameCount);
let maxStackDepth = 0;
stackFrameCount = 0;
function flattenStacksImpl(tree, stack) {
let childStack;
maxStackDepth = Math.max(maxStackDepth, stack.length);
for (const frameId in tree) {
if (frameId !== 'id') {
stack.push(Number(frameId));
childStack = flattenStacksImpl(tree[frameId], stack);
stack.pop();
}
}
const id = tree.id;
if (id < 0 || id >= stackIdMap.length || stackIdMap[id] !== undefined) {
throw 'invalid stack id!';
}
if (childStack !== undefined) {
// each child must have our stack as a prefix, so just use that
stackIdMap[id] = childStack.subarray(0, stack.length);
} else {
const newStack = stackArray.subarray(stackFrameCount, stackFrameCount + stack.length);
stackFrameCount += stack.length;
for (let i = 0; i < stack.length; i++) {
newStack[i] = stack[i];
}
stackIdMap[id] = newStack;
}
return stackIdMap[id];
}
flattenStacksImpl(this.root, []);
this.root = null;
this.stackIdMap = stackIdMap;
this.maxDepth = maxStackDepth;
},
};
}
function AggrowData(columns) { // eslint-disable-line no-unused-vars
const columnCount = columns.length;
const columnConverter = columns.map(c => {
switch (c.type) {
case 'int': // stores raw value
return (i) => i;
case 'string': // stores interned id of string
return (s) => c.strings.intern(s);
case 'stack': // stores id of stack node
return (s) => s.id;
default:
throw 'unknown AggrowData column type';
}
});
return {
data: new Int32Array(0),
columns: columns,
rowCount: 0,
rowInserter: function rowInserter(numRows) {
console.log(
'increasing row data from ' + (this.data.length * 4).toLocaleString() + ' B to ' +
(this.data.length * 4 + numRows * columnCount * 4).toLocaleString() + ' B'
);
const newData = new Int32Array(this.data.length + numRows * columnCount);
newData.set(this.data);
let currOffset = this.data.length;
const endOffset = newData.length;
this.data = newData;
this.rowCount = newData.length / columnCount;
return {
insertRow: function insertRow() {
if (currOffset >= endOffset) {
throw 'tried to insert data off end of added range';
}
if (arguments.length !== columnCount) {
throw 'expected data for ' + columnCount.toString() + ' columns, got' +
arguments.length.toString() + ' columns';
}
for (let i = 0; i < arguments.length; i++) {
newData[currOffset + i] = columnConverter[i](arguments[i]);
}
currOffset += columnCount;
},
done: function done() {
if (currOffset !== endOffset) {
throw 'unfilled rows';
}
},
};
},
};
}
function Aggrow(aggrowData) {
const columns = aggrowData.columns;
const columnCount = columns.length;
const data = aggrowData.data;
function columnIndex(columnName, columnType) {
const index = columns.findIndex(c => c.name === columnName && c.type === columnType);
if (index < 0) {
throw 'did not find data column ' + columnName + ' with type ' + columnType;
}
return index;
}
for (let i = 0; i < columns.length; i++) {
if (columns[i].type === 'stack') {
columns[i].stacks.flatten();
}
}
return {
expander: new AggrowExpander(aggrowData.rowCount),
addSumAggregator: function addSumAggregator(aggregatorName, columnName) {
const index = columnIndex(columnName, 'int');
return this.expander.addAggregator(
aggregatorName,
function aggregateSize(indices) {
let size = 0;
for (let i = 0; i < indices.length; i++) {
const row = indices[i];
size += data[row * columnCount + index];
}
return size;
},
(value) => value.toLocaleString(),
(a, b) => b - a,
);
},
addCountAggregator: function addCountAggregator(aggregatorName) {
return this.expander.addAggregator(
aggregatorName,
function aggregateCount(indices) {
return indices.length;
},
(value) => value.toLocaleString(),
(a, b) => b - a,
);
},
addStringExpander: function addStringExpander(expanderName, columnName) {
const index = columnIndex(columnName, 'string');
const strings = columns[index].strings;
return this.expander.addFieldExpander(
expanderName,
(row) => strings.get(data[row * columnCount + index]),
(rowA, rowB) => data[rowA * columnCount + index] - data[rowB * columnCount + index],
);
},
addNumberExpander: function addNumberExpander(expanderName, columnName) {
const index = columnIndex(columnName, 'int');
return this.expander.addFieldExpander(
expanderName,
(row) => data[row * columnCount + index].toLocaleString(),
(rowA, rowB) => data[rowA * columnCount + index] - data[rowB * columnCount + index],
);
},
addPointerExpander: function addPointerExpander(expanderName, columnName) {
const index = columnIndex(columnName, 'int');
return this.expander.addFieldExpander(
expanderName,
(row) => '0x' + (data[row * columnCount + index] >>> 0).toString(),
(rowA, rowB) => data[rowA * columnCount + index] - data[rowB * columnCount + index],
);
},
addStackExpander: function addStackExpander(expanderName, columnName, formatter) {
// TODO: options for caller/callee, pivoting
const index = columnIndex(columnName, 'stack');
const stacks = columns[index].stacks;
return this.expander.addCalleeStackExpander(
expanderName,
stacks.maxDepth,
(row) => stacks.get(data[row * columnCount + index]),
formatter,
);
},
};
}
function AggrowExpander(numRows) { // eslint-disable-line no-unused-vars
// expander ID definitions
const FIELD_EXPANDER_ID_MIN = 0x0000;
const FIELD_EXPANDER_ID_MAX = 0x7fff;
const STACK_EXPANDER_ID_MIN = 0x8000;
const STACK_EXPANDER_ID_MAX = 0xffff;
// used for row.expander which reference state.activeExpanders (with frame index masked in)
const INVALID_ACTIVE_EXPANDER = -1;
const ACTIVE_EXPANDER_MASK = 0xffff;
const ACTIVE_EXPANDER_FRAME_SHIFT = 16;
// aggregator ID definitions
const AGGREGATOR_ID_MAX = 0xffff;
// active aggragators can have sort order changed in the reference
const ACTIVE_AGGREGATOR_MASK = 0xffff;
const ACTIVE_AGGREGATOR_ASC_BIT = 0x10000;
// tree node state definitions
const NODE_EXPANDED_BIT = 0x0001; // this row is expanded
const NODE_REAGGREGATE_BIT = 0x0002; // children need aggregates
const NODE_REORDER_BIT = 0x0004; // children need to be sorted
const NODE_REPOSITION_BIT = 0x0008; // children need position
const NODE_INDENT_SHIFT = 16;
function calleeFrameIdGetter(stack, depth) {
return stack[depth];
}
function callerFrameIdGetter(stack, depth) {
return stack[stack.length - depth - 1];
}
function createStackComparers(stackGetter, frameIdGetter, maxStackDepth) {
const comparers = new Array(maxStackDepth);
for (let depth = 0; depth < maxStackDepth; depth++) {
const captureDepth = depth; // NB: to capture depth per loop iteration
comparers[depth] = function calleeStackComparer(rowA, rowB) {
const a = stackGetter(rowA);
const b = stackGetter(rowB);
// NB: we put the stacks that are too short at the top,
// so they can be grouped into the '<exclusive>' bucket
if (a.length <= captureDepth && b.length <= captureDepth) {
return 0;
} else if (a.length <= captureDepth) {
return -1;
} else if (b.length <= captureDepth) {
return 1;
}
return frameIdGetter(a, captureDepth) - frameIdGetter(b, captureDepth);
};
}
return comparers;
}
function createTreeNode(parent, label, indices, expander) {
const indent = parent === null ? 0 : (parent.state >>> NODE_INDENT_SHIFT) + 1;
const state = NODE_REPOSITION_BIT |
NODE_REAGGREGATE_BIT |
NODE_REORDER_BIT |
(indent << NODE_INDENT_SHIFT);
return {
parent: parent, // null if root
children: null, // array of children nodes
label: label, // string to show in UI
indices: indices, // row indices under this node
aggregates: null, // result of aggregate on indices
expander: expander, // index into state.activeExpanders
top: 0, // y position of top row (in rows)
height: 1, // number of rows including children
state: state, // see NODE_* definitions above
};
}
function noSortOrder(a, b) {
return 0;
}
const indices = new Int32Array(numRows);
for (let i = 0; i < numRows; i++) {
indices[i] = i;
}
const state = {
fieldExpanders: [], // tree expanders that expand on simple values
stackExpanders: [], // tree expanders that expand stacks
activeExpanders: [], // index into field or stack expanders, hierarchy of tree
aggregators: [], // all available aggregators, might not be used
activeAggregators: [], // index into aggregators, to actually compute
sorter: noSortOrder, // compare function that uses sortOrder to sort row.children
root: createTreeNode(null, '<root>', indices, INVALID_ACTIVE_EXPANDER),
};
function evaluateAggregate(row) {
const activeAggregators = state.activeAggregators;
const aggregates = new Array(activeAggregators.length);
for (let j = 0; j < activeAggregators.length; j++) {
const aggregator = state.aggregators[activeAggregators[j]];
aggregates[j] = aggregator.aggregator(row.indices);
}
row.aggregates = aggregates;
row.state |= NODE_REAGGREGATE_BIT;
}
function evaluateAggregates(row) {
if ((row.state & NODE_EXPANDED_BIT) !== 0) {
const children = row.children;
for (let i = 0; i < children.length; i++) {
evaluateAggregate(children[i]);
}
row.state |= NODE_REORDER_BIT;
}
row.state ^= NODE_REAGGREGATE_BIT;
}
function evaluateOrder(row) {
if ((row.state & NODE_EXPANDED_BIT) !== 0) {
const children = row.children;
for (let i = 0; i < children.length; i++) {
const child = children[i];
child.state |= NODE_REORDER_BIT;
}
children.sort(state.sorter);
row.state |= NODE_REPOSITION_BIT;
}
row.state ^= NODE_REORDER_BIT;
}
function evaluatePosition(row) {
if ((row.state & NODE_EXPANDED_BIT) !== 0) {
const children = row.children;
let childTop = row.top + 1;
for (let i = 0; i < children.length; i++) {
const child = children[i];
if (child.top !== childTop) {
child.top = childTop;
child.state |= NODE_REPOSITION_BIT;
}
childTop += child.height;
}
}
row.state ^= NODE_REPOSITION_BIT;
}
function getRowsImpl(row, top, height, result) {
if ((row.state & NODE_REAGGREGATE_BIT) !== 0) {
evaluateAggregates(row);
}
if ((row.state & NODE_REORDER_BIT) !== 0) {
evaluateOrder(row);
}
if ((row.state & NODE_REPOSITION_BIT) !== 0) {
evaluatePosition(row);
}
if (row.top >= top && row.top < top + height) {
if (result[row.top - top] != null) {
throw 'getRows put more than one row at position ' + row.top + ' into result';
}
result[row.top - top] = row;
}
if ((row.state & NODE_EXPANDED_BIT) !== 0) {
const children = row.children;
for (let i = 0; i < children.length; i++) {
const child = children[i];
if (child.top < top + height && top < child.top + child.height) {
getRowsImpl(child, top, height, result);
}
}
}
}
function updateHeight(row, heightChange) {
while (row !== null) {
row.height += heightChange;
row.state |= NODE_REPOSITION_BIT;
row = row.parent;
}
}
function addChildrenWithFieldExpander(row, expander, nextActiveIndex) {
const rowIndices = row.indices;
const comparer = expander.comparer;
rowIndices.sort(comparer);
let begin = 0;
let end = 1;
row.children = [];
while (end < rowIndices.length) {
if (comparer(rowIndices[begin], rowIndices[end]) !== 0) {
row.children.push(createTreeNode(
row,
expander.name + ': ' + expander.formatter(rowIndices[begin]),
rowIndices.subarray(begin, end),
nextActiveIndex));
begin = end;
}
end++;
}
row.children.push(createTreeNode(
row,
expander.name + ': ' + expander.formatter(rowIndices[begin]),
rowIndices.subarray(begin, end),
nextActiveIndex));
}
function addChildrenWithStackExpander(row, expander, activeIndex, depth, nextActiveIndex) {
const rowIndices = row.indices;
const stackGetter = expander.stackGetter;
const frameIdGetter = expander.frameIdGetter;
const frameGetter = expander.frameGetter;
const comparer = expander.comparers[depth];
const expandNextFrame = activeIndex | ((depth + 1) << ACTIVE_EXPANDER_FRAME_SHIFT);
rowIndices.sort(comparer);
let columnName = '';
if (depth === 0) {
columnName = expander.name + ': ';
}
// put all the too-short stacks under <exclusive>
let begin = 0;
let beginStack = null;
row.children = [];
while (begin < rowIndices.length) {
beginStack = stackGetter(rowIndices[begin]);
if (beginStack.length > depth) {
break;
}
begin++;
}
if (begin > 0) {
row.children.push(createTreeNode(
row,
columnName + '<exclusive>',
rowIndices.subarray(0, begin),
nextActiveIndex));
}
// aggregate the rest under frames
if (begin < rowIndices.length) {
let end = begin + 1;
while (end < rowIndices.length) {
const endStack = stackGetter(rowIndices[end]);
if (frameIdGetter(beginStack, depth) !== frameIdGetter(endStack, depth)) {
row.children.push(createTreeNode(
row,
columnName + frameGetter(frameIdGetter(beginStack, depth)),
rowIndices.subarray(begin, end),
expandNextFrame));
begin = end;
beginStack = endStack;
}
end++;
}
row.children.push(createTreeNode(
row,
columnName + frameGetter(frameIdGetter(beginStack, depth)),
rowIndices.subarray(begin, end),
expandNextFrame));
}
}
function contractRow(row) {
if ((row.state & NODE_EXPANDED_BIT) === 0) {
throw 'can not contract row, already contracted';
}
row.state ^= NODE_EXPANDED_BIT;
const heightChange = 1 - row.height;
updateHeight(row, heightChange);
}
function pruneExpanders(row, oldExpander, newExpander) {
row.state |= NODE_REPOSITION_BIT;
if (row.expander === oldExpander) {
row.state |= NODE_REAGGREGATE_BIT | NODE_REORDER_BIT | NODE_REPOSITION_BIT;
if ((row.state & NODE_EXPANDED_BIT) !== 0) {
contractRow(row);
}
row.children = null;
row.expander = newExpander;
} else {
row.state |= NODE_REPOSITION_BIT;
const children = row.children;
if (children != null) {
for (let i = 0; i < children.length; i++) {
const child = children[i];
pruneExpanders(child, oldExpander, newExpander);
}
}
}
}
return {
addFieldExpander: function addFieldExpander(name, formatter, comparer) {
if (FIELD_EXPANDER_ID_MIN + state.fieldExpanders.length >= FIELD_EXPANDER_ID_MAX) {
throw 'too many field expanders!';
}
state.fieldExpanders.push({
name: name, // name for column
formatter: formatter, // row index -> display string
comparer: comparer, // compares by two row indices
});
return FIELD_EXPANDER_ID_MIN + state.fieldExpanders.length - 1;
},
addCalleeStackExpander: function addCalleeStackExpander(name, maxStackDepth, stackGetter, frameGetter) {
if (STACK_EXPANDER_ID_MIN + state.fieldExpanders.length >= STACK_EXPANDER_ID_MAX) {
throw 'too many stack expanders!';
}
state.stackExpanders.push({
name: name, // name for column
stackGetter: stackGetter, // row index -> stack array
comparers: createStackComparers(stackGetter, calleeFrameIdGetter, maxStackDepth), // depth -> comparer
frameIdGetter: calleeFrameIdGetter, // (stack, depth) -> string id
frameGetter: frameGetter,
});
return STACK_EXPANDER_ID_MIN + state.stackExpanders.length - 1;
},
addCallerStackExpander: function addCallerStackExpander(name, maxStackDepth, stackGetter, frameGetter) {
if (STACK_EXPANDER_ID_MIN + state.fieldExpanders.length >= STACK_EXPANDER_ID_MAX) {
throw 'too many stack expanders!';
}
state.stackExpanders.push({
name: name,
stackGetter: stackGetter,
comparers: createStackComparers(stackGetter, callerFrameIdGetter, maxStackDepth),
frameIdGetter: callerFrameIdGetter,
frameGetter: frameGetter,
});
return STACK_EXPANDER_ID_MIN + state.stackExpanders.length - 1;
},
getExpanders: function getExpanders() {
const expanders = [];
for (let i = 0; i < state.fieldExpanders.length; i++) {
expanders.push(FIELD_EXPANDER_ID_MIN + i);
}
for (let i = 0; i < state.stackExpanders.length; i++) {
expanders.push(STACK_EXPANDER_ID_MIN + i);
}
return expanders;
},
getExpanderName: function getExpanderName(id) {
if (id >= FIELD_EXPANDER_ID_MIN && id <= FIELD_EXPANDER_ID_MAX) {
return state.fieldExpanders[id - FIELD_EXPANDER_ID_MIN].name;
} else if (id >= STACK_EXPANDER_ID_MIN && id <= STACK_EXPANDER_ID_MAX) {
return state.stackExpanders[id - STACK_EXPANDER_ID_MIN].name;
}
throw 'Unknown expander ID ' + id.toString();
},
setActiveExpanders: function setActiveExpanders(ids) {
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
if (id >= FIELD_EXPANDER_ID_MIN && id <= FIELD_EXPANDER_ID_MAX) {
if (id - FIELD_EXPANDER_ID_MIN >= state.fieldExpanders.length) {
throw 'field expander for id ' + id.toString() + ' does not exist!';
}
} else if (id >= STACK_EXPANDER_ID_MIN && id <= STACK_EXPANDER_ID_MAX) {
if (id - STACK_EXPANDER_ID_MIN >= state.stackExpanders.length) {
throw 'stack expander for id ' + id.toString() + ' does not exist!';
}
}
}
for (let i = 0; i < ids.length; i++) {
if (state.activeExpanders.length <= i) {
pruneExpanders(state.root, INVALID_ACTIVE_EXPANDER, i);
break;
} else if (ids[i] !== state.activeExpanders[i]) {
pruneExpanders(state.root, i, i);
break;
}
}
// TODO: if ids is prefix of activeExpanders, we need to make an expander invalid
state.activeExpanders = ids.slice();
},
getActiveExpanders: function getActiveExpanders() {
return state.activeExpanders.slice();
},
addAggregator: function addAggregator(name, aggregator, formatter, sorter) {
if (state.aggregators.length >= AGGREGATOR_ID_MAX) {
throw 'too many aggregators!';
}
state.aggregators.push({
name: name, // name for column
aggregator: aggregator, // index array -> aggregate value
formatter: formatter, // aggregate value -> display string
sorter: sorter, // compare two aggregate values
});
return state.aggregators.length - 1;
},
getAggregators: function getAggregators() {
const aggregators = [];
for (let i = 0; i < state.aggregators.length; i++) {
aggregators.push(i);
}
return aggregators;
},
getAggregatorName: function getAggregatorName(id) {
return state.aggregators[id & ACTIVE_AGGREGATOR_MASK].name;
},
setActiveAggregators: function setActiveAggregators(ids) {
for (let i = 0; i < ids.length; i++) {
const id = ids[i] & ACTIVE_AGGREGATOR_MASK;
if (id < 0 || id > state.aggregators.length) {
throw 'aggregator id ' + id.toString() + ' not valid';
}
}
state.activeAggregators = ids.slice();
// NB: evaluate root here because dirty bit is for children
// so someone has to start with root, and it might as well be right away
evaluateAggregate(state.root);
let sorter = noSortOrder;
for (let i = ids.length - 1; i >= 0; i--) {
const ascending = (ids[i] & ACTIVE_AGGREGATOR_ASC_BIT) !== 0;
const id = ids[i] & ACTIVE_AGGREGATOR_MASK;
const comparer = state.aggregators[id].sorter;
const captureSorter = sorter;
const captureIndex = i;
sorter = function (a, b) {
const c = comparer(a.aggregates[captureIndex], b.aggregates[captureIndex]);
if (c === 0) {
return captureSorter(a, b);
}
return ascending ? -c : c;
};
}
state.sorter = sorter;
state.root.state |= NODE_REORDER_BIT;
},
getActiveAggregators: function getActiveAggregators() {
return state.activeAggregators.slice();
},
getRows: function getRows(top, height) {
const result = new Array(height);
for (let i = 0; i < height; i++) {
result[i] = null;
}
getRowsImpl(state.root, top, height, result);
return result;
},
getRowLabel: function getRowLabel(row) {
return row.label;
},
getRowIndent: function getRowIndent(row) {
return row.state >>> NODE_INDENT_SHIFT;
},
getRowAggregate: function getRowAggregate(row, index) {
const aggregator = state.aggregators[state.activeAggregators[index]];
return aggregator.formatter(row.aggregates[index]);
},
getHeight: function getHeight() {
return state.root.height;
},
canExpand: function canExpand(row) {
return (row.state & NODE_EXPANDED_BIT) === 0 && (row.expander !== INVALID_ACTIVE_EXPANDER);
},
canContract: function canContract(row) {
return (row.state & NODE_EXPANDED_BIT) !== 0;
},
expand: function expand(row) {
if ((row.state & NODE_EXPANDED_BIT) !== 0) {
throw 'can not expand row, already expanded';
}
if (row.height !== 1) {
throw 'unexpanded row has height ' + row.height.toString() + ' != 1';
}
if (row.children === null) { // first expand, generate children
const activeIndex = row.expander & ACTIVE_EXPANDER_MASK;
let nextActiveIndex = activeIndex + 1; // NB: if next is stack, frame is 0
if (nextActiveIndex >= state.activeExpanders.length) {
nextActiveIndex = INVALID_ACTIVE_EXPANDER;
}
if (activeIndex >= state.activeExpanders.length) {
throw 'invalid active expander index ' + activeIndex.toString();
}
const exId = state.activeExpanders[activeIndex];
if (exId >= FIELD_EXPANDER_ID_MIN &&
exId < FIELD_EXPANDER_ID_MIN + state.fieldExpanders.length) {
const expander = state.fieldExpanders[exId - FIELD_EXPANDER_ID_MIN];
addChildrenWithFieldExpander(row, expander, nextActiveIndex);
} else if (exId >= STACK_EXPANDER_ID_MIN &&
exId < STACK_EXPANDER_ID_MIN + state.stackExpanders.length) {
const depth = row.expander >>> ACTIVE_EXPANDER_FRAME_SHIFT;
const expander = state.stackExpanders[exId - STACK_EXPANDER_ID_MIN];
addChildrenWithStackExpander(row, expander, activeIndex, depth, nextActiveIndex);
} else {
throw 'state.activeIndex ' + activeIndex.toString()
+ ' has invalid expander' + exId.toString();
}
}
row.state |= NODE_EXPANDED_BIT
| NODE_REAGGREGATE_BIT | NODE_REORDER_BIT | NODE_REPOSITION_BIT;
let heightChange = 0;
for (let i = 0; i < row.children.length; i++) {
heightChange += row.children[i].height;
}
updateHeight(row, heightChange);
// if children only contains one node, then expand it as well
if (row.children.length === 1 && this.canExpand(row.children[0])) {
this.expand(row.children[0]);
}
},
contract: function contract(row) {
contractRow(row);
},
};
}
@@ -1,379 +0,0 @@
/**
* Copyright (c) 2016-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.
*/
'use strict';
/*eslint no-console-disallow: "off"*/
/*global React ReactDOM Table StringInterner StackRegistry AggrowData Aggrow preLoadedCapture:true*/
function RefVisitor(refs, id) {
this.refs = refs;
this.id = id;
}
RefVisitor.prototype = {
moveToEdge: function moveToEdge(name) {
const ref = this.refs[this.id];
if (ref && ref.edges) {
const edges = ref.edges;
for (const edgeId in edges) {
if (edges[edgeId] === name) {
this.id = edgeId;
return this;
}
}
}
this.id = undefined;
return this;
},
moveToFirst: function moveToFirst(callback) {
const ref = this.refs[this.id];
if (ref && ref.edges) {
const edges = ref.edges;
for (const edgeId in edges) {
this.id = edgeId;
if (callback(edges[edgeId], this)) {
return this;
}
}
}
this.id = undefined;
return this;
},
forEachEdge: function forEachEdge(callback) {
const ref = this.refs[this.id];
if (ref && ref.edges) {
const edges = ref.edges;
const visitor = new RefVisitor(this.refs, undefined);
for (const edgeId in edges) {
visitor.id = edgeId;
callback(edges[edgeId], visitor);
}
}
},
getType: function getType() {
const ref = this.refs[this.id];
if (ref) {
return ref.type;
}
return undefined;
},
getRef: function getRef() {
return this.refs[this.id];
},
clone: function clone() {
return new RefVisitor(this.refs, this.id);
},
isDefined: function isDefined() {
return !!this.id;
},
getValue: function getValue() {
const ref = this.refs[this.id];
if (ref) {
if (ref.type === 'string') {
if (ref.value) {
return ref.value;
} else {
const rope = [];
this.forEachEdge((name, visitor) => {
if (name && name.startsWith('[') && name.endsWith(']')) {
const index = parseInt(name.substring(1, name.length - 1), 10);
rope[index] = visitor.getValue();
}
});
return rope.join('');
}
} else if (ref.type === 'ScriptExecutable'
|| ref.type === 'EvalExecutable'
|| ref.type === 'ProgramExecutable') {
return ref.value.url + ':' + ref.value.line + ':' + ref.value.col;
} else if (ref.type === 'FunctionExecutable') {
return ref.value.name + '@' + ref.value.url + ':' + ref.value.line + ':' + ref.value.col;
} else if (ref.type === 'NativeExecutable') {
return ref.value.function + ' ' + ref.value.constructor + ' ' + ref.value.name;
} else if (ref.type === 'Function') {
const executable = this.clone().moveToEdge('@Executable');
if (executable.id) {
return executable.getRef().type + ' ' + executable.getValue();
}
}
}
return '#none';
}
};
function forEachRef(refs, callback) {
const visitor = new RefVisitor(refs, undefined);
for (const id in refs) {
visitor.id = id;
callback(visitor);
}
}
function firstRef(refs, callback) {
for (const id in refs) {
const ref = refs[id];
if (callback(id, ref)) {
return new RefVisitor(refs, id);
}
}
return new RefVisitor(refs, undefined);
}
function getInternalInstanceName(visitor) {
const type = visitor.clone().moveToEdge('_currentElement').moveToEdge('type');
if (type.getType() === 'string') { // element.type is string
return type.getValue();
} else if (type.getType() === 'Function') { // element.type is function
const displayName = type.clone().moveToEdge('displayName');
if (displayName.isDefined()) {
return displayName.getValue(); // element.type.displayName
}
const name = type.clone().moveToEdge('name');
if (name.isDefined()) {
return name.getValue(); // element.type.name
}
type.moveToEdge('@Executable');
if (type.getType() === 'FunctionExecutable') {
return type.getRef().value.name; // element.type symbolicated name
}
}
return '#unknown';
}
function buildReactComponentTree(visitor, registry, strings) {
const ref = visitor.getRef();
if (ref.reactTree || ref.reactParent === undefined) {
return; // has one or doesn't need one
}
const parentVisitor = ref.reactParent;
if (parentVisitor === null) {
ref.reactTree = registry.insert(registry.root, strings.intern(getInternalInstanceName(visitor)));
} else if (parentVisitor) {
const parentRef = parentVisitor.getRef();
buildReactComponentTree(parentVisitor, registry, strings);
let relativeName = getInternalInstanceName(visitor);
if (ref.reactKey) {
relativeName = ref.reactKey + ': ' + relativeName;
}
ref.reactTree = registry.insert(parentRef.reactTree, strings.intern(relativeName));
} else {
throw 'non react instance parent of react instance';
}
}
function markReactComponentTree(refs, registry, strings) {
// annotate all refs that are react internal instances with their parent and name
// ref.reactParent = visitor that points to parent instance,
// null if we know it's an instance, but don't have a parent yet
// ref.reactKey = if a key is used to distinguish siblings
forEachRef(refs, (visitor) => {
const visitorClone = visitor.clone(); // visitor will get stomped on next iteration
const ref = visitor.getRef();
visitor.forEachEdge((edgeName, edgeVisitor) => {
const edgeRef = edgeVisitor.getRef();
if (edgeRef) {
if (edgeName === '_renderedChildren') {
if (ref.reactParent === undefined) {
// ref is react component, even if we don't have a parent yet
ref.reactParent = null;
}
edgeVisitor.forEachEdge((childName, childVisitor) => {
const childRef = childVisitor.getRef();
if (childRef && childName.startsWith('.')) {
childRef.reactParent = visitorClone;
childRef.reactKey = childName;
}
});
} else if (edgeName === '_renderedComponent') {
if (ref.reactParent === undefined) {
ref.reactParent = null;
}
edgeRef.reactParent = visitorClone;
}
}
});
});
// build tree of react internal instances (since that's what has the structure)
// fill in ref.reactTree = path registry node
forEachRef(refs, (visitor) => {
buildReactComponentTree(visitor, registry, strings);
});
// hook in components by looking at their _reactInternalInstance fields
forEachRef(refs, (visitor) => {
const ref = visitor.getRef();
const instanceRef = visitor.moveToEdge('_reactInternalInstance').getRef();
if (instanceRef) {
ref.reactTree = instanceRef.reactTree;
}
});
}
function functionUrlFileName(visitor) {
const executable = visitor.clone().moveToEdge('@Executable');
const ref = executable.getRef();
if (ref && ref.value && ref.value.url) {
const url = ref.value.url;
let file = url.substring(url.lastIndexOf('/') + 1);
if (file.endsWith('.js')) {
file = file.substring(0, file.length - 3);
}
return file;
}
return undefined;
}
function markModules(refs) {
const modules = firstRef(refs, (id, ref) => ref.type === 'CallbackGlobalObject');
modules.moveToEdge('require');
modules.moveToFirst((name, visitor) => visitor.getType() === 'JSActivation');
modules.moveToEdge('modules');
modules.forEachEdge((name, visitor) => {
const ref = visitor.getRef();
visitor.moveToEdge('exports');
if (visitor.getType() === 'Object') {
visitor.moveToFirst((memberName, member) => member.getType() === 'Function');
if (visitor.isDefined()) {
ref.module = functionUrlFileName(visitor);
}
} else if (visitor.getType() === 'Function') {
const displayName = visitor.clone().moveToEdge('displayName');
if (displayName.isDefined()) {
ref.module = displayName.getValue();
}
ref.module = functionUrlFileName(visitor);
}
if (ref && !ref.module) {
ref.module = '#unknown ' + name;
}
});
}
function registerPathToRoot(refs, registry, strings) {
markReactComponentTree(refs, registry, strings);
markModules(refs);
let breadth = [];
forEachRef(refs, (visitor) => {
const ref = visitor.getRef();
if (ref.type === 'CallbackGlobalObject') {
ref.rootPath = registry.insert(registry.root, strings.intern(ref.type));
breadth.push(visitor.clone());
}
});
while (breadth.length > 0) {
const nextBreadth = [];
for (let i = 0; i < breadth.length; i++) {
const visitor = breadth[i];
const ref = visitor.getRef();
visitor.forEachEdge((edgeName, edgeVisitor) => {
const edgeRef = edgeVisitor.getRef();
if (edgeRef && edgeRef.rootPath === undefined) {
let pathName = edgeRef.type;
if (edgeName) {
pathName = edgeName + ': ' + pathName;
}
edgeRef.rootPath = registry.insert(ref.rootPath, strings.intern(pathName));
nextBreadth.push(edgeVisitor.clone());
// copy module and react tree forward
if (edgeRef.module === undefined) {
edgeRef.module = ref.module;
}
if (edgeRef.reactTree === undefined) {
edgeRef.reactTree = ref.reactTree;
}
}
});
}
breadth = nextBreadth;
}
}
function registerCapture(data, captureId, capture, stacks, strings) {
// NB: capture.refs is potentially VERY large, so we try to avoid making
// copies, even if iteration is a bit more annoying.
let rowCount = 0;
for (const id in capture.refs) { // eslint-disable-line no-unused-vars
rowCount++;
}
for (const id in capture.markedBlocks) { // eslint-disable-line no-unused-vars
rowCount++;
}
const inserter = data.rowInserter(rowCount);
registerPathToRoot(capture.refs, stacks, strings);
const noneString = strings.intern('#none');
const noneStack = stacks.insert(stacks.root, noneString);
forEachRef(capture.refs, (visitor) => {
// want to data.append(value, value, value), not IDs
const ref = visitor.getRef();
const id = visitor.id;
inserter.insertRow(
parseInt(id, 16),
ref.type,
ref.size,
captureId,
ref.rootPath === undefined ? noneStack : ref.rootPath,
ref.reactTree === undefined ? noneStack : ref.reactTree,
visitor.getValue(),
ref.module === undefined ? '#none' : ref.module,
);
});
for (const id in capture.markedBlocks) {
const block = capture.markedBlocks[id];
inserter.insertRow(
parseInt(id, 16),
'Marked Block Overhead',
block.capacity - block.size,
captureId,
noneStack,
noneStack,
'capacity: ' + block.capacity + ', size: ' + block.size + ', granularity: ' + block.cellSize,
'#none',
);
}
inserter.done();
}
if (preLoadedCapture) {
const strings = StringInterner();
const stacks = new StackRegistry();
const columns = [
{ name: 'id', type: 'int' },
{ name: 'type', type: 'string', strings: strings },
{ name: 'size', type: 'int' },
{ name: 'trace', type: 'string', strings: strings },
{ name: 'path', type: 'stack', stacks: stacks },
{ name: 'react', type: 'stack', stacks: stacks },
{ name: 'value', type: 'string', strings: strings },
{ name: 'module', type: 'string', strings: strings },
];
const data = new AggrowData(columns);
registerCapture(data, 'trace', preLoadedCapture, stacks, strings);
preLoadedCapture = undefined; // let GG clean up the capture
const aggrow = new Aggrow(data);
aggrow.addPointerExpander('Id', 'id');
const typeExpander = aggrow.addStringExpander('Type', 'type');
aggrow.addNumberExpander('Size', 'size');
aggrow.addStringExpander('Trace', 'trace');
const pathExpander = aggrow.addStackExpander('Path', 'path', strings.get);
const reactExpander = aggrow.addStackExpander('React Tree', 'react', strings.get);
const valueExpander = aggrow.addStringExpander('Value', 'value');
const moduleExpander = aggrow.addStringExpander('Module', 'module');
aggrow.expander.setActiveExpanders([
pathExpander,
reactExpander,
moduleExpander,
typeExpander,
valueExpander,
]);
const sizeAggregator = aggrow.addSumAggregator('Size', 'size');
const countAggregator = aggrow.addCountAggregator('Count');
aggrow.expander.setActiveAggregators([
sizeAggregator,
countAggregator,
]);
ReactDOM.render(<Table aggrow={aggrow.expander} />, document.body);
}
@@ -1,540 +0,0 @@
/**
* Copyright (c) 2016-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.
*/
'use strict';
/*eslint no-console-disallow: "off"*/
/*global React:true*/
// TODO:
// selection and arrow keys for navigating
const rowHeight = 20;
const treeIndent = 16;
class Draggable extends React.Component { // eslint-disable-line no-unused-vars
constructor(props) {
super(props);
}
render() {
const id = this.props.id;
return React.cloneElement(
this.props.children,
{
draggable: 'true',
onDragStart: (e) => {
e.dataTransfer.setData('text', id);
},
}
);
}
}
Draggable.propTypes = {
children: React.PropTypes.element.isRequired,
id: React.PropTypes.string.isRequired,
};
class DropTarget extends React.Component { // eslint-disable-line no-unused-vars
constructor(props) {
super(props);
}
render() {
const thisId = this.props.id;
const dropAction = this.props.dropAction;
return React.cloneElement(
this.props.children,
{
onDragOver: (e) => e.preventDefault(),
onDrop: (e) => {
const sourceId = e.dataTransfer.getData('text');
e.preventDefault();
dropAction(sourceId, thisId);
},
}
);
}
}
DropTarget.propTypes = {
children: React.PropTypes.element.isRequired,
id: React.PropTypes.string.isRequired,
dropAction: React.PropTypes.func.isRequired,
};
class ExpanderConfiguration extends React.Component {
constructor(props) {
super(props);
}
render() {
const aggrow = this.props.aggrow;
const expander = this.props.expander;
return (
<Draggable id={'expander:add:' + expander.toString()}>
<div
style={{
width: 'auto',
height: '26px',
border: '1px solid darkGray',
margin: '2px',
}}>
{aggrow.getExpanderName(expander)}
</div>
</Draggable>
);
}
}
class TableConfiguration extends React.Component {
constructor(props) {
super(props);
this.state = {
expanded: false,
};
}
renderExpander(ex) {
return (<ExpanderConfiguration aggrow={this.props.aggrow} expander={ex} />);
}
render() {
const expanderText = this.state.expanded ? '>>' : '<<';
const aggrow = this.props.aggrow;
let config = [];
if (this.state.expanded) {
config = aggrow.getExpanders().map((ex) => this.renderExpander(ex));
}
return (
<div style={{
width: this.state.expanded ? '512px' : '26px',
height: '100%',
display: 'flex',
flexDirection: 'column',
overflow: 'hidden',
borderLeft: '2px solid black',
}}>
<div style={{
width: '100%',
height: '26px',
border: '1px solid darkGray',
}}
onClick={ (e) => this.setState({expanded: !this.state.expanded}) }>
{ expanderText }
</div>
{ config }
</div>
);
}
}
TableConfiguration.propTypes = {
aggrow: React.PropTypes.object.isRequired,
};
class TableHeader extends React.Component {
constructor(props) {
super(props);
}
render() {
const aggrow = this.props.aggrow;
const aggregators = aggrow.getActiveAggregators();
const expanders = aggrow.getActiveExpanders();
const headers = [];
for (let i = 0; i < aggregators.length; i++) {
const name = aggrow.getAggregatorName(aggregators[i]);
headers.push((
<DropTarget
id={'aggregate:insert:' + i.toString()}
dropAction={this.props.dropAction}
>
<div style={{
width: '16px',
height: 'inherit',
backgroundColor: 'darkGray',
flexShrink: '0' }}
></div>
</DropTarget>));
headers.push((<Draggable id={'aggregate:active:' + i.toString()}>
<div style={{ width: '128px', textAlign: 'center', flexShrink: '0' }}>{name}</div>
</Draggable>));
}
headers.push((
<DropTarget
id="divider:insert"
dropAction={this.props.dropAction}
>
<div style={{
width: '16px',
height: 'inherit',
backgroundColor: 'gold',
flexShrink: '0'
}}></div>
</DropTarget>));
for (let i = 0; i < expanders.length; i++) {
const name = aggrow.getExpanderName(expanders[i]);
const bg = (i % 2 === 0) ? 'white' : 'lightGray';
headers.push((<Draggable id={'expander:active:' + i.toString()}>
<div style={{
width: '128px',
textAlign: 'center',
backgroundColor: bg,
flexShrink: '0'
}}>
{name}
</div>
</Draggable>));
const sep = i + 1 < expanders.length ? '->' : '...';
headers.push((
<DropTarget
id={'expander:insert:' + (i + 1).toString()}
dropAction={this.props.dropAction}
>
<div style={{
height: 'inherit',
backgroundColor: 'darkGray',
flexShrink: '0'
}}>
{sep}
</div>
</DropTarget>)
);
}
return (
<div style={{
width: '100%',
height: '26px',
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
borderBottom: '2px solid black',
}}>
{headers}
</div>
);
}
}
TableHeader.propTypes = {
aggrow: React.PropTypes.object.isRequired,
dropAction: React.PropTypes.func.isRequired,
};
class Table extends React.Component { // eslint-disable-line no-unused-vars
constructor(props) {
super(props);
this.state = {
aggrow: props.aggrow,
viewport: { top: 0, height: 100 },
cursor: 0,
};
}
scroll(e) {
const viewport = e.target;
const top = Math.floor((viewport.scrollTop - viewport.clientHeight * 1.0) / rowHeight);
const height = Math.ceil(viewport.clientHeight * 3.0 / rowHeight);
if (top !== this.state.viewport.top || height !== this.state.viewport.height) {
this.setState({viewport: {top, height}});
}
}
_contractRow(row) {
let newCursor = this.state.cursor;
if (newCursor > row.top && newCursor < row.top + row.height) { // in contracted section
newCursor = row.top;
} else if (newCursor >= row.top + row.height) { // below contracted section
newCursor -= row.height - 1;
}
this.state.aggrow.contract(row);
this.setState({cursor: newCursor});
console.log('-' + row.top);
}
_expandRow(row) {
let newCursor = this.state.cursor;
this.state.aggrow.expand(row);
if (newCursor > row.top) { // below expanded section
newCursor += row.height - 1;
}
this.setState({cursor: newCursor});
console.log('+' + row.top);
}
_scrollDiv: null;
_keepCursorInViewport() {
if (this._scrollDiv) {
const cursor = this.state.cursor;
const scrollDiv = this._scrollDiv;
if (cursor * rowHeight < scrollDiv.scrollTop + scrollDiv.clientHeight * 0.1) {
scrollDiv.scrollTop = cursor * rowHeight - scrollDiv.clientHeight * 0.1;
} else if ((cursor + 1) * rowHeight > scrollDiv.scrollTop + scrollDiv.clientHeight * 0.9) {
scrollDiv.scrollTop = (cursor + 1) * rowHeight - scrollDiv.clientHeight * 0.9;
}
}
}
keydown(e) {
const aggrow = this.state.aggrow;
let cursor = this.state.cursor;
let row = aggrow.getRows(cursor, 1)[0];
switch (e.keyCode) {
case 38: // up
if (cursor > 0) {
this.setState({cursor: cursor - 1});
this._keepCursorInViewport();
}
e.preventDefault();
break;
case 40: // down
if (cursor < aggrow.getHeight() - 1) {
this.setState({cursor: cursor + 1});
this._keepCursorInViewport();
}
e.preventDefault();
break;
case 37: // left
if (aggrow.canContract(row)) {
this._contractRow(row);
} else if (aggrow.getRowIndent(row) > 0) {
const indent = aggrow.getRowIndent(row) - 1;
while (aggrow.getRowIndent(row) > indent) {
cursor--;
row = aggrow.getRows(cursor, 1)[0];
}
this.setState({cursor: cursor});
this._keepCursorInViewport();
}
e.preventDefault();
break;
case 39: // right
if (aggrow.canExpand(row)) {
this._expandRow(row);
} else if (cursor < aggrow.getHeight() - 1) {
this.setState({cursor: cursor + 1});
this._keepCursorInViewport();
}
e.preventDefault();
break;
}
}
dropAction(s, d) {
const aggrow = this.state.aggrow;
console.log('dropped ' + s + ' to ' + d);
if (s.startsWith('aggregate:active:')) {
const sIndex = parseInt(s.substr(17), 10);
let dIndex = -1;
const active = aggrow.getActiveAggregators();
const dragged = active[sIndex];
if (d.startsWith('aggregate:insert:')) {
dIndex = parseInt(d.substr(17), 10);
} else if (d === 'divider:insert') {
dIndex = active.length;
} else {
throw 'not allowed to drag ' + s + ' to ' + d;
}
if (dIndex > sIndex) {
dIndex--;
}
active.splice(sIndex, 1);
active.splice(dIndex, 0, dragged);
aggrow.setActiveAggregators(active);
this.setState({cursor:0});
} else if (s.startsWith('expander:active:')) {
const sIndex = parseInt(s.substr(16), 10);
let dIndex = -1;
const active = aggrow.getActiveExpanders();
const dragged = active[sIndex];
if (d.startsWith('expander:insert:')) {
dIndex = parseInt(d.substr(16), 10);
} else if (d === 'divider:insert') {
dIndex = 0;
} else {
throw 'not allowed to drag ' + s + ' to ' + d;
}
if (dIndex > sIndex) {
dIndex--;
}
active.splice(sIndex, 1);
active.splice(dIndex, 0, dragged);
aggrow.setActiveExpanders(active);
this.setState({cursor:0});
} else if (s.startsWith('expander:add:')) {
let dIndex = -1;
const sExpander = parseInt(s.substring(13), 10);
if (d.startsWith('expander:insert:')) {
dIndex = parseInt(d.substr(16), 10);
} else if (d === 'divider:insert') {
dIndex = 0;
} else {
throw 'not allowed to drag ' + s + ' to ' + d;
}
const active = aggrow.getActiveExpanders();
active.splice(dIndex, 0, sExpander);
aggrow.setActiveExpanders(active);
this.setState({cursor:0});
}
}
render() {
return (
<div style={{ width: '100%', height: '100%', display: 'flex', flexDirection: 'row' }}>
<div style={{ width: '100%', height: '100%', display: 'flex', flexDirection: 'column', overflow: 'hidden', }}>
<TableHeader aggrow={this.state.aggrow} dropAction={(s, d) => this.dropAction(s, d)} />
<div
style={{
width: '100%',
flexGrow: '1',
overflow: 'scroll'
}}
onScroll={ (e) => this.scroll(e) }
ref={(div) => { this._scrollDiv = div; } }>
<div style={{ position: 'relative' }}>
{ this.renderVirtualizedRows() }
</div>
</div>
</div>
<TableConfiguration aggrow={this.state.aggrow} />
</div>
);
}
renderVirtualizedRows() {
const aggrow = this.state.aggrow;
const viewport = this.state.viewport;
const rows = aggrow.getRows(viewport.top, viewport.height);
return (
<div style={{
position: 'absolute',
width: '100%',
height: (rowHeight * (aggrow.getHeight() + 20)).toString() + 'px'
}}>
{ rows.map(child => this.renderRow(child)) }
</div>
);
}
renderRow(row) {
if (row === null) {
return null;
}
let bg = 'lightGray';
const aggrow = this.state.aggrow;
const columns = [];
let rowText = '';
const indent = 4 + aggrow.getRowIndent(row) * treeIndent;
const aggregates = aggrow.getActiveAggregators();
if (row.parent !== null && (row.parent.expander % 2 === 0)) {
bg = 'white';
}
if (row.top === this.state.cursor) {
bg = 'lightblue';
}
for (let i = 0; i < aggregates.length; i++) {
var aggregate = aggrow.getRowAggregate(row, i);
columns.push((
<div style={{
width: '16px',
height: 'inherit',
backgroundColor: 'darkGray',
flexShrink: '0'
}}></div>
));
columns.push((
<div style={{
width: '128px',
textAlign: 'right',
flexShrink: '0'
}}>
{aggregate}
</div>
));
}
columns.push((
<div style={{
width: '16px',
height: 'inherit',
backgroundColor: 'gold',
flexShrink: '0'
}}></div>
));
if (aggrow.canExpand(row)) {
columns.push((
<div
style={{
marginLeft: indent.toString() + 'px',
flexShrink: '0',
width: '12px',
textAlign: 'center',
border: '1px solid gray',
}}
onClick={ () => this._expandRow(row) }
>+</div>
));
} else if (aggrow.canContract(row)) {
columns.push((
<div
style={{
marginLeft: indent.toString() + 'px',
flexShrink: '0',
width: '12px',
textAlign: 'center',
border: '1px solid gray',
}}
onClick={ () => this._contractRow(row) }
>-</div>
));
} else {
columns.push((
<div
style={{
marginLeft: indent.toString() + 'px',
}}
></div>
));
}
rowText += aggrow.getRowLabel(row);
columns.push((
<div style={{
flexShrink: '0',
whiteSpace: 'nowrap',
marginRight: '20px'
}}>
{rowText}
</div>
));
return (
<div
key={row.top}
style={{
position: 'absolute',
height: (rowHeight - 1).toString() + 'px',
top: (rowHeight * row.top).toString() + 'px',
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
backgroundColor: bg,
borderBottom: '1px solid gray',
}}
onClick={ () => {
this.setState({cursor: row.top});
}}>
{columns}
</div>
);
}
componentDidMount() {
this.keydown = this.keydown.bind(this);
document.body.addEventListener('keydown', this.keydown);
}
componentWillUnmount() {
document.body.removeEventListener('keydown', this.keydown);
}
}