Comparing version 1.3.3 to 1.4.0
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const v8 = require('v8'); | ||
const Promise = require('bluebird'); | ||
@@ -10,5 +12,28 @@ const times = require('./times'); | ||
return Promise.map(times(opts.count), () => { | ||
return Promise.map(opts.url, iterator, { concurrency: concurrency }); | ||
}, { concurrency: 1 }) | ||
let interrupted = false; | ||
process.on('SIGINT', () => { | ||
if (interrupted) { | ||
process.exit(); | ||
} else { | ||
interrupted = true; | ||
console.log('\nShutting down gracefully - CTRL^C again to terminate immediately'); | ||
} | ||
}); | ||
return Promise.reduce(times(opts.count), (results, i) => { | ||
if (interrupted) { | ||
// if count is set very high then we can hit maximum call stack size | ||
// introduce some async every 1000 iterations to break call stack | ||
return i % 1000 ? results : Promise.delay(0).then(() => results); | ||
} | ||
const memory = v8.getHeapStatistics(); | ||
if (memory.total_available_size / memory.heap_size_limit < 0.1) { | ||
console.log('Less than 10% of process memory limit remaining. Terminating...'); | ||
console.log('To increase available memory start with `--max_old_space_size=<size>`'); | ||
interrupted = true; | ||
return results; | ||
} else { | ||
return Promise.map(opts.url, iterator, { concurrency: concurrency }) | ||
.then((logs) => results.concat([logs])); | ||
} | ||
}, []) | ||
.then(zip); | ||
@@ -15,0 +40,0 @@ } |
{ | ||
"name": "timeliner", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"description": "Network Timeline Analyser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -61,5 +61,4 @@ # timeliner | ||
.then(timeliner.reporters.basic) | ||
.then((results) => { | ||
// your code here | ||
}); | ||
.then(timeliner.reporters.table) | ||
.then(result => console.log(result)); | ||
``` | ||
@@ -107,4 +106,8 @@ | ||
### Using `console.timeStamp` | ||
You can fire custom events by calling `console.timeStamp` from anywhere within your code with a label that matches `timeliner.*`. This will then report the first occurence of that event with a metric name of the wildcard portion of the timestamp label. | ||
These can either be fired directly by the site under test, or injected as part of the test run using the `inject` option. | ||
Example - inject some custom javascript into your page to trigger a custom event after 1 second. | ||
@@ -126,2 +129,26 @@ | ||
}); | ||
``` | ||
``` | ||
### In Code | ||
You can pass an optional function to the `basic` reporter as a second argument which can execute custom metrics and output them in a form compatible with the `table` reporter. | ||
The function should take a single set of logs as an argument and return an object keyed by metric names and with values corresponding to the value of each metric. | ||
Example: | ||
```javascript | ||
const timeliner = require('timeliner'); | ||
function customMetrics (logs) { | ||
// value = do some big map-reduce on the logs | ||
return { | ||
'my-metric': value | ||
} | ||
} | ||
timeliner({ url: 'http://google.com' }) | ||
.then(logs => timeliner.reporters.basic(logs, customMetrics)) | ||
.then(timeliner.reporters.table) | ||
.then(result => console.log(result)); | ||
``` |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
23594
416
152
1