@vpalmisano/webrtcperf 4.4.2 → 4.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.min.js +1 -1
- package/build/src/config.js +4 -1
- package/build/src/config.js.map +1 -1
- package/build/src/session.d.ts +1 -0
- package/build/src/session.js +81 -65
- package/build/src/session.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/config.ts +4 -1
- package/src/session.ts +82 -66
package/src/session.ts
CHANGED
|
@@ -1367,70 +1367,12 @@ Object.defineProperty(window.screen.orientation, 'type', { value: 'landscape-pri
|
|
|
1367
1367
|
}
|
|
1368
1368
|
})
|
|
1369
1369
|
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
sentBytes: 0,
|
|
1373
|
-
recvBytes: 0,
|
|
1374
|
-
recvLatency: new FastStats({ store_data: false }),
|
|
1375
|
-
wsSentBytes: 0,
|
|
1376
|
-
wsRecvBytes: 0,
|
|
1377
|
-
wsRecvLatency: new FastStats({ store_data: false }),
|
|
1378
|
-
}
|
|
1379
|
-
this.httpResourcesStats.set(index, resourcesStats)
|
|
1380
|
-
|
|
1381
|
-
const pendingRequests = new Map<string, { url: string; timestamp: number }>()
|
|
1382
|
-
pageCDPSession.on('Network.requestWillBeSent', event => {
|
|
1383
|
-
if (event.request.url.startsWith('data:')) return
|
|
1384
|
-
const { requestId, request, timestamp } = event
|
|
1385
|
-
const sentBytes = request.postDataEntries?.reduce((acc, entry) => acc + (entry.bytes?.length || 0), 0)
|
|
1386
|
-
//log.log('Network.requestWillBeSent', event.type, request.url, sentBytes)
|
|
1387
|
-
if (sentBytes) resourcesStats.sentBytes += sentBytes
|
|
1388
|
-
pendingRequests.set(requestId, { url: request.url, timestamp })
|
|
1370
|
+
await page.exposeFunction('webrtcperf_reload', () => {
|
|
1371
|
+
return page.reload()
|
|
1389
1372
|
})
|
|
1390
1373
|
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
if (!request) return
|
|
1394
|
-
const { response } = event
|
|
1395
|
-
if (response.fromDiskCache) {
|
|
1396
|
-
pendingRequests.delete(event.requestId)
|
|
1397
|
-
return
|
|
1398
|
-
}
|
|
1399
|
-
resourcesStats.recvBytes += response.encodedDataLength
|
|
1400
|
-
})
|
|
1401
|
-
|
|
1402
|
-
pageCDPSession.on('Network.dataReceived', event => {
|
|
1403
|
-
const request = pendingRequests.get(event.requestId)
|
|
1404
|
-
if (!request) return
|
|
1405
|
-
resourcesStats.recvBytes += event.encodedDataLength
|
|
1406
|
-
})
|
|
1407
|
-
|
|
1408
|
-
pageCDPSession.on('Network.loadingFinished', event => {
|
|
1409
|
-
const request = pendingRequests.get(event.requestId)
|
|
1410
|
-
if (!request) return
|
|
1411
|
-
pendingRequests.delete(event.requestId)
|
|
1412
|
-
const { timestamp } = event
|
|
1413
|
-
resourcesStats.recvLatency.push(timestamp - request.timestamp)
|
|
1414
|
-
})
|
|
1415
|
-
|
|
1416
|
-
pageCDPSession.on('Network.webSocketCreated', event => {
|
|
1417
|
-
pendingRequests.set(event.requestId, { url: event.url, timestamp: Date.now() })
|
|
1418
|
-
})
|
|
1419
|
-
|
|
1420
|
-
pageCDPSession.on('Network.webSocketHandshakeResponseReceived', event => {
|
|
1421
|
-
const request = pendingRequests.get(event.requestId)
|
|
1422
|
-
if (!request) return
|
|
1423
|
-
pendingRequests.delete(event.requestId)
|
|
1424
|
-
resourcesStats.wsRecvLatency.push((Date.now() - request.timestamp) / 1000)
|
|
1425
|
-
})
|
|
1426
|
-
|
|
1427
|
-
pageCDPSession.on('Network.webSocketFrameSent', event => {
|
|
1428
|
-
resourcesStats.wsSentBytes += event.response.payloadData.length
|
|
1429
|
-
})
|
|
1430
|
-
|
|
1431
|
-
pageCDPSession.on('Network.webSocketFrameReceived', event => {
|
|
1432
|
-
resourcesStats.wsRecvBytes += event.response.payloadData.length
|
|
1433
|
-
})
|
|
1374
|
+
// HTTP stats.
|
|
1375
|
+
this.setupPageNetworkStats(pageCDPSession, index)
|
|
1434
1376
|
|
|
1435
1377
|
// Hardware concurrency.
|
|
1436
1378
|
if (this.hardwareConcurrency) {
|
|
@@ -1510,11 +1452,19 @@ Object.defineProperty(window.screen.orientation, 'type', { value: 'landscape-pri
|
|
|
1510
1452
|
// add to pages map
|
|
1511
1453
|
this.pages.set(index, page)
|
|
1512
1454
|
|
|
1455
|
+
// Handle network internal throttling.
|
|
1513
1456
|
if (this.throttleIndex > -1 && (process.platform !== 'linux' || this.useBrowserThrottling)) {
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1457
|
+
const onThrottleChange = async () => {
|
|
1458
|
+
if (page.isClosed()) return
|
|
1459
|
+
try {
|
|
1460
|
+
await this.applyNetworkThrottling(pageCDPSession)
|
|
1461
|
+
} catch (err) {
|
|
1462
|
+
log.error(`applyNetworkThrottling error: ${(err as Error).stack}`)
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
await onThrottleChange()
|
|
1466
|
+
throttleNotifier.on('change', onThrottleChange)
|
|
1467
|
+
page.once('close', () => throttleNotifier.off('change', onThrottleChange))
|
|
1518
1468
|
}
|
|
1519
1469
|
|
|
1520
1470
|
log.debug(`Page ${index + 1} "${url}" loaded in ${(Date.now() - pageLoadTime) / 1000}s`)
|
|
@@ -1528,6 +1478,72 @@ Object.defineProperty(window.screen.orientation, 'type', { value: 'landscape-pri
|
|
|
1528
1478
|
}
|
|
1529
1479
|
}
|
|
1530
1480
|
|
|
1481
|
+
private setupPageNetworkStats(pageCDPSession: CDPSession, index: number) {
|
|
1482
|
+
const resourcesStats = {
|
|
1483
|
+
sentBytes: 0,
|
|
1484
|
+
recvBytes: 0,
|
|
1485
|
+
recvLatency: new FastStats({ store_data: false }),
|
|
1486
|
+
wsSentBytes: 0,
|
|
1487
|
+
wsRecvBytes: 0,
|
|
1488
|
+
wsRecvLatency: new FastStats({ store_data: false }),
|
|
1489
|
+
}
|
|
1490
|
+
this.httpResourcesStats.set(index, resourcesStats)
|
|
1491
|
+
|
|
1492
|
+
const pendingRequests = new Map<string, { url: string; timestamp: number }>()
|
|
1493
|
+
pageCDPSession.on('Network.requestWillBeSent', event => {
|
|
1494
|
+
if (event.request.url.startsWith('data:')) return
|
|
1495
|
+
const { requestId, request, timestamp } = event
|
|
1496
|
+
const sentBytes = request.postDataEntries?.reduce((acc, entry) => acc + (entry.bytes?.length || 0), 0)
|
|
1497
|
+
//log.log('Network.requestWillBeSent', event.type, request.url, sentBytes)
|
|
1498
|
+
if (sentBytes) resourcesStats.sentBytes += sentBytes
|
|
1499
|
+
pendingRequests.set(requestId, { url: request.url, timestamp })
|
|
1500
|
+
})
|
|
1501
|
+
|
|
1502
|
+
pageCDPSession.on('Network.responseReceived', event => {
|
|
1503
|
+
const request = pendingRequests.get(event.requestId)
|
|
1504
|
+
if (!request) return
|
|
1505
|
+
const { response } = event
|
|
1506
|
+
if (response.fromDiskCache) {
|
|
1507
|
+
pendingRequests.delete(event.requestId)
|
|
1508
|
+
return
|
|
1509
|
+
}
|
|
1510
|
+
resourcesStats.recvBytes += response.encodedDataLength
|
|
1511
|
+
})
|
|
1512
|
+
|
|
1513
|
+
pageCDPSession.on('Network.dataReceived', event => {
|
|
1514
|
+
const request = pendingRequests.get(event.requestId)
|
|
1515
|
+
if (!request) return
|
|
1516
|
+
resourcesStats.recvBytes += event.encodedDataLength
|
|
1517
|
+
})
|
|
1518
|
+
|
|
1519
|
+
pageCDPSession.on('Network.loadingFinished', event => {
|
|
1520
|
+
const request = pendingRequests.get(event.requestId)
|
|
1521
|
+
if (!request) return
|
|
1522
|
+
pendingRequests.delete(event.requestId)
|
|
1523
|
+
const { timestamp } = event
|
|
1524
|
+
resourcesStats.recvLatency.push(timestamp - request.timestamp)
|
|
1525
|
+
})
|
|
1526
|
+
|
|
1527
|
+
pageCDPSession.on('Network.webSocketCreated', event => {
|
|
1528
|
+
pendingRequests.set(event.requestId, { url: event.url, timestamp: Date.now() })
|
|
1529
|
+
})
|
|
1530
|
+
|
|
1531
|
+
pageCDPSession.on('Network.webSocketHandshakeResponseReceived', event => {
|
|
1532
|
+
const request = pendingRequests.get(event.requestId)
|
|
1533
|
+
if (!request) return
|
|
1534
|
+
pendingRequests.delete(event.requestId)
|
|
1535
|
+
resourcesStats.wsRecvLatency.push((Date.now() - request.timestamp) / 1000)
|
|
1536
|
+
})
|
|
1537
|
+
|
|
1538
|
+
pageCDPSession.on('Network.webSocketFrameSent', event => {
|
|
1539
|
+
resourcesStats.wsSentBytes += event.response.payloadData.length
|
|
1540
|
+
})
|
|
1541
|
+
|
|
1542
|
+
pageCDPSession.on('Network.webSocketFrameReceived', event => {
|
|
1543
|
+
resourcesStats.wsRecvBytes += event.response.payloadData.length
|
|
1544
|
+
})
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1531
1547
|
private async applyNetworkThrottling(pageCDPSession: CDPSession) {
|
|
1532
1548
|
const throttleUpValues = getSessionThrottleValues(this.throttleIndex, 'up')
|
|
1533
1549
|
const throttleDownValues = getSessionThrottleValues(this.throttleIndex, 'down')
|