Skip to content

Commit 07e3ab5

Browse files
committed
mperf metrics in progress
1 parent 62d8b7a commit 07e3ab5

File tree

8 files changed

+92
-79
lines changed

8 files changed

+92
-79
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"jest-diff": "^26.1.0",
100100
"jest-puppeteer": "^4.4.0",
101101
"jest-runner-eslint": "^0.7.7",
102+
"jscharting-react": "^1.2.1",
102103
"puppeteer": "^5.1.0",
103104
"sass": "^1.26.10",
104105
"sass-loader": "^7.3.1",
@@ -145,6 +146,7 @@
145146
"d3-zoom": "^1.8.3",
146147
"immer": "^3.3.0",
147148
"jest-runner": "^26.1.0",
149+
"jscharting": "^3.0.2",
148150
"jsondiffpatch": "^0.3.11",
149151
"mixpanel": "^0.11.0",
150152
"mixpanel-browser": "^2.39.0",

src/app/components/StateRoute.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { useStoreContext } from '../store';
2020
import PerformanceVisx from './PerformanceVisx';
2121
import Legend from './AtomsRelationshipLegend';
2222
import AtomsRelationship from './AtomsRelationship';
23-
import Vitals from './Vitals';
23+
import WebMetrics from './WebMetrics';
2424

2525
const History = require('./History').default;
2626
const ErrorHandler = require('./ErrorHandler').default;
@@ -43,11 +43,11 @@ export interface StateRouteProps {
4343
hierarchy: any;
4444
snapshots: [];
4545
viewIndex: number;
46-
FCP: any;
46+
webMetrics: object;
4747
}
4848

4949
const StateRoute = (props: StateRouteProps) => {
50-
const { snapshot, hierarchy, snapshots, viewIndex, FCP } = props;
50+
const { snapshot, hierarchy, snapshots, viewIndex, webMetrics } = props;
5151
const [{ tabs, currentTab }, dispatch] = useStoreContext();
5252
const { hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
5353
const isRecoil = snapshot.atomsComponents ? true : false;
@@ -116,8 +116,8 @@ const StateRoute = (props: StateRouteProps) => {
116116
return <div className="noState">{NO_STATE_MSG}</div>;
117117

118118
};
119-
const renderVitals = () => {
120-
return <Vitals FCP={FCP}/>;
119+
const renderWebMetrics = () => {
120+
return <WebMetrics webMetrics={webMetrics}/>;
121121
};
122122

123123
const renderPerfView = () => {
@@ -165,9 +165,9 @@ const StateRoute = (props: StateRouteProps) => {
165165
<NavLink
166166
className="router-link"
167167
activeClassName="is-active"
168-
to="/vitals"
168+
to="/webMetrics"
169169
>
170-
Vitals
170+
Web Metrics
171171
</NavLink>
172172
<NavLink
173173
className="router-link"
@@ -190,7 +190,7 @@ const StateRoute = (props: StateRouteProps) => {
190190
<Route path="/performance" render={renderPerfView} />
191191
<Route path="/history" render={renderHistory} />
192192
<Route path="/relationship" render={renderAtomsRelationship} />
193-
<Route path="/vitals" render={renderVitals} />
193+
<Route path="/webMetrics" render={renderWebMetrics} />
194194
<Route path="/tree" render={renderTree} />
195195
<Route path="/" render={renderComponentMap} />
196196
</Switch>

src/app/components/Vitals.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/app/components/WebMetrics.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { useState } from 'react';
2+
import { JSCharting } from 'jscharting-react';
3+
4+
const config = {
5+
type: 'horizontal column',
6+
series: [
7+
{
8+
points: [
9+
{ x: 'A', y: 50 },
10+
{ x: 'B', y: 30 },
11+
{ x: 'C', y: 50 }
12+
]
13+
}
14+
]
15+
};
16+
17+
const divStyle = {
18+
maxWidth: '700px',
19+
height: '400px',
20+
margin: '0px auto'
21+
};
22+
23+
// const WebMetrics = ({webMetrics}) => {
24+
// const [data, setData] = React.useState({});
25+
// const METRICS = ["TTFB", "LCP", "FID", "FCP", "CLS"];
26+
27+
// React.useEffect(() => {
28+
// chrome.runtime.sendMessage({
29+
// type: "performance:metric:request",
30+
// }, (d) => {
31+
// setData(d);
32+
// })
33+
// }, [])
34+
35+
// const output = [];
36+
// const perfMetrics = Object.keys(webMetrics)
37+
// .map((metric) => output.push(<div><div>{metric}</div><div>{Math.round(webMetrics[metric])}</div></div>));
38+
39+
40+
41+
42+
return (
43+
<div id="chartDiv" style="width: 100%; height: 400px;"></div>
44+
)
45+
}
46+
47+
export default WebMetrics;

src/app/containers/MainContainer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ function MainContainer(): any {
155155
</div>
156156
);
157157
}
158-
const { viewIndex, sliderIndex, snapshots, hierarchy, FCP } = tabs[currentTab];
158+
const { viewIndex, sliderIndex, snapshots, hierarchy, webMetrics } = tabs[currentTab];
159159
// if viewIndex is -1, then use the sliderIndex instead
160-
console.log('FCP in MainContainer >>>', FCP);
160+
console.log('webMetrics in MainContainer >>>', webMetrics);
161161

162162

163163
const snapshotView =
@@ -208,7 +208,7 @@ function MainContainer(): any {
208208
{snapshots.length ? (
209209
<StateContainer
210210
toggleActionContainer={toggleActionContainer}
211-
FCP={FCP}
211+
webMetrics={webMetrics}
212212
viewIndex={viewIndex}
213213
snapshot={snapshotDisplay}
214214
hierarchy={hierarchyDisplay}

src/app/containers/StateContainer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface StateContainerProps {
2424
}
2525
>;
2626
toggleActionContainer?: any;
27-
FCP: any;
27+
webMetrics: object;
2828
AtomsRelationship?: any[];
2929
hierarchy: Record<string, unknown>;
3030
snapshots: [];
@@ -34,7 +34,7 @@ interface StateContainerProps {
3434

3535
// eslint-disable-next-line react/prop-types
3636
const StateContainer = (props: StateContainerProps): JSX.Element => {
37-
const { snapshot, hierarchy, snapshots, viewIndex, toggleActionContainer, FCP } = props;
37+
const { snapshot, hierarchy, snapshots, viewIndex, toggleActionContainer, webMetrics } = props;
3838
const [Text, setText] = useState('State');
3939

4040
return (
@@ -75,7 +75,7 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
7575
setText('State');
7676
return (
7777
<StateRoute
78-
FCP={FCP}
78+
webMetrics={webMetrics}
7979
viewIndex={viewIndex}
8080
snapshot={snapshot}
8181
hierarchy={hierarchy}

src/extension/background.js

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const reloaded = {};
66
const firstSnapshotReceived = {};
77
// there will be the same number of objects in here as there are reactime tabs open for each user application being worked on
88
const tabsObj = {};
9-
let data = {}; //for Performance Metrics 8.0
9+
10+
let metrics = {}; //for Performance Metrics 8.0
1011

1112
function createTabObj(title) {
1213
// update tabsObj
@@ -33,8 +34,8 @@ function createTabObj(title) {
3334
paused: false,
3435
empty: false,
3536
},
36-
// Holds FCP metric
37-
FCP: null,
37+
38+
webMetrics: {},
3839
};
3940
}
4041

@@ -189,15 +190,15 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
189190
console.log('Sender in Listener >>>', sender)
190191
const tabTitle = sender.tab.title;
191192
const tabId = sender.tab.id;
192-
const { action, index, name, value } = request;
193+
const { action, index, name, value } = request;
193194
let isReactTimeTravel = false;
194195

195-
if (request.value) {
196-
data = {
197-
name, value
196+
if (name) {
197+
metrics[name] = value;
198198
};
199-
console.log("data >>>", data)
200-
}
199+
200+
console.log('metrics outside', metrics);
201+
201202
// Filter out tabs that don't have reactime, tabs that dont use react?
202203
if (
203204
action === 'tabReload' ||
@@ -217,27 +218,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
217218

218219
//Performance Metrics 8.0
219220

220-
// if (request.type === "performance:metric") {
221-
// console.log('performance:metric received');
222-
223-
// const tab = sender.tab.url.toString();
224-
// data[tab] = data[tab] || {};
225-
// const name = request.name;
226-
// data[tab][name] = data[tab][name] || {
227-
// values: [],
228-
// average: 0,
229-
// };
230-
// data[tab][name].values.push(request.value);
231-
// data[tab][name].average =
232-
// data[tab][name].values.reduce((a, v) => a + v, 0) / data[tab][name].values.length;
233-
// }
234-
// if (request.type === "performance:metric:request") {
235-
// console.log('performance:metric:request received')
236-
// console.log('p:m:r', data)
237-
// sendResponse(data);
238-
// }
239-
240-
241221
const { persist, empty } = tabsObj[tabId].mode;
242222

243223
switch (action) {
@@ -311,15 +291,23 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
311291
case 'recordSnap': {
312292
const sourceTab = tabId;
313293
// first snapshot received from tab
294+
console.log('metrics in recordSnap case', metrics);
295+
tabsObj[tabId].webMetrics = metrics;
296+
297+
// metrics check
298+
console.log('tabsObj >>>', tabsObj);
299+
300+
314301
if (!firstSnapshotReceived[tabId]) {
315302
firstSnapshotReceived[tabId] = true;
316303
reloaded[tabId] = false;
317304

318-
if (data.value) tabsObj[tabId].FCP = data.value;
305+
console.log('metrics in recordSnap case', metrics);
306+
tabsObj[tabId].webMetrics = metrics;
319307

320308
tabsObj[tabId].snapshots.push(request.payload);
321309

322-
// FCP check
310+
// metrics check
323311
console.log('tabsObj >>>', tabsObj);
324312

325313
sendToHierarchy(

src/extension/contentScript.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getTTFB, getLCP, getFID, getFCP, getCLS } from "web-vitals";
22

33

4-
54
let firstMessage = true;
65

76
// listening for window messages (from the injected script.../DOM)
@@ -42,24 +41,25 @@ chrome.runtime.onMessage.addListener(request => {
4241

4342
const metrics = {};
4443
const gatherMetrics = ({ name, value }) => {
45-
46-
console.log('inside Content Script gather metrics', name, value)
4744
metrics[name] = value;
45+
4846

4947
chrome.runtime.sendMessage({
5048
type: "performance:metric",
5149
name,
52-
value,
50+
value
5351
});
52+
53+
5454

55-
const metricsHTML = Object.keys(metrics)
5655
}
5756

58-
// getTTFB(gatherMetrics);
59-
// getLCP(gatherMetrics);
60-
// getFID(gatherMetrics);
57+
getTTFB(gatherMetrics);
58+
getLCP(gatherMetrics);
59+
getFID(gatherMetrics);
6160
getFCP(gatherMetrics);
62-
// getCLS(gatherMetrics);
61+
getCLS(gatherMetrics);
62+
6363

6464

6565
chrome.runtime.sendMessage({ action: 'injectScript' });

0 commit comments

Comments
 (0)