github.com/grafana/pyroscope@v1.18.0/docs/sources/view-and-analyze-profile-data/profile-cli.md (about) 1 --- 2 aliases: 3 - /docs/phlare/latest/operators-guide/configuring/profile-cli/ 4 - /docs/phlare/latest/profile-cli/ 5 - /docs/pyroscope/latest/configure-server/profile-cli/ 6 - ../ingest-and-analyze-profile-data/profile-cli/ 7 description: Getting started with the profile CLI tool. 8 menuTitle: Profile CLI 9 title: Profile CLI 10 weight: 500 11 --- 12 13 # Profile CLI 14 15 Pyroscope provides a command-line interface (CLI), `profilecli`. 16 This utility enables various productivity flows such as: 17 18 - Interacting with a running Pyroscope server to upload profiles, query data, and more 19 - Inspecting [Parquet](https://parquet.apache.org/docs/) files 20 21 {{< admonition type="tip">}} 22 Use the `help` command (`profilecli help`) for a full list of capabilities and help information. 23 {{< /admonition>}} 24 25 ## Install Profile CLI 26 27 You can install Profile CLI using a package or by compiling the code. 28 29 ### Install using a package 30 31 On macOS, you can install Profile CLI using [HomeBrew](https://brew.sh): 32 33 ```bash 34 brew install pyroscope-io/brew/profilecli 35 ``` 36 37 For other platforms, you can manually [download the `profilecli` release asset](https://github.com/grafana/pyroscope/releases/latest) for your operating system and architecture and make it executable. 38 39 For example, for Linux with the AMD64 architecture: 40 41 1. Download and extract the package (archive). 42 43 ```bash 44 curl -fL https://github.com/grafana/pyroscope/releases/download/v1.13.2/profilecli_1.13.2_linux_amd64.tar.gz | tar xvz 45 ``` 46 47 1. Make `profilecli` executable: 48 49 ```bash 50 chmod +x profilecli 51 ``` 52 53 1. Optional: Make `profilecli` reachable from anywhere: 54 55 ```bash 56 sudo mv profilecli /usr/local/bin 57 ``` 58 59 ### Build from source code 60 61 To build from source code, you must have: 62 63 - Go installed (> 1.19). 64 - Either `$GOPATH` or `$GOBIN` configured and added to your `PATH` environment variable. 65 66 To build the source code: 67 68 1. Clone the repository. 69 70 ```bash 71 git clone git@github.com:grafana/pyroscope.git 72 ``` 73 74 1. Run the Go install command to build and install the package. 75 76 ```bash 77 cd pyroscope 78 go install ./cmd/profilecli 79 ``` 80 81 The command places the `profilecli` executable in `$GOPATH/bin/` (or `$GOBIN/`) and make it available to use. 82 83 84 ## Common flags and environment variables 85 86 The `profilecli` commands that interact with a Pyroscope server require a server URL and optionally authentication details. These can be provided as command-line flags or environment variables. 87 88 1. Server URL 89 90 `default: http://localhost:4040` 91 92 The `--url` flag specifies the server against which the command will run. 93 If using Grafana Cloud, an example URL could be `https://profiles-prod-001.grafana.net`. 94 For local instances, the URL could look like `http://localhost:4040`. 95 96 1. Authentication details. 97 98 `default: <empty>` 99 100 If using Grafana Cloud or authentication is enabled on your Pyroscope server, you will need to provide a username and password using the `--username` and `--password` flags respectively. 101 For Grafana Cloud, the username will be the Stack ID and the password the generated API token. 102 103 ### Environment variable naming 104 105 You can use environment variables to avoid passing flags to the command every time you use it, or to protect sensitive information. 106 Environment variables have a `PROFILECLI_` prefix. Here is an example of providing the server URL and credentials for the `profilecli` tool: 107 108 ```bash 109 export PROFILECLI_URL=<pyroscope_server_url> 110 export PROFILECLI_USERNAME=<username> 111 export PROFILECLI_PASSWORD=<password> 112 # now we can run a profilecli command without specifying the url or credentials: 113 profilecli <command> 114 ``` 115 116 {{< admonition type="caution" >}} 117 If you're querying data from Cloud Profiles, be sure to use the url of your Cloud Profiles server in `PROFILECLI_URL` (e.g. `https://profiles-prod-001.grafana.net`) and **not** the url of your Grafana Cloud tenant (e.g. `<your tenant>.grafana.net`). 118 {{< /admonition >}} 119 120 ## Upload a profile to a Pyroscope server using `profilecli` 121 122 Using `profilecli` streamlines the process of uploading profiles to Pyroscope, making it a convenient alternative to manual HTTP requests. 123 124 ### Before you begin 125 126 - Ensure you have `profilecli` installed on your system by following the [installation](#install-profile-cli) steps above. 127 - Have a profile file ready for upload. Note that you can only upload pprof files at this time. 128 129 ### Upload steps 130 131 1. Identify the pprof file. 132 133 - Path to your pprof file: `path/to/your/pprof-file.pprof` 134 135 1. Optional: Specify any extra labels. 136 137 - You can add additional labels to your uploaded profile using the `--extra-labels` flag. 138 - You can provide the name of the application that the profile was captured from via the `service_name` label (defaults to `profilecli-upload`). This will be useful when querying the data via `profilecli` or the UI. 139 - You can use the flag multiple times to add several labels. 140 141 1. Construct and execute the Upload command. 142 143 - Here's a basic command template: 144 ```bash 145 export PROFILECLI_URL=<pyroscope_server_url> 146 export PROFILECLI_USERNAME=<username> 147 export PROFILECLI_PASSWORD=<password> 148 149 profilecli upload --extra-labels=<label_name>=<label_value> <pprof_file_path> 150 ``` 151 152 - Example command: 153 ```bash 154 export PROFILECLI_URL=https://profiles-prod-001.grafana.net 155 export PROFILECLI_USERNAME=my_username 156 export PROFILECLI_PASSWORD=my_password 157 158 profilecli upload path/to/your/pprof-file.pprof 159 ``` 160 161 - Example command with extra labels: 162 ```bash 163 export PROFILECLI_URL=https://profiles-prod-001.grafana.net 164 export PROFILECLI_USERNAME=my_username 165 export PROFILECLI_PASSWORD=my_password 166 167 profilecli upload \ 168 --extra-labels=service_name=my_application_name \ 169 --extra-labels=cluster=us-east \ 170 path/to/your/pprof-file.pprof 171 ``` 172 173 1. Check for successful upload. 174 175 - After running the command, you should see a confirmation message indicating a successful upload. If there are any issues, `profilecli` provides error messages to help you troubleshoot. 176 177 ## Query a Pyroscope server using `profilecli` 178 179 You can use the `profilecli query` command to look up the available profiles on a Pyroscope server and read actual profile data. 180 This can be useful for debugging purposes or for integrating profiling in CI pipelines (for example to facilitate [profile-guided optimization](https://go.dev/doc/pgo)). 181 182 ### Look up available profiles on a Pyroscope server 183 184 You can use the `profilecli query series` command to look up the available profiles on a Pyroscope server. 185 By default, it queries the last hour of data, though this can be controlled with the `--from` and `--to` flags. 186 You can narrow the results down with the `--query` flag. See `profilecli help query series` for more information. 187 188 #### Query series steps 189 190 1. Optional: Specify a query and a time range. 191 192 - You can provide a label selector using the `--query` flag, for example: `--query='{service_name="my_application_name"}'`. 193 - You can provide a custom time range using the `--from` and `--to` flags, for example, `--from="now-3h" --to="now"`. 194 195 1. Construct and execute the Query Series command. 196 197 - Here's a basic command template: 198 ```bash 199 export PROFILECLI_URL=<pyroscope_server_url> 200 export PROFILECLI_USERNAME=<username> 201 export PROFILECLI_PASSWORD=<password> 202 203 profilecli query series --query='{<label_name>="<label_value>"}' 204 ``` 205 206 - Example command: 207 ```bash 208 export PROFILECLI_URL=https://profiles-prod-001.grafana.net 209 export PROFILECLI_USERNAME=my_username 210 export PROFILECLI_PASSWORD=my_password 211 212 profilecli query series --query='{service_name="my_application_name"}' 213 ``` 214 215 - Example output: 216 ```json 217 { 218 "__name__":"memory", 219 "__period_type__":"space", 220 "__period_unit__":"bytes", 221 "__profile_type__":"memory:inuse_objects:count:space:bytes", 222 "__service_name__":"my_application_name", 223 "__type__":"inuse_objects", 224 "__unit__":"count", 225 "cluster":"eu-west-1", 226 "service_name":"my_application_name" 227 } 228 ``` 229 230 ### Read a raw profile from a Pyroscope server 231 232 You can use the `profilecli query profile` command to retrieve a merged (aggregated) profile from a Pyroscope server. 233 The command merges all samples found in the profile store for the specified query and time range. 234 By default it looks for samples within the last hour, though this can be controlled with the `--from` and `--to` flags. The source data can be narrowed down with the `--query` flag in the same way as with the `series` command. 235 236 #### Query profile steps 237 238 1. Specify optional flags. 239 240 - You can provide a label selector using the `--query` flag, for example, `--query='{service_name="my_application_name"}'`. 241 - You can provide a custom time range using the `--from` and `--to` flags, for example, `--from="now-3h" --to="now"`. 242 - You can specify the profile type via the `--profile-type` flag. The available profile types are listed in the output of the `profilecli query series` command. 243 244 2. Construct and execute the `query profile` command. 245 246 - Here's a basic command template: 247 ```bash 248 export PROFILECLI_URL=<pyroscope_server_url> 249 export PROFILECLI_USERNAME=<username> 250 export PROFILECLI_PASSWORD=<password> 251 252 profilecli query profile \ 253 --profile-type=<profile_type> \ 254 --query='{<label_name>="<label_value>"}' \ 255 --from="<from>" --to="<to>" 256 ``` 257 258 - Example command: 259 ```bash 260 export PROFILECLI_URL=https://profiles-prod-001.grafana.net 261 export PROFILECLI_USERNAME=my_username 262 export PROFILECLI_PASSWORD=my_password 263 264 profilecli query profile \ 265 --profile-type=memory:inuse_space:bytes:space:bytes \ 266 --query='{service_name="my_application_name"}' \ 267 --from="now-1h" --to="now" 268 ``` 269 270 - Example output: 271 ```bash 272 level=info msg="query aggregated profile from profile store" url=http://localhost:4040 from=2023-12-11T13:38:33.115683-04:00 to=2023-12-11T14:38:33.115684-04:00 query={} type=memory:inuse_space:bytes:space:bytes 273 PeriodType: space bytes 274 Period: 524288 275 Time: 2023-12-11 13:59:59.999 -0400 AST 276 Duration: 59m5 277 Samples: 278 inuse_space/bytes[dflt] 279 115366240: 107 13 14 15 16 17 1 2 3 280 ... 281 ``` 282 283 ### Export a profile for Go PGO 284 285 You can use the `profilecli query go-pgo` command to retrieve an aggregated profile from a Pyroscope server for use with Go PGO. 286 Profiles retrieved with `profilecli query profile` include all samples found in the profile store, resulting in a large profile size. 287 The profile size may cause issues with network transfer and slow down the PGO process. 288 In contrast, profiles retrieved with `profilecli query go-pgo` include only the information used in Go PGO, making them significantly smaller and more efficient to handle. 289 By default, it looks for samples within the last hour, though this can be controlled with the `--from` and `--to` flags. The source data can be narrowed down with the `--query` flag in the same way as with the `query` command. 290 291 1. Specify optional flags. 292 293 - You can provide a label selector using the `--query` flag, for example, `--query='{service_name="my_application_name"}'`. 294 - You can provide a custom time range using the `--from` and `--to` flags, for example, `--from="now-3h" --to="now"`. 295 - You can specify the profile type via the `--profile-type` flag. The available profile types are listed in the output of the `profilecli query series` command. 296 - You can specify the number of leaf locations to keep via the `--keep-locations` flag. The default value is `5`. The Go compiler does not use the full stack trace. Reducing the number helps to minimize the profile size. 297 - You can control whether to use callee aggregation with the `--aggregate-callees` flag. By default, this option is enabled, meaning samples are aggregated based on the leaf location, disregarding the callee line number, which the Go compiler does not utilize. To disable aggregation, use the `--no-aggregate-callees` flag. 298 299 2. Construct and execute the command. 300 301 - Example command: 302 ```bash 303 export PROFILECLI_URL=https://profiles-prod-001.grafana.net 304 export PROFILECLI_USERNAME=my_username 305 export PROFILECLI_PASSWORD=my_password 306 307 profilecli query go-pgo \ 308 --query='{service_name="my_service"}' \ 309 --from="now-1h" --to="now" 310 ``` 311 312 - Example output: 313 ```bash 314 level=info msg="querying pprof profile for Go PGO" url=https://localhost:4040 query="{service_name=\"my_service\"}" from=2024-06-20T12:32:20+08:00 to=2024-06-20T15:24:40+08:00 type=process_cpu:cpu:nanoseconds:cpu:nanoseconds output="pprof=default.pgo" keep-locations=5 aggregate-callees=true 315 # By default, the profile is saved to the current directory as `default.pgo` 316 ```