hyperdrive-profiler 2.2.1 → 2.2.3

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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/index.js +51 -27
  3. package/package.json +6 -3
package/README.md CHANGED
@@ -21,11 +21,13 @@ Note: for running with bare, use `hyperdrive-profiler-bare`,
21
21
  This downloads the Hyperdrive with the given key to a temporary folder, and displays performance and progress metrics.
22
22
 
23
23
  To see all options, run
24
+
24
25
  ```
25
26
  hyperdrive-profiler --help
26
27
  ```
27
28
 
28
29
  Example output:
30
+
29
31
  ```
30
32
  General
31
33
  - Runtime: 97.95 seconds
package/index.js CHANGED
@@ -15,16 +15,23 @@ const HypercoreStats = require('hypercore-stats')
15
15
  const HyperswarmStats = require('hyperswarm-stats')
16
16
  const byteSize = require('tiny-byte-size')
17
17
 
18
- const cmd = command('hyperdrive-profiler',
18
+ const cmd = command(
19
+ 'hyperdrive-profiler',
19
20
  arg('<key>', 'Public key of the hyperdrive to download'),
20
- flag('--interval|-i [integer]', 'Interval (in seconds) at which to print the performance stats (default 10)'),
21
+ flag(
22
+ '--interval|-i [integer]',
23
+ 'Interval (in seconds) at which to print the performance stats (default 10)'
24
+ ),
21
25
  flag('--ip', 'Print the IP address (obfuscated by default)'),
22
26
  flag('--detail', 'Include detailed stats'),
23
- flag('--remotes|-r [string]', 'Location of a .txt file containing remote keys. Will print the remote status of each of them. Useful to verify all remotes downloaded the drive.'),
27
+ flag(
28
+ '--remotes|-r [string]',
29
+ 'Location of a .txt file containing remote keys. Will print the remote status of each of them. Useful to verify all remotes downloaded the drive.'
30
+ ),
24
31
 
25
32
  async function ({ args, flags }) {
26
33
  const key = IdEnc.decode(args.key)
27
- const statsIntervalMs = 1000 * (parseInt(flags.interval || 10))
34
+ const statsIntervalMs = 1000 * parseInt(flags.interval || 10)
28
35
  const printIp = flags.ip
29
36
  const detail = flags.detail
30
37
 
@@ -32,8 +39,13 @@ const cmd = command('hyperdrive-profiler',
32
39
  let secTillMetadata = null
33
40
  let secTillFullyDownload = null
34
41
 
35
- const tmpdir = path.join(os.tmpdir(), `hyperdrive-profiler-tmp-${Math.random().toString(16).slice(2)}`)
36
- console.info(`Profiling hyperdrive download for ${IdEnc.normalize(key)} using runtime: ${runtime}`)
42
+ const tmpdir = path.join(
43
+ os.tmpdir(),
44
+ `hyperdrive-profiler-tmp-${Math.random().toString(16).slice(2)}`
45
+ )
46
+ console.info(
47
+ `Profiling hyperdrive download for ${IdEnc.normalize(key)} using runtime: ${runtime}`
48
+ )
37
49
  console.info(`Using temporary directory ${tmpdir}`)
38
50
  console.info(`Printing progress every ${(statsIntervalMs / 1000).toFixed(0)} seconds`)
39
51
 
@@ -57,7 +69,7 @@ const cmd = command('hyperdrive-profiler',
57
69
 
58
70
  const drive = new Hyperdrive(store, key)
59
71
  const swarm = new Hyperswarm()
60
- swarm.on('connection', conn => {
72
+ swarm.on('connection', (conn) => {
61
73
  store.replicate(conn)
62
74
  conn.on('error', (e) => {
63
75
  console.log(`Connection error: ${e.stack}`)
@@ -76,18 +88,25 @@ const cmd = command('hyperdrive-profiler',
76
88
  : 'unknown (still connecting...)'
77
89
  timestampsInfo += `\n - Metadata db: ${drive.db.core.contiguousLength} / ${drive.db.core.length} (contiguous length / length)`
78
90
 
79
- const blobsContig = drive.blobs?.core?.contiguousLength == null
80
- ? 'loading'
81
- : drive.blobs.core.contiguousLength
82
- const blobsLength = drive.blobs?.core?.length == null
83
- ? 'loading'
84
- : drive.blobs.core.length
91
+ const blobsContig =
92
+ drive.blobs?.core?.contiguousLength === null ||
93
+ drive.blobs?.core?.contiguousLength === undefined
94
+ ? 'loading'
95
+ : drive.blobs.core.contiguousLength
96
+ const blobsLength =
97
+ drive.blobs?.core?.length === null || drive.blobs?.core?.length === undefined
98
+ ? 'loading'
99
+ : drive.blobs.core.length
85
100
 
86
101
  timestampsInfo += `\n - Blobs core: ${blobsContig} / ${blobsLength} (contiguous length / length)`
87
- if (secTillFullyDownload) timestampsInfo += `\n - Fully downloaded in ${secTillFullyDownload.toFixed(2)} seconds`
102
+ if (secTillFullyDownload) {
103
+ timestampsInfo += `\n - Fully downloaded in ${secTillFullyDownload.toFixed(2)} seconds`
104
+ }
88
105
 
89
106
  timestampsInfo += `\n - Nr peers db core: ${drive.db.core.peers.length} `
90
- if (drive.blobs) timestampsInfo += `\n - Nr peers blobs core: ${drive.blobs.core.peers.length} `
107
+ if (drive.blobs) {
108
+ timestampsInfo += `\n - Nr peers blobs core: ${drive.blobs.core.peers.length} `
109
+ }
91
110
 
92
111
  let remoteLength = 0
93
112
  let remoteContiguousLength = 0
@@ -101,7 +120,10 @@ const cmd = command('hyperdrive-profiler',
101
120
 
102
121
  for (const peer of drive.blobs?.core.peers || []) {
103
122
  blobRemoteLength = Math.max(peer.remoteLength, blobRemoteLength)
104
- blobRemoteContiguousLength = Math.max(peer.remoteContiguousLength, blobRemoteContiguousLength)
123
+ blobRemoteContiguousLength = Math.max(
124
+ peer.remoteContiguousLength,
125
+ blobRemoteContiguousLength
126
+ )
105
127
  }
106
128
 
107
129
  let contigInfo = 'Availability:\n'
@@ -164,11 +186,11 @@ const cmd = command('hyperdrive-profiler',
164
186
  }
165
187
  )
166
188
 
167
- async function gcDir (dir) {
189
+ async function gcDir(dir) {
168
190
  await fs.promises.rm(dir, { recursive: true })
169
191
  }
170
192
 
171
- function getHypercoreInfo (stats, { detail }) {
193
+ function getHypercoreInfo(stats, { detail }) {
172
194
  let res = `Hypercore stats
173
195
  - Hotswaps: ${stats.totalHotswaps}
174
196
  `
@@ -188,10 +210,8 @@ function getHypercoreInfo (stats, { detail }) {
188
210
  return res
189
211
  }
190
212
 
191
- function getSwarmInfo (swarmStats, { printIp, detail }) {
192
- const address = printIp
193
- ? swarmStats.dhtStats.getRemoteAddress()
194
- : 'xxx.xxx.xxx.xxx'
213
+ function getSwarmInfo(swarmStats, { printIp, detail }) {
214
+ const address = printIp ? swarmStats.dhtStats.getRemoteAddress() : 'xxx.xxx.xxx.xxx'
195
215
  const firewalled = swarmStats.dhtStats.isFirewalled
196
216
  let res = `Connection info
197
217
  - Address: ${address} (firewalled: ${firewalled})
@@ -225,7 +245,7 @@ function getSwarmInfo (swarmStats, { printIp, detail }) {
225
245
  return res
226
246
  }
227
247
 
228
- function getUdxInfo (swarmStats, elapsedSec) {
248
+ function getUdxInfo(swarmStats, elapsedSec) {
229
249
  const bytesRx = swarmStats.dhtStats.udxBytesReceived
230
250
  const bytesRxPerSec = (bytesRx / elapsedSec).toFixed(2)
231
251
  const bytesTx = swarmStats.dhtStats.udxBytesTransmitted
@@ -247,7 +267,7 @@ function getUdxInfo (swarmStats, elapsedSec) {
247
267
  `
248
268
  }
249
269
 
250
- async function printRemotesInfo (drive, remotes) {
270
+ async function printRemotesInfo(drive, remotes) {
251
271
  console.info('Remote download progress overview')
252
272
  let nrDoneDbBlindPeers = 0
253
273
  let nrDoneBlobsBlindPeers = 0
@@ -258,17 +278,21 @@ async function printRemotesInfo (drive, remotes) {
258
278
  if (remotes.includes(pubKey)) {
259
279
  const done = p.remoteLength > 0 && p.remoteContiguousLength === p.remoteLength
260
280
  if (remotes && done) nrDoneDbBlindPeers++
261
- console.info(` - ${IdEnc.normalize(p.remotePublicKey)} ${done ? 'DONE' : 'DOWNLOADING'} ${p.remoteContiguousLength} / ${p.remoteLength}`)
281
+ console.info(
282
+ ` - ${IdEnc.normalize(p.remotePublicKey)} ${done ? 'DONE' : 'DOWNLOADING'} ${p.remoteContiguousLength} / ${p.remoteLength}`
283
+ )
262
284
  }
263
285
  }
264
286
 
265
287
  console.info(' - Blobs core:')
266
- for (const p of drive.blobs.core.replicator.peers) {
288
+ for (const p of drive.blobs?.core?.replicator.peers || []) {
267
289
  const pubKey = IdEnc.normalize(p.remotePublicKey)
268
290
  if (remotes.includes(pubKey)) {
269
291
  const done = p.remoteLength > 0 && p.remoteContiguousLength === p.remoteLength
270
292
  if (remotes && done) nrDoneBlobsBlindPeers++
271
- console.info(` - ${IdEnc.normalize(p.remotePublicKey)} ${done ? 'DONE' : 'DOWNLOADING'} ${p.remoteContiguousLength} / ${p.remoteLength}`)
293
+ console.info(
294
+ ` - ${IdEnc.normalize(p.remotePublicKey)} ${done ? 'DONE' : 'DOWNLOADING'} ${p.remoteContiguousLength} / ${p.remoteLength}`
295
+ )
272
296
  }
273
297
  }
274
298
 
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "hyperdrive-profiler",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "Profile hyperdrive download performance",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "standard"
7
+ "format": "prettier --write .",
8
+ "test": "prettier --check . && lunte"
8
9
  },
9
10
  "bin": {
10
11
  "hyperdrive-profiler": "bin.js",
@@ -31,7 +32,9 @@
31
32
  },
32
33
  "homepage": "https://github.com/holepunchto/hyperdrive-profiler#readme",
33
34
  "devDependencies": {
34
- "standard": "^17.1.2"
35
+ "lunte": "^1.6.0",
36
+ "prettier": "^3.6.2",
37
+ "prettier-config-holepunch": "^2.0.0"
35
38
  },
36
39
  "dependencies": {
37
40
  "bare-events": "^2.5.4",