-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Support pprof profiling feature #13502
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
Merged
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
41acb04
feat: support pprof feature
JophieQu 6b4640f
fix
JophieQu a54d8dc
fix
JophieQu d069e68
fix: rollback yaml
JophieQu 1afb571
fix
JophieQu 2578bd1
fix
JophieQu 4c03a81
add jdbc & es storage
JophieQu 5520d01
test ci
JophieQu c965482
update proto
JophieQu c467076
fix query submules
JophieQu 5000e71
fix ci
JophieQu cce039d
fix ci
JophieQu 3989494
ci test (to rollback)
JophieQu 232cdc4
fix
JophieQu 1dc8fcd
Merge remote-tracking branch 'origin/master' into ci
JophieQu e8f44ad
fix
JophieQu f46887f
fix e2e
JophieQu f49e7a3
fix e2e
JophieQu 3449d89
fix e2e docker path
JophieQu 26956b0
fix
JophieQu baaf886
fix
JophieQu 62fd3fb
fix
JophieQu 88692d1
fix duration
JophieQu 843585f
fix
JophieQu 07fe14c
fix port
JophieQu 2e62876
fix e2e
JophieQu 02a5b55
fix e2e
JophieQu ed0403a
fix e2e
JophieQu fc0ae02
Add self obs metrics for L1/L2 queue and persistent cache. (#13405)
wankai123 b3d09ca
add design doc
JophieQu c6d7a79
fix so11y UI template MQE (#13411)
wankai123 e8253f0
test ci
JophieQu a438569
merge
JophieQu 4df8bd2
merge change
JophieQu 78d2e8a
Merge branch 'ci' into feat/pprof
JophieQu b5f3e89
rollback ci
JophieQu 57fc59f
rollback ci
JophieQu 1b7d636
Merge remote-tracking branch 'origin/master' into feat/pprof
JophieQu 39911d4
fix ci
JophieQu 78a2c9c
test ci(to roll back)
JophieQu a4882ff
test ci(to roll back)
JophieQu ba4f02f
fix ci
JophieQu 9c1379a
fix
JophieQu 6a2dd3a
test
JophieQu 050a339
Fix
JophieQu 602917d
fix go agent e2e
JophieQu 32f384d
fix
JophieQu e76bdd5
Merge branch 'master' into feat/pprof
wu-sheng 296ed0f
fix e2e, roll back LICENSE
JophieQu 1906182
fix change.md
JophieQu 233027b
Merge branch 'feat/pprof' of https://github.com/JophieQu/skywalking i…
JophieQu 7bc7d60
roll back ci
JophieQu 9e9eb9d
roll back LICENSE
JophieQu 6a4ed7f
roll back
JophieQu 93b407b
fix doc
JophieQu 55d67eb
add doc
JophieQu 8790b79
roll back
JophieQu 7f6267b
Merge branch 'master' into feat/pprof
mrproliu 2431af5
roll back ui submodule
JophieQu 0e397af
roll back & test ci
JophieQu 901eeaa
test ci
JophieQu ad6e7ae
fix: format the code
JophieQu 3e4c261
fix doc
JophieQu d3763bc
roll back ui
JophieQu e60e3d5
roll back ci
JophieQu 36a83c9
Merge branch 'master' into feat/pprof
wu-sheng 5b6ffae
fix pprof cache
JophieQu 6bb29d4
fix get pprof task
JophieQu f979edd
Merge branch 'ci1' into feat/pprof
JophieQu 8adfd28
Merge branch 'feat/pprof' of https://github.com/JophieQu/skywalking i…
JophieQu f613cbd
delete blank lines
JophieQu 02d2964
fix doc & mock oap
JophieQu 4f76698
roll back proto
JophieQu 49d84a0
roll back
JophieQu 79a74bb
Merge branch 'master' into feat/pprof
mrproliu ce5384b
fix codestyle
JophieQu 5226098
Merge branch 'feat/pprof' of https://github.com/JophieQu/skywalking i…
JophieQu 4c47d09
fix
JophieQu a895cba
fix doc
JophieQu c2825e7
fix doc
JophieQu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...va/org/apache/skywalking/oap/server/network/trace/component/command/PprofTaskCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.skywalking.oap.server.network.trace.component.command; | ||
|
|
||
| import org.apache.skywalking.apm.network.common.v3.Command; | ||
| import org.apache.skywalking.apm.network.common.v3.KeyStringValuePair; | ||
| import java.util.List; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class PprofTaskCommand extends BaseCommand implements Serializable, Deserializable<PprofTaskCommand> { | ||
| public static final Deserializable<PprofTaskCommand> DESERIALIZER = new PprofTaskCommand("", "", "", 0, 0, 0); | ||
| public static final String NAME = "PprofTaskQuery"; | ||
| /** | ||
| * pprof taskId | ||
| */ | ||
| private String taskId; | ||
| /** | ||
| * event type of profiling (CPU/Heap/Block/Mutex/Goroutine/Threadcreate/Allocs) | ||
| */ | ||
| private String events; | ||
| /** | ||
| * run profiling for duration (minute) | ||
| */ | ||
| private long duration; | ||
| /** | ||
| * task create time | ||
| */ | ||
| private long createTime; | ||
| /** | ||
| * pprof dump period parameters. There are different dumpperiod configurations for different events. | ||
| * Here is a table of parameters. | ||
| * | ||
| * <p>for Block - sample an average of one blocking event per rate nanoseconds spent blocked. (default: 0)</p> | ||
| * <p>for Mutex - sample an average of 1/rate events are reported. (default: 0)</p> | ||
| * details @see <a href="https://pkg.go.dev/runtime/pprof">pprof argument</a> | ||
| */ | ||
| private int dumpPeriod; | ||
|
|
||
| public PprofTaskCommand(String serialNumber, String taskId, String events, | ||
| long duration, long createTime, int dumpPeriod) { | ||
| super(NAME, serialNumber); | ||
| this.taskId = taskId; | ||
| this.duration = duration; | ||
| this.createTime = createTime; | ||
| this.dumpPeriod = dumpPeriod; | ||
| this.events = events; | ||
| } | ||
|
|
||
| @Override | ||
| public PprofTaskCommand deserialize(Command command) { | ||
| final List<KeyStringValuePair> argsList = command.getArgsList(); | ||
| String taskId = null; | ||
| String events = null; | ||
| long duration = 0; | ||
| long createTime = 0; | ||
| int dumpPeriod = 0; | ||
| String serialNumber = null; | ||
| for (final KeyStringValuePair pair : argsList) { | ||
| if ("SerialNumber".equals(pair.getKey())) { | ||
| serialNumber = pair.getValue(); | ||
| } else if ("TaskId".equals(pair.getKey())) { | ||
| taskId = pair.getValue(); | ||
| } else if ("Events".equals(pair.getKey())) { | ||
| events = pair.getValue(); | ||
| } else if ("Duration".equals(pair.getKey())) { | ||
| duration = Long.parseLong(pair.getValue()); | ||
| } else if ("CreateTime".equals(pair.getKey())) { | ||
| createTime = Long.parseLong(pair.getValue()); | ||
| } else if ("DumpPeriod".equals(pair.getKey())) { | ||
| dumpPeriod = Integer.parseInt(pair.getValue()); | ||
| } | ||
| } | ||
| return new PprofTaskCommand(serialNumber, taskId, events, duration, createTime, dumpPeriod); | ||
| } | ||
|
|
||
| @Override | ||
| public Command.Builder serialize() { | ||
| final Command.Builder builder = commandBuilder(); | ||
| builder.addArgs(KeyStringValuePair.newBuilder().setKey("TaskId").setValue(taskId)) | ||
| .addArgs(KeyStringValuePair.newBuilder().setKey("Events").setValue(events)) | ||
| .addArgs(KeyStringValuePair.newBuilder().setKey("Duration").setValue(String.valueOf(duration))) | ||
| .addArgs(KeyStringValuePair.newBuilder().setKey("CreateTime").setValue(String.valueOf(createTime))) | ||
| .addArgs(KeyStringValuePair.newBuilder().setKey("DumpPeriod").setValue(String.valueOf(dumpPeriod))); | ||
| return builder; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # Go App Profiling | ||
|
|
||
| Go App Profiling uses the pprof for sampling | ||
|
|
||
| pprof is bundled within the auto-instrument agent and corresponds to [In-Process Profiling](../../concepts-and-designs/profiling.md#in-process-profiling). | ||
|
|
||
| It is delivered to the agent in the form of a task, allowing it to be enabled or disabled dynamically. | ||
| When service encounters performance issues (CPU usage, memory allocation, etc.), pprof task can be created. | ||
| When the agent receives a task, it enables pprof for sampling. | ||
| After sampling is completed, the sampling results are analyzed by requesting the server to render a flame graph for performance | ||
| analysis to determine the specific business code lines that cause performance problems. | ||
| Note, tracing profiling in the Go agent relies on the Go runtime’s global CPU sampling used by pprof. | ||
| Since only one CPU profiler can run at a time within the same instance, tracing and pprof CPU profiling cannot be enabled simultaneously. | ||
| If both are activated on the same instance, one task may fail to start. | ||
wu-sheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Activate pprof in the OAP | ||
| OAP and the agent use a brand-new protocol to exchange pprof data, so it is necessary to start OAP with the following configuration: | ||
|
|
||
| ```yaml | ||
| receiver-pprof: | ||
| selector: ${SW_RECEIVER_PPROF:default} | ||
| default: | ||
| # Used to manage the maximum size of the pprof file that can be received, the unit is Byte, default is 30M | ||
| pprofMaxSize: ${SW_RECEIVER_PPROF_MAX_SIZE:31457280} | ||
| # Used to determine whether to receive pprof in memory file or physical file mode | ||
| # | ||
| # The memory file mode have fewer local file system limitations, so they are by default. But it costs more memory. | ||
| # | ||
| # The physical file mode will use less memory when parsing and is more friendly to parsing large files. | ||
| # However, if the storage of the tmp directory in the container is insufficient, the oap server instance may crash. | ||
| # It is recommended to use physical file mode when volume mounting is used or the tmp directory has sufficient storage. | ||
| memoryParserEnabled: ${SW_RECEIVER_PPROF_MEMORY_PARSER_ENABLED:true} | ||
| ``` | ||
|
|
||
| ## pprof Task with Analysis | ||
|
|
||
| To use the pprof feature, please follow these steps: | ||
|
|
||
| 1. **Create pprof task**: Use the UI or CLI tool to create a task. | ||
| 2. **Wait agent collect data and upload**: Wait for pprof to collect pprof data and report. | ||
| 3. **Query task progress**: Query the progress of tasks, including analyzing successful and failed instances and task logs. | ||
| 4. **Analyze the data**: Analyze the pprof data to determine where performance bottlenecks exist in the service. | ||
|
|
||
| ### Create an pprof task | ||
|
|
||
| Create an pprof task to notify some go-agent instances in the execution service to start pprof for data collection. | ||
|
|
||
| When creating a task, the following configuration fields are required: | ||
|
|
||
| 1. **serviceId**: Define the service to execute the task. | ||
| 2. **serviceInstanceIds**: Define which instances need to execute tasks. | ||
| 3. **duration**: Define the duration of this task in minutes, required for CPU, BLOCK, MUTEX events. | ||
| 4. **events**: Define which event types this task needs to collect. | ||
| 5. **dumpPeriod**: Define the period of the pprof dump, required for BLOCK, MUTEX events. | ||
|
|
||
| When the Agent receives a pprof task from OAP, it automatically generates a log to notify that the task has been acknowledged. The log contains the following field information: | ||
|
|
||
| 1. **Instance**: The name of the instance where the Agent is located. | ||
| 2. **Type**: Supports "NOTIFIED" and "EXECUTION_FINISHED" and "PPROF_UPLOAD_FILE_TOO_LARGE_ERROR", "EXECUTION_TASK_ERROR", with the current log displaying "NOTIFIED". | ||
| 3. **Time**: The time when the Agent received the task. | ||
|
|
||
| ### Wait the agent to collect data and upload | ||
|
|
||
| At this point, pprof will trace the events you selected when you created the task: | ||
|
|
||
| 1. CPU: samples CPU usage over time to show which functions consume the most processing time. | ||
| 2. ALLOC, HEAP: | ||
| - HEAP: a sampling of memory allocations of live objects. | ||
| - ALLOC: a sampling of all past memory allocations. | ||
| 3. BLOCK, MUTEX: | ||
| - BLOCK: stack traces that led to blocking on synchronization primitives. | ||
| - MUTEX: stack traces of holders of contended mutexes. | ||
| 4. GOROUTINE, THREADCREAT: | ||
| - GOROUTINE: stack traces of all current goroutines. | ||
| - THREADCREATE: stack traces that led to the creation of new OS threads. | ||
|
|
||
| Finally, the agent will upload the pprof file produced by pprof to the oap server for online performance analysis. | ||
|
|
||
| ### Query the profiling task progresses | ||
|
|
||
| Wait for pprof to complete data collection and upload successfully. | ||
| We can query the execution logs of the pprof task and the task status, which includes the following information: | ||
|
|
||
| 1. **successInstanceIds**: SuccessInstanceIds gives instances that have executed the task successfully. | ||
| 2. **errorInstanceIds**: ErrorInstanceIds gives instances that failed to execute the task. | ||
| 3. **logs**: All task execution logs of the current task. | ||
| 1. **id**: The task id. | ||
| 2. **instanceId**: InstanceId is the id of the instance which reported this task log. | ||
| 3. **instanceName**: InstanceName is the name of the instance which reported this task log. | ||
| 4. **operationType**: Contains "NOTIFIED" and "EXECUTION_FINISHED" and "PPROF_UPLOAD_FILE_TOO_LARGE_ERROR", "EXECUTION_TASK_ERROR". | ||
| 5. **operationTime**: operationTime is the time when the operation occurs. | ||
|
|
||
| ### Analyze the profiling data | ||
|
|
||
| Once some agents completed the task, we can analyze the data through the following query: | ||
|
|
||
| 1. **taskId**: The task id. | ||
| 2. **instanceIds**: InstanceIds defines the instances to be included for analysis | ||
|
|
||
| After the query, the following data would be returned to render a flame graph: | ||
| 1. **taskId**: The task id. | ||
| 2. **elements**: Combined with "id" to determine the hierarchical relationship. | ||
| 1. **Id**: Id is the identity of the stack element. | ||
| 2. **parentId**: Parent element ID. The dependency relationship between elements can be determined using the element ID and parent element ID. | ||
| 3. **codeSignature**: Method signatures in tree nodes. | ||
| 4. **total**:The total number of samples of the current tree node, including child nodes. | ||
| 5. **self**: The sampling number of the current tree node, excluding samples of the children. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should be linked from doc menu.