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

docs: added debugging section #6743

Merged
merged 12 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ validators
**/dist
**/.nyc_output
.tmp
.vscode
jeluard marked this conversation as resolved.
Show resolved Hide resolved
.npmrc
.vscode/launch.json
.vscode/settings.json
.vscode/tasks.json

# Tests artifacts
packages/*/spec-tests*
Expand Down
2 changes: 2 additions & 0 deletions .vscode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Adapt to your needs `launch.template.json` and copy as `launch.json`.
jeluard marked this conversation as resolved.
Show resolved Hide resolved
Follow `docs/pages/tools/debugging.md` for more details.
59 changes: 59 additions & 0 deletions .vscode/launch.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"]
},
{
"type": "node",
"request": "launch",
"name": "Beacon",
"skipFiles": ["<node_internals>/**"],
"smartStep": true,
"program": "${workspaceFolder}/packages/cli/bin/lodestar.js",
"args": ["beacon"],
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Dev",
"skipFiles": ["<node_internals>/**"],
"smartStep": true,
"program": "${workspaceFolder}/packages/cli/bin/lodestar.js",
"args": ["dev"],
"console": "integratedTerminal"
},
{
"name": "Test Current File",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/vitest",
"args": ["--run", "${file}", "-t", "${input:testName}"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a single thread flag here so the test starts up quicker?

Suggested change
"args": ["--run", "${file}", "-t", "${input:testName}"],
"args": [
"--run",
"--pool",
"threads",
"--poolOptions.threads.singleThread",
"-t",
"${input:testName}"
"${file}"
],

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this branch is out of date, I kinda wanna look into not requiring a vs code extension as well to make it easier to use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now uptodate

"cwd": "${workspaceFolder}/${input:packageName}",
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**"]
}
],
"inputs": [
matthewkeil marked this conversation as resolved.
Show resolved Hide resolved
{
"id": "packageName",
"type": "command",
"command": "extension.commandvariable.transform",
jeluard marked this conversation as resolved.
Show resolved Hide resolved
"args": {
"text": "${relativeFileDirname}",
"find": "^(packages/[^/]+).*",
"replace": "$1"
}
},
{
"id": "testName",
"type": "promptString",
"description": "Enter the test name to run, leave empty to run all"
}
]
}
19 changes: 19 additions & 0 deletions docs/pages/tools/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Debugging
---

The simplest way to debug is to use the provided [launch.template.json](https://github.com/ChainSafe/lodestar/blob/unstable/.vscode/launch.template.json) `configurations`. Adapt and copy them as `.vscode/launch.json`, and they will be made available in the `Run and Debug` section. Note that users probably want to adapt the arguments of the beacon [configuration](https://github.com/ChainSafe/lodestar/blob/unstable/.vscode/launch.json#L11) to match their needs.
VS Code supports debugging Workers out of the box when using those configurations.

Remote `lodestar` processes can also be debugged by leveraging [node:inspector](https://nodejs.org/api/inspector.html). Adding `--inspect` to the node CLI (e.g. `NODE_OPTIONS=--inspect ./lodestar beacon`) allows to debug the main thread. To debug a specific `Worker`, follow those steps:

- remove `--inspect` from `node` CLI
- add following code to the `worker`

```js
import inspector from "node:inspector";
inspector.open();
inspector.waitForDebugger();
```

Use VS Code or Chrome devtools to debug those processes.
2 changes: 1 addition & 1 deletion docs/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Tools",
items: ["tools/flamegraphs", "tools/heap-dumps", "tools/core-dumps"],
items: ["tools/debugging", "tools/flamegraphs", "tools/heap-dumps", "tools/core-dumps"],
},
{
type: "category",
Expand Down
Loading