-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat(add go profile data collect and analyze) #13524
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
89 commits
Select commit
Hold shift + click to select a range
46ed258
Update apm-network proto submodule manually
cqhasy c556d8d
feat(add go profile data collect、prase、store)
cqhasy 5f01462
feat(add go analyzer)
cqhasy 332747d
fix(remove the start label)
cqhasy ac584f9
Merge branch 'master' into master
cqhasy e285f20
docs:(update the changes.md)
cqhasy b15c41c
feat(add go profile e2e test)
cqhasy 1593082
test ci
cqhasy 0eb4f7e
fix(delete wrong java expeected)
cqhasy 50f2d34
feat(test:go;ci)add go profile test,add to ci
cqhasy 1a1f882
feat ci error
cqhasy ee3e750
feat ci error
cqhasy c84db28
feat ci error
cqhasy bcdc2cc
feat ci error
cqhasy cc2b3cc
feat ci error
cqhasy 07eef41
feat ci error
cqhasy ea46b39
feat ci error
cqhasy 3c72f4d
feat ci error
cqhasy c4f9e1f
feat ci error
cqhasy 412e752
feat ci error
cqhasy 3add337
feat ci error
cqhasy 3044195
merge pprof
cqhasy b0d71f8
update query-protocol
cqhasy 120860e
update query-protocol
cqhasy 882ae0d
add some log for go profile e2e
cqhasy d4136ab
add some log for go profile e2e
cqhasy 49e0c76
fix ci
cqhasy ec1d993
fix ci
cqhasy 71e059e
fix ci
cqhasy 34656a8
fix ci
cqhasy f98ebc7
fix ci
cqhasy ce666ce
fix ci
cqhasy 1098d3a
fix ci
cqhasy 6c1ab7b
fix ci
cqhasy a28d2aa
fix ci
cqhasy fa82fc1
fix ci
cqhasy e81831e
fix ci
cqhasy e95dd79
fix ci
cqhasy 1f47a62
fix ci
cqhasy 72bf450
fix ci
cqhasy 2963949
fix ci
cqhasy bb5b290
fix ci
cqhasy de1717f
fix ci
cqhasy 625226f
fix ci
cqhasy f3322d1
fix ci
cqhasy 1e5ceae
fix ci
cqhasy 176d64f
fix ci
cqhasy 9ba032f
fix ci
cqhasy 600e083
fix ci
cqhasy f681970
fix ci
cqhasy 256cf08
fix ci
cqhasy ba0fd1e
fix ci
cqhasy fbf76d2
fix ci
cqhasy 3044b47
fix ci
cqhasy fa94f1d
test ci
cqhasy 998ccdb
Set skywalking-ui to commit 51817f32de0cd5c4fc78f9c25399316f23d782e8
cqhasy 16f1f72
test ci
cqhasy 3a0b246
roll back ci
cqhasy 7cb024a
fix(move go profile to pofiling)
cqhasy 959479e
fix(move go profile to pofiling)
cqhasy 9eac3b9
fix(move go profile to pofiling)
cqhasy d73595d
fix(move go profile to pofiling)
cqhasy cee4873
fix(move go profile to pofiling)
cqhasy eee3c65
fix(roll back ui)
cqhasy f0a9af4
fix ci
cqhasy a60c033
fix ci
cqhasy c471434
fix c
cqhasy 49823d7
roll back ci
cqhasy 50e7a3e
Merge branch 'master' into master
mrproliu 82a490b
fix(use library pprof,roll back proto version);docs(update changes.md)
cqhasy 46654e9
Merge branch 'master' of github.com:cqhasy/skywalking
cqhasy 7537d87
refactor: extract method signature lookup into a separate function
cqhasy 55ac28e
fix(analyze java first then go in profileAnalyzer )
cqhasy 284d402
Merge branch 'master' into master
mrproliu b347616
refactor(separate language type a class)
cqhasy 81681b4
Merge branch 'master' of github.com:cqhasy/skywalking
cqhasy 8f3e9fd
roll submodule proto to d4da569
cqhasy dfaaac5
fix(delete no use build,change language_type store method)
cqhasy bd122b5
test ci
cqhasy f99831b
fix ci
cqhasy 278fa18
fix ci
cqhasy eaaa361
fix ci
cqhasy 5ba1a8e
fix ci
cqhasy 0d6bcc7
fix ci
cqhasy dea8217
fix ci
cqhasy 2f89908
role back ci
cqhasy dcf2796
fix(delete no use variable,roll back kong)
cqhasy 582814a
fix(align field annotation and adjust log level in ProfileAnalyzer)
cqhasy 5717d41
add NoIndexing for language
cqhasy 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
Some comments aren't visible on the classic Files Changed page.
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
45 changes: 45 additions & 0 deletions
45
.../main/java/org/apache/skywalking/oap/server/core/profiling/trace/ProfileLanguageType.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,45 @@ | ||
| /* | ||
| * 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.core.profiling.trace; | ||
|
|
||
| /** | ||
| * Language type for profile records. Stored as int in storage for compatibility. | ||
| */ | ||
| public enum ProfileLanguageType { | ||
| JAVA(0), | ||
| GO(1); | ||
|
|
||
| private final int value; | ||
|
|
||
| ProfileLanguageType(int value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public int getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public static ProfileLanguageType fromValue(int value) { | ||
| for (ProfileLanguageType language : values()) { | ||
| if (language.value == value) { | ||
| return language; | ||
| } | ||
| } | ||
| return JAVA; // default to 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
243 changes: 243 additions & 0 deletions
243
...java/org/apache/skywalking/oap/server/core/profiling/trace/analyze/GoProfileAnalyzer.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,243 @@ | ||
| /* | ||
| * 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.core.profiling.trace.analyze; | ||
|
|
||
| import com.google.perftools.profiles.ProfileProto; | ||
| import java.util.Collections; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import java.util.ArrayDeque; | ||
| import org.apache.skywalking.oap.server.core.profiling.trace.ProfileThreadSnapshotRecord; | ||
| import org.apache.skywalking.oap.server.core.query.input.SegmentProfileAnalyzeQuery; | ||
| import org.apache.skywalking.oap.server.core.query.type.ProfileAnalyzation; | ||
| import org.apache.skywalking.oap.server.core.query.type.ProfileStackElement; | ||
| import org.apache.skywalking.oap.server.core.query.type.ProfileStackTree; | ||
| import org.apache.skywalking.oap.server.library.pprof.parser.PprofSegmentParser; | ||
| import org.apache.skywalking.oap.server.library.pprof.parser.PprofParser; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Analyzer for Go pprof samples. Builds a stack tree with total/self durations using sampling period. | ||
| * This works independently from ThreadSnapshot, for Go profiles only. | ||
| */ | ||
| public class GoProfileAnalyzer { | ||
| private static final Logger LOGGER = LoggerFactory.getLogger(GoProfileAnalyzer.class); | ||
|
|
||
| /** | ||
| * Analyze a pprof profile for a specific segment and time window. | ||
| */ | ||
| public ProfileAnalyzation analyze(final String segmentId, | ||
| final ProfileProto.Profile profile) { | ||
| final long periodMs = PprofSegmentParser.resolvePeriodMillis(profile); | ||
|
|
||
| // Build ProfileStackElement directly (reuse FrameTreeBuilder's mergeSample logic) | ||
| Map<String, Integer> key2Id = new HashMap<>(); // "parentId|name" -> id | ||
| List<ProfileStackElement> elements = new ArrayList<>(); | ||
|
|
||
| // Strict per-segment filtering | ||
| final List<String> stringTable = profile.getStringTableList(); | ||
|
|
||
| for (ProfileProto.Sample sample : profile.getSampleList()) { | ||
| final String seg = PprofSegmentParser.extractSegmentIdFromLabels(sample.getLabelList(), stringTable); | ||
| if (seg == null || !seg.equals(segmentId)) { | ||
| continue; | ||
| } | ||
| long sampleCount = sample.getValueCount() > 0 ? sample.getValue(0) : 1L; | ||
| long weightMs = sampleCount * periodMs; | ||
|
|
||
| // Build function stack then ensure root->leaf order for aggregation | ||
| List<String> stack = PprofSegmentParser.extractStackFromSample(sample, profile); | ||
| Collections.reverse(stack); | ||
|
|
||
| // Aggregate along path (similar to FrameTreeBuilder.mergeSample) | ||
| int parentId = -1; // root | ||
| for (String fn : stack) { | ||
| String key = parentId + "|" + fn; | ||
| Integer nodeId = key2Id.get(key); | ||
|
|
||
| if (nodeId == null) { | ||
| ProfileStackElement element = new ProfileStackElement(); | ||
| element.setId(elements.size()); | ||
| element.setParentId(parentId); | ||
| element.setCodeSignature(fn); | ||
| element.setDuration(0); | ||
| element.setDurationChildExcluded(0); | ||
| element.setCount(0); | ||
| elements.add(element); | ||
| nodeId = element.getId(); | ||
| key2Id.put(key, nodeId); | ||
| } | ||
|
|
||
| ProfileStackElement element = elements.get(nodeId); | ||
| element.setDuration(element.getDuration() + (int) weightMs); | ||
| element.setCount(element.getCount() + (int) sampleCount); | ||
|
|
||
| parentId = nodeId; | ||
| } | ||
| } | ||
|
|
||
| int rootCount = 0; | ||
| for (ProfileStackElement e : elements) { | ||
| if (e.getParentId() == -1) { | ||
| rootCount++; | ||
| } | ||
| } | ||
| if (rootCount > 1) { | ||
| int virtualRootId = elements.size(); | ||
| ProfileStackElement virtualRoot = new ProfileStackElement(); | ||
| virtualRoot.setId(virtualRootId); | ||
| virtualRoot.setParentId(-1); | ||
| virtualRoot.setCodeSignature("root"); | ||
| virtualRoot.setDuration(0); | ||
| virtualRoot.setDurationChildExcluded(0); | ||
| virtualRoot.setCount(0); | ||
| elements.add(virtualRoot); | ||
|
|
||
| for (ProfileStackElement e : elements) { | ||
| if (e.getId() == virtualRootId) { | ||
| continue; | ||
| } | ||
| if (e.getParentId() == -1) { | ||
| e.setParentId(virtualRootId); | ||
| virtualRoot.setDuration(virtualRoot.getDuration() + e.getDuration()); | ||
| virtualRoot.setCount(virtualRoot.getCount() + e.getCount()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Map<Integer, Integer> childDurSum = new HashMap<>(); | ||
| for (ProfileStackElement child : elements) { | ||
| int pid = child.getParentId(); | ||
| if (pid != -1) { | ||
| childDurSum.put(pid, childDurSum.getOrDefault(pid, 0) + child.getDuration()); | ||
| } | ||
| } | ||
| for (ProfileStackElement elem : elements) { | ||
| int childrenSum = childDurSum.getOrDefault(elem.getId(), 0); | ||
| elem.setDurationChildExcluded(Math.max(0, elem.getDuration() - childrenSum)); | ||
| } | ||
|
|
||
| Integer rootId = null; | ||
| for (ProfileStackElement e : elements) { | ||
| if (e.getParentId() == -1) { | ||
| rootId = e.getId(); | ||
| break; | ||
| } | ||
| } | ||
| if (rootId != null) { | ||
| Map<Integer, List<ProfileStackElement>> childrenMap = new HashMap<>(); | ||
| for (ProfileStackElement e : elements) { | ||
| childrenMap.computeIfAbsent(e.getParentId(), k -> new ArrayList<>()).add(e); | ||
| } | ||
|
|
||
| List<ProfileStackElement> ordered = new ArrayList<>(); | ||
| ArrayDeque<ProfileStackElement> queue = new ArrayDeque<>(); | ||
| // start from root | ||
| for (ProfileStackElement e : elements) { | ||
| if (e.getId() == rootId) { | ||
| queue.add(e); | ||
| break; | ||
| } | ||
| } | ||
| while (!queue.isEmpty()) { | ||
| ProfileStackElement cur = queue.removeFirst(); | ||
| ordered.add(cur); | ||
| List<ProfileStackElement> children = childrenMap.get(cur.getId()); | ||
| if (children != null) { | ||
| // sort children by duration desc to make primary path first | ||
| children.sort((a, b) -> Integer.compare(b.getDuration(), a.getDuration())); | ||
| queue.addAll(children); | ||
| } | ||
| } | ||
|
|
||
| Map<Integer, Integer> idRemap = new HashMap<>(); | ||
| for (int i = 0; i < ordered.size(); i++) { | ||
| idRemap.put(ordered.get(i).getId(), i); | ||
| } | ||
| for (ProfileStackElement e : ordered) { | ||
| int newId = idRemap.get(e.getId()); | ||
| int parentId = e.getParentId(); | ||
| e.setId(newId); | ||
| if (parentId == -1) { | ||
| e.setParentId(-1); | ||
| } else { | ||
| e.setParentId(idRemap.getOrDefault(parentId, -1)); | ||
| } | ||
| } | ||
| elements = ordered; | ||
| } | ||
|
|
||
| ProfileStackTree tree = new ProfileStackTree(); | ||
| tree.setElements(elements); | ||
|
|
||
| ProfileAnalyzation result = new ProfileAnalyzation(); | ||
| result.getTrees().add(tree); | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Analyze multiple Go profile records and return combined results | ||
| */ | ||
| public ProfileAnalyzation analyzeRecords(List<ProfileThreadSnapshotRecord> records, List<SegmentProfileAnalyzeQuery> queries) { | ||
| ProfileAnalyzation result = new ProfileAnalyzation(); | ||
|
|
||
| // Build query map for O(1) lookup | ||
| Map<String, SegmentProfileAnalyzeQuery> queryMap = queries.stream() | ||
| .collect(Collectors.toMap(SegmentProfileAnalyzeQuery::getSegmentId, q -> q)); | ||
|
|
||
| for (ProfileThreadSnapshotRecord record : records) { | ||
| try { | ||
| // Find the corresponding query for this segment | ||
| SegmentProfileAnalyzeQuery query = queryMap.get(record.getSegmentId()); | ||
|
|
||
| if (query == null) { | ||
| LOGGER.warn("No query found for Go profile segment: {}", record.getSegmentId()); | ||
| continue; | ||
| } | ||
|
|
||
| // Parse pprof data from stackBinary | ||
| ProfileProto.Profile profile = PprofParser.parseProfile(record.getStackBinary()); | ||
|
|
||
| // Analyze this record | ||
| ProfileAnalyzation recordAnalyzation = analyze( | ||
| record.getSegmentId(), | ||
| profile | ||
| ); | ||
|
|
||
| if (recordAnalyzation != null && !recordAnalyzation.getTrees().isEmpty()) { | ||
| result.getTrees().addAll(recordAnalyzation.getTrees()); | ||
|
|
||
| if (LOGGER.isInfoEnabled()) { | ||
| LOGGER.info("Go profile analysis completed: segmentId={}, window=[{}-{}], trees={}", | ||
| record.getSegmentId(), query.getTimeRange().getStart(), query.getTimeRange().getEnd(), | ||
| recordAnalyzation.getTrees().size()); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| LOGGER.error("Failed to analyze Go profile record: segmentId={}, sequence={}, dumpTime={}", | ||
| record.getSegmentId(), record.getSequence(), record.getDumpTime(), e); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
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.
Is this already done in the proof library?