UNPKG

3.8 kBMarkdownView Raw
1# Clinic.js Doctor
2
3[![Greenkeeper badge](https://badges.greenkeeper.io/nearform/node-clinic-doctor.svg)](https://greenkeeper.io/)
4[![npm version][npm-version]][npm-url] [![Stability Stable][stability-stable]][stability-docs] [![Azure Pipelines build status][azure-status]][azure-url]
5[![Downloads][npm-downloads]][npm-url] [![Code style][lint-standard]][lint-standard-url]
6
7Programmable interface to [Clinic.js][clinic-url] Doctor. Learn more about Clinic.js: https://clinicjs.org/
8
9![Screenshot](screenshot.png)
10
11## Supported node versions
12
13* Node.js 10.0.0 and above
14* Node.js 9.4.0 and above
15* Node.js 8.10.0 and above
16
17Node.js 8.9.4 also works, however you have to listen to `SIGINT` and shutdown
18the process nicely.
19
20## Example
21
22```js
23const ClinicDoctor = require('@nearform/doctor')
24const doctor = new ClinicDoctor()
25
26doctor.collect(['node', './path-to-script.js'], function (err, filepath) {
27 if (err) throw err
28
29 doctor.visualize(filepath, filepath + '.html', function (err) {
30 if (err) throw err
31 });
32})
33```
34
35You can find examples in
36[node-clinic-doctor-examples](https://github.com/nearform/node-clinic-doctor-examples)
37
38## Documentation
39
40```js
41const ClinicDoctor = require('@nearform/doctor')
42const doctor = new ClinicDoctor()
43```
44
45### new ClinicDoctor([settings])
46
47* settings [`<Object>`][]
48 * sampleInterval [`<number>`][] Time between each sample in milliseconds.
49 **Default**: 10
50 * detectPort [`<boolean>`][] **Default**: false
51 * dest [`<String>`][] The folder where the collected data is stored. **Default**: '.'
52 * debug [`<boolean>`][] If set to true, the generated html will not be minified.
53 **Default**: false
54
55#### `doctor.collect(args, callback)`
56
57Starts a process by using:
58
59```js
60const { spawn } = require('child_process')
61spawn(args[0], ['-r', 'sampler.js'].concat(args.slice(1)))
62```
63
64The injected sampler will produce a file in the current working directory, with
65the process PID in its filename. The filepath relative to the current working
66directory will be the value in the callback.
67
68stdout, stderr, and stdin will be relayed to the calling process. As will the
69`SIGINT` event.
70
71#### `doctor.visualize(dataFilename, outputFilename, callback)`
72
73Will consume the datafile specified by `dataFilename`, this datafile will be
74produced by the sampler using `doctor.collect`.
75
76`doctor.visualize` will then output a standalone HTML file to `outputFilename`.
77When completed the `callback` will be called with no extra arguments, except a
78possible error.
79
80## License
81[GPL 3.0](LICENSE)
82
83[stability-stable]: https://img.shields.io/badge/stability-stable-green.svg?style=flat-square
84[stability-docs]: https://nodejs.org/api/documentation.html#documentation_stability_index
85[npm-version]: https://img.shields.io/npm/v/@nearform/clinic-doctor.svg?style=flat-square
86[npm-url]: https://www.npmjs.org/@nearform/clinic-doctor
87[npm-downloads]: http://img.shields.io/npm/dm/@nearform/clinic-doctor.svg?style=flat-square
88[lint-standard]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
89[lint-standard-url]: https://github.com/feross/standard
90[clinic-url]: https://github.com/nearform/node-clinic
91[`<Object>`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
92[`<boolean>`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
93[`<number>`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type
94[`<String>`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
95[azure-status]: https://dev.azure.com/node-clinic/node-clinic/_apis/build/status/nearform.node-clinic-doctor
96[azure-url]: https://dev.azure.com/node-clinic/node-clinic/_apis/build/status/nearform.node-clinic-doctor?branchName=master