Skip to content

Commit 001b1a3

Browse files
committed
made changes to the performance tab to properly pass information into rendering frequency
1 parent bb906f1 commit 001b1a3

File tree

4 files changed

+99
-38
lines changed

4 files changed

+99
-38
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable guard-for-in */
2+
/* eslint-disable no-restricted-syntax */
13
// @ts-nocheck
24
import React, { useState } from 'react';
35
import FormControlLabel from '@material-ui/core/FormControlLabel';
@@ -8,13 +10,16 @@ import {
810
NavLink,
911
Switch,
1012
} from 'react-router-dom';
13+
import { Component } from 'react';
1114
import RenderingFrequency from './RenderingFrequency';
1215
// import Switch from '@material-ui/core/Switch';
1316
import BarGraph from './BarGraph';
1417
import BarGraphComparison from './BarGraphComparison';
1518
import { useStoreContext } from '../store';
1619
// import snapshots from './snapshots';
17-
import { Component } from 'react';
20+
import snapshots from './snapshots';
21+
22+
const exclude = ['childExpirationTime', 'staticContext', '_debugSource', 'actualDuration', 'actualStartTime', 'treeBaseDuration', '_debugID', '_debugIsCurrentlyTiming', 'selfBaseDuration', 'expirationTime', 'effectTag', 'alternate', '_owner', '_store', 'get key', 'ref', '_self', '_source', 'firstBaseUpdate', 'updateQueue', 'lastBaseUpdate', 'shared', 'responders', 'pending', 'lanes', 'childLanes', 'effects', 'memoizedState', 'pendingProps', 'lastEffect', 'firstEffect', 'tag', 'baseState', 'baseQueue', 'dependencies', 'Consumer', 'context', '_currentRenderer', '_currentRenderer2', 'mode', 'flags', 'nextEffect', 'sibling', 'create', 'deps', 'next', 'destroy', 'parentSub', 'child', 'key', 'return', 'children', '$$typeof', '_threadCount', '_calculateChangedBits', '_currentValue', '_currentValue2', 'Provider', '_context', 'stateNode', 'elementType', 'type'];
1823

1924
/* NOTES
2025
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
@@ -34,15 +39,17 @@ interface BarStackProps {
3439
hierarchy: any;
3540
}
3641

37-
38-
42+
const formatRenderTime = time => {
43+
time = time.toFixed(3);
44+
return `${time} ms `;
45+
};
3946
// function getComponentsArr(componentName, snapshots, node) {
4047
// //Input: Name of component and all snapshots
4148
// //Output: One array of each individual snapshot
4249

4350
// //NOTE:
4451
// //Every snapshot is an object with a children array with a snapshot that also has a children array etc
45-
// //Children arrays more than one signify siblings
52+
// //Children arrays more than one signify siblings
4653

4754
// }
4855
// // snapshots.map(rootNode => {
@@ -57,37 +64,77 @@ interface BarStackProps {
5764
// // }
5865
// // }
5966
// // })
67+
const makePropsPretty = data => {
68+
const propsFormat = [];
69+
const nestedObj = [];
70+
// console.log('show me the data we are getting', data);
71+
if (typeof data !== 'object') {
72+
return data;
73+
}
74+
for (const key in data) {
75+
if (data[key] !== 'reactFiber' && typeof data[key] !== 'object' && exclude.includes(key) !== true) {
76+
propsFormat.push(<p className="stateprops">
77+
{`${key}: ${data[key]}`}
78+
</p>);
79+
} else if (data[key] !== 'reactFiber' && typeof data[key] === 'object' && exclude.includes(key) !== true) {
80+
const result = makePropsPretty(data[key]);
81+
nestedObj.push(result);
82+
}
83+
}
84+
if (nestedObj) {
85+
propsFormat.push(nestedObj);
86+
}
87+
// console.log('this is propsformat', propsFormat);
88+
return propsFormat;
89+
};
6090

6191
const collectNodes = (snaps, componentName) => {
6292
const componentsResult = [];
63-
// console.log("This is the snapshots", snaps);
64-
// componentsResult.splice(0, componentsResult.length); { /* We used the .splice method here to ensure that nodeList did not accumulate with page refreshes */ }
65-
// componentsResult.push(snaps);
66-
93+
let trackChanges = 0;
94+
let newChange = true;
6795
for (let x = 0; x < snaps.length; x++) {
68-
const snapshotList = []
96+
const snapshotList = [];
6997
snapshotList.push(snaps[x]);
70-
7198
for (let i = 0; i < snapshotList.length; i++) {
72-
7399
const cur = snapshotList[i];
74100
if (cur.name === componentName) {
75-
componentsResult.push(cur.componentData.props);
101+
// compare the last pushed component Data from the array to the current one to see if there are differences
102+
if (x !== 0 && componentsResult.length !== 0) {
103+
// needs to be stringified because values are hard to determine if true or false if in they're seen as objects
104+
if (JSON.stringify(Object.values(componentsResult[newChange ? componentsResult.length - 1 : trackChanges])[0]) !== JSON.stringify(cur.componentData.props)) {
105+
newChange = true;
106+
const props = { [`snapshot${x}`]: { ...cur.componentData.props, rendertime: formatRenderTime(cur.componentData.actualDuration) } };
107+
//props[`snapshot${x}`].rendertime = formatRenderTime(cur.componentData.actualDuration);
108+
componentsResult.push(props);
109+
} else {
110+
newChange = false;
111+
trackChanges = componentsResult.length - 1;
112+
const props = { [`snapshot${x}`]: 'Same state as prior snapshot', rendertime: formatRenderTime(cur.componentData.actualDuration) };
113+
componentsResult.push(props);
114+
}
115+
} else {
116+
const props = { [`snapshot${x}`]: { ...cur.componentData.props}};
117+
props[`snapshot${x}`].rendertime = formatRenderTime(cur.componentData.actualDuration);
118+
componentsResult.push(props);
119+
}
76120
break;
77121
}
78122
if (cur.children && cur.children.length > 0) {
79-
for (let child of cur.children) {
123+
for (const child of cur.children) {
80124
snapshotList.push(child);
81125
}
82126
}
83127
}
84-
}
85-
//console.log('componentsResult looks like: ', componentsResult);
128+
}
129+
// console.log('componentsResult looks like: ', componentsResult);
130+
for (let i = 0; i < componentsResult.length; i++) {
131+
for (const componentSnapshot in componentsResult[i]) {
132+
componentsResult[i][componentSnapshot] = makePropsPretty(componentsResult[i][componentSnapshot]);
133+
}
134+
}
135+
console.log('we should be seeing react components with information', componentsResult);
86136
return componentsResult;
87-
}
88-
89-
90-
137+
};
91138

92139
/* DATA HANDLING HELPER FUNCTIONS */
93140
const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
@@ -113,7 +160,7 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
113160
renderFrequency: 0,
114161
totalRenderTime: 0,
115162
rtid: '',
116-
props: {},
163+
information: {},
117164
};
118165
if (child.state !== 'stateless') data.componentData[componentName].stateType = 'stateful';
119166
}
@@ -131,7 +178,8 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
131178
data.componentData[componentName].totalRenderTime += renderTime;
132179
// Get rtid for the hovering feature
133180
data.componentData[componentName].rtid = child.rtid;
134-
data.componentData[componentName].props = collectNodes(snapshots, child.name);
181+
data.componentData[componentName].information = collectNodes(snapshots, child.name).flat(Infinity);
182+
// console.log('what is the result', data.componentData[componentName].information);
135183
traverse(snapshot.children[idx], data, snapshots, currTotalRender);
136184
});
137185
// reassigns total render time to max render time
@@ -144,13 +192,13 @@ const allStorage = () => {
144192
const values = [];
145193
const keys = Object.keys(localStorage);
146194
let i = keys.length;
147-
console.log('allstorage keys', keys);
195+
// console.log('allstorage keys', keys);
148196

149197
while (i--) {
150198
const series = localStorage.getItem(keys[i]);
151199
values.push(JSON.parse(series));
152200
}
153-
console.log('allstorage values', values);
201+
// console.log('allstorage values', values);
154202
return values;
155203
};
156204

@@ -172,7 +220,7 @@ const getPerfMetrics = (snapshots, snapshotsIds): {} => {
172220
componentData: {},
173221
maxTotalRender: 0,
174222
};
175-
console.log('show me all of the snapshots', snapshots);
223+
// console.log('show me all of the snapshots', snapshots);
176224
snapshots.forEach((snapshot, i) => {
177225
perfData.barStack.push({ snapshotId: snapshotsIds[i] });
178226
traverse(snapshot, perfData, snapshots);
@@ -192,6 +240,7 @@ const PerformanceVisx = (props: BarStackProps) => {
192240
const [comparisonData, setComparisonData] = useState();
193241
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
194242
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy));
243+
// console.log('this is line 220', data);
195244

196245
const renderComparisonBargraph = () => {
197246
if (hierarchy) {
@@ -213,10 +262,9 @@ const PerformanceVisx = (props: BarStackProps) => {
213262
};
214263

215264
const renderComponentDetailsView = () => {
216-
console.log('show me snapshots', snapshots)
217-
console.log('what is heirarchy', hierarchy);
218-
console.log('this is the info for rendering frequency', data.componentData);
265+
// console.log('this is the info for rendering frequency', data.componentData);
219266
if (hierarchy) {
267+
// console.log('this is line 246', data.comparisonData);
220268
return <RenderingFrequency data={data.componentData} />;
221269
}
222270
return <div className="noState">{NO_STATE_MSG}</div>;

src/app/components/RenderingFrequency.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const RenderingFrequency = (props) => {
1818
).toFixed(3)}
1919
renderFrequency={currentComponent.renderFrequency}
2020
rtid={currentComponent.rtid}
21+
information={perfData[componentName].information}
2122
/>
2223
);
2324
})}
@@ -32,30 +33,40 @@ const ComponentCard = (props) => {
3233
averageRenderTime,
3334
renderFrequency,
3435
rtid,
36+
information,
3537
} = props;
3638
const [{ tabs, currentTab }, dispatch] = useStoreContext();
3739

38-
const onMouseMove = () => {
39-
dispatch(onHover(rtid));
40-
};
41-
const onMouseLeave = () => {
42-
dispatch(onHoverExit(rtid));
43-
};
40+
// const onMouseMove = () => {
41+
// console.log(rtid);
42+
// dispatch(onHover(rtid));
43+
// };
44+
// const onMouseLeave = () => {
45+
// console.log(rtid);
46+
// dispatch(onHoverExit(rtid));
47+
// };
48+
console.log('this is the information', information)
49+
50+
// render time for each component from each snapshot
51+
// differences in state change that happened prior;
4452

4553
return (
4654
<div
47-
onMouseLeave={onMouseLeave}
48-
onMouseMove={onMouseMove}
55+
// onMouseLeave={onMouseLeave}
56+
// onMouseMove={onMouseMove}
4957
className="StyledGridElement"
5058
>
5159
<div className="RenderLeft">
5260
<h3>{componentName} </h3>
5361
<h4>{stateType}</h4>
5462
<h4>average time: {averageRenderTime} ms</h4>
5563
</div>
56-
<div className="RenderRight">
64+
<div onClick={() => console.log('this is triggering')} className="RenderRight">
5765
<p>{renderFrequency}</p>
5866
</div>
67+
{/* <div>
68+
<p>{information}</p>
69+
</div> */}
5970
</div>
6071
);
6172
};

src/app/reducers/mainReducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export default (state, action) => produce(state, draft => {
265265
}
266266
case types.NEW_SNAPSHOTS: {
267267
const { payload } = action;
268-
console.log("in NEW_SANPSHOTS", payload);
268+
//console.log("in NEW_SANPSHOTS", payload);
269269
Object.keys(tabs).forEach(tab => {
270270
if (!payload[tab]) {
271271
delete tabs[tab];

src/backend/tree.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class Tree {
4343

4444
name: string;
4545

46-
componentData: {};
46+
componentData: {
47+
props:{}
48+
};
4749

4850
children: (Tree | string)[];
4951

0 commit comments

Comments
 (0)