Skip to content

[8.x] @kbn/profiler-cli: collect and display CPU profiles (#216356)#216774

Merged
dgieselaar merged 2 commits intoelastic:8.xfrom
dgieselaar:backport/8.x/pr-216356
Apr 3, 2025
Merged

[8.x] @kbn/profiler-cli: collect and display CPU profiles (#216356)#216774
dgieselaar merged 2 commits intoelastic:8.xfrom
dgieselaar:backport/8.x/pr-216356

Conversation

@dgieselaar
Copy link
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

# @kbn/profiler-cli

Profile Kibana while it's running, and open the CPU profile in
Speedscope.

## Usage

Run a command by either preceding it with the profiler script:
`node scripts/profile.js -- $command`

Or by piping it in:
`$command | node scripts/profile.js`

You can also just run it until SIGINT:

`node scripts/profile.js`

Or with a timeout:

`node scripts/profile.js --timeout=10000`

## Examples

### Commands

You can copy a curl request from the browser, and place it after the
command:

`node scripts/profile.js --connections=10 --amount=50 -- curl ...`

You can also use stdin for this, for example:

`pbpaste | node scripts/profile.js`

When using stdin, take into consideration that there is some lag between
starting the script and connecting the profiler, so the profiler might
miss the first second or so of the running process.

You can also use any other command, like `autocannon`, `sleep` or
`xargs`.

### SigInt

By default, the profiler will run until the process exits:`node
scripts/profile.js`. This is useful when you have a long running process
running separately and you want to collect the profile over a longer
time period. Be aware that this might cause memory issues because the
profile will get huge. When you press Cmd+C, the profiler will
gracefully exit and first write the profile to disk and open Speedscope.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit d1493b9)

# Conflicts:
#	.github/CODEOWNERS
#	src/cli/dev.js
@dgieselaar dgieselaar added the backport This PR is a backport of another PR label Apr 2, 2025
@dgieselaar dgieselaar enabled auto-merge (squash) April 2, 2025 09:12
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/profiler-cli - 1 +1
Unknown metric groups

API count

id before after diff
@kbn/profiler-cli - 1 +1

@dgieselaar dgieselaar merged commit 2089267 into elastic:8.x Apr 3, 2025
8 checks passed
@dgieselaar dgieselaar deleted the backport/8.x/pr-216356 branch April 3, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants