Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PARKED] Collect timeout feature #107

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a1dcceb
Add timeoutDelay arg to constructor
DylanC Feb 5, 2020
cba429a
Wrap collect 0x call in timeout
DylanC Feb 6, 2020
1a34fca
Add time delay parameter for 0x
DylanC Feb 11, 2020
da07855
Change parameter for 0x to be collectDelay
DylanC Feb 11, 2020
b505a61
Update 0x require path
DylanC Feb 18, 2020
60d887d
Update require path and ackage deps for 0x
DylanC Feb 18, 2020
f0d4b9d
Add file to test the new collect delay feature
DylanC Feb 18, 2020
ef05d2e
Fix cleanup fn and linting issues
DylanC Feb 19, 2020
83ea61a
Fix getLoggingPaths for missing /samples
DylanC Feb 19, 2020
f200110
Add another delay fn
DylanC Feb 19, 2020
01a89f6
Add the new collectDelay arg to the readme
DylanC Feb 19, 2020
7b005e0
Match the markdown def for Number
DylanC Feb 19, 2020
c23d79f
Add matching datatype link for Number
DylanC Feb 19, 2020
59447b2
Replace timeouts with syncwait in a separate file
DylanC Feb 20, 2020
d1885c9
Execute both fn and fix delay path
DylanC Feb 20, 2020
0f7cc32
Add fn to search through the tree
DylanC Feb 20, 2020
74cc845
Fix path for npm test
DylanC Feb 25, 2020
0fa1402
Add DS_Store to the ignore list
DylanC Feb 25, 2020
82edbdd
Check both values with tap lib
DylanC Feb 25, 2020
5f5dc1a
Move cleanup into our analyze block
DylanC Feb 25, 2020
642c219
Increase collectDelay for CI
DylanC Feb 25, 2020
2cfc0a2
Use undefined for testing delayOneSecond
DylanC Feb 25, 2020
a9053c3
Remove logging of test inject
DylanC Mar 2, 2020
65e79fb
Increase delay for CI by 200ms
DylanC Mar 2, 2020
d5cc38b
Extend test delay a bit more for CI
DylanC Mar 2, 2020
a140e56
Remove all DS_Store files from the folder
DylanC Mar 3, 2020
38fcdf0
Fire the CI tests again
DylanC Mar 4, 2020
3f4acba
some debugging
goto-bus-stop Mar 10, 2020
ceefd2c
debug: count ticks instead
goto-bus-stop Mar 10, 2020
6f972f4
debug: try an extremely huge collectDelay
goto-bus-stop Mar 10, 2020
f5a4753
log initial delays
goto-bus-stop Mar 10, 2020
4b5fa74
back to 1500ms delay
goto-bus-stop Mar 19, 2020
e2e2132
Remove debug things
goto-bus-stop Mar 19, 2020
707aa93
Revert "Remove debug things"
goto-bus-stop Mar 19, 2020
4084e75
readd debug stuff, list dependency versions on CI
goto-bus-stop Mar 19, 2020
f98a70a
make the timeout super broad again
goto-bus-stop Mar 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.nyc_output
.vscode
.DS_Store
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Programmable interface to [Clinic.js][clinic-url] Flame. Learn more about Clinic

## Supported node versions

* Node.js 8 and above
* Node.js 10 and above

## Example

Expand Down Expand Up @@ -41,6 +41,7 @@ const flame = new ClinicFlame()
**Default**: false
* dest [`<String>`][] The folder where the collected data is stored.
**Default**: '.'
* collectDelay [`<Number>`][] **Default**: 0

#### `flame.collect(args, callback)`

Expand Down Expand Up @@ -76,5 +77,6 @@ possible error.
[`<Object>`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
[`<boolean>`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
[`<String>`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
[`<Number>`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
[azure-status]: https://dev.azure.com/node-clinic/node-clinic/_apis/build/status/nearform.node-clinic-doctor
[azure-url]: https://dev.azure.com/node-clinic/node-clinic/_apis/build/status/nearform.node-clinic-doctor?branchName=master
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class ClinicFlame extends events.EventEmitter {
super()

const {
collectDelay = 0,
detectPort = false,
debug = false,
dest = null
} = settings

this.collectDelay = collectDelay
this.detectPort = detectPort
this.debug = debug
this.path = dest
Expand All @@ -37,7 +39,6 @@ class ClinicFlame extends events.EventEmitter {
path: this.path,
identifier: '{pid}' // replaced with actual pid by 0x
})

callbackify(x({
argv,
onPort: this.detectPort ? onPort : undefined,
Expand All @@ -48,7 +49,8 @@ class ClinicFlame extends events.EventEmitter {
collectOnly: true,
writeTicks: true,
outputDir: paths['/0x-data/'],
workingDir: '.' // 0x temporary working files, doesn't support placeholders like {pid}
workingDir: '.', // 0x temporary working files, doesn't support placeholders like {pid}
collectDelay: this.collectDelay
}), done)

function done (err, dir) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"author": "",
"license": "GPL-3.0-or-later",
"dependencies": {
"0x": "^4.9.1",
"0x": "DylanC/0x#collect_timeout_feature",
"@nearform/clinic-common": "^2.2.0",
"copy-to-clipboard": "^3.0.8",
"d3-array": "^2.0.2",
Expand Down
Binary file added test/.DS_Store
Binary file not shown.
47 changes: 47 additions & 0 deletions test/cmd-collect-delay.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const path = require('path')
const { test } = require('tap')
const rimraf = require('rimraf')
const ClinicFlame = require('../index.js')

test('cmd - test collect - 1s collect delay', (t) => {
const tool = new ClinicFlame({ debug: true, collectDelay: 1000 })
DylanC marked this conversation as resolved.
Show resolved Hide resolved

function cleanup (err, dirname) {
t.ifError(err)
t.match(dirname, /^[0-9]+\.clinic-flame$/)

rimraf(dirname, (err) => {
t.ifError(err)
t.end()
})
}

const searchTree = (tree, target) => {
if (tree.name.includes(target)) {
return tree
}
for (const child of tree.children) {
const res = searchTree(child, target)

if (res) {
return res
}
}
}

tool.collect(
[process.execPath, path.join('test', 'fixtures', 'delay.js')],
function (err, dirname) {
if (err) return cleanup(err, dirname)

const getLoggingPaths = require('../collect/get-logging-paths')
const analyse = require('../analysis')
const paths = getLoggingPaths({ path: dirname })
analyse(paths).then((result) => {
t.equal(searchTree(result.merged, 'delayOneSecond'), null)
t.equal(searchTree(result.merged, 'delayTwoSecond').functionName, 'delayTwoSecond')
cleanup(null, dirname)
})
}
)
})
17 changes: 17 additions & 0 deletions test/fixtures/delay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const syncWait = ms => {
const end = Date.now() + ms
while (Date.now() < end) continue
}

function delayOneSecond () {
syncWait(1000)
console.log('return after one second')
}

function delayTwoSecond () {
syncWait(2000)
console.log('return after two seconds')
}

delayOneSecond()
delayTwoSecond()