提交 ff76951d 编写于 作者: L lsyf

Merge branch 'master' of https://github.com/lsyf/skywalking

...@@ -51,7 +51,7 @@ public class ProfileAnalyzer { ...@@ -51,7 +51,7 @@ public class ProfileAnalyzer {
private final int analyzeSnapshotMaxSize; private final int analyzeSnapshotMaxSize;
private final ModuleManager moduleManager; private final ModuleManager moduleManager;
private IProfileThreadSnapshotQueryDAO profileThreadSnapshotQueryDAO; protected IProfileThreadSnapshotQueryDAO profileThreadSnapshotQueryDAO;
public ProfileAnalyzer(ModuleManager moduleManager, int snapshotAnalyzeBatchSize, int analyzeSnapshotMaxSize) { public ProfileAnalyzer(ModuleManager moduleManager, int snapshotAnalyzeBatchSize, int analyzeSnapshotMaxSize) {
this.moduleManager = moduleManager; this.moduleManager = moduleManager;
...@@ -91,7 +91,7 @@ public class ProfileAnalyzer { ...@@ -91,7 +91,7 @@ public class ProfileAnalyzer {
return analyzation; return analyzation;
} }
private SequenceSearch getAllSequenceRange(String segmentId, long start, long end) throws IOException { protected SequenceSearch getAllSequenceRange(String segmentId, long start, long end) throws IOException {
// query min and max sequence // query min and max sequence
int minSequence = getProfileThreadSnapshotQueryDAO().queryMinSequence(segmentId, start, end); int minSequence = getProfileThreadSnapshotQueryDAO().queryMinSequence(segmentId, start, end);
int maxSequence = getProfileThreadSnapshotQueryDAO().queryMaxSequence(segmentId, start, end); int maxSequence = getProfileThreadSnapshotQueryDAO().queryMaxSequence(segmentId, start, end);
...@@ -107,13 +107,10 @@ public class ProfileAnalyzer { ...@@ -107,13 +107,10 @@ public class ProfileAnalyzer {
do { do {
int batchMax = Math.min(minSequence + threadSnapshotAnalyzeBatchSize, maxSequence); int batchMax = Math.min(minSequence + threadSnapshotAnalyzeBatchSize, maxSequence);
sequenceSearch.getRanges().add(new SequenceRange(minSequence, batchMax)); sequenceSearch.getRanges().add(new SequenceRange(minSequence, batchMax));
minSequence = batchMax + 1; minSequence = batchMax;
} }
while (minSequence < maxSequence); while (minSequence < maxSequence);
// increase last range max sequence, need to include last sequence data
sequenceSearch.getRanges().getLast().increaseMaxSequence();
return sequenceSearch; return sequenceSearch;
} }
...@@ -135,7 +132,7 @@ public class ProfileAnalyzer { ...@@ -135,7 +132,7 @@ public class ProfileAnalyzer {
return new ArrayList<>(stackTrees.values()); return new ArrayList<>(stackTrees.values());
} }
private IProfileThreadSnapshotQueryDAO getProfileThreadSnapshotQueryDAO() { protected IProfileThreadSnapshotQueryDAO getProfileThreadSnapshotQueryDAO() {
if (profileThreadSnapshotQueryDAO == null) { if (profileThreadSnapshotQueryDAO == null) {
profileThreadSnapshotQueryDAO = moduleManager.find(StorageModule.NAME) profileThreadSnapshotQueryDAO = moduleManager.find(StorageModule.NAME)
.provider() .provider()
......
...@@ -16,23 +16,24 @@ ...@@ -16,23 +16,24 @@
* *
*/ */
package org.apache.skywalking.oap.server.core.profile; package org.apache.skywalking.oap.server.core.profile.analyze;
import org.apache.skywalking.oap.server.core.profile.analyze.ProfileStackAnalyze;
import org.apache.skywalking.oap.server.core.profile.analyze.ProfileStackAnalyzeHolder;
import org.junit.Test; import org.junit.Test;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class ProfileAnalyzerTest { public class ProfileAnalyzerTest {
public static final int MAX_ANALYZE_COUNT = 10;
@Test @Test
public void testAnalyze() { public void testAnalyze() throws IOException {
ProfileStackAnalyzeHolder holder = loadYaml("thread-snapshot.yml", ProfileStackAnalyzeHolder.class); ProfileStackAnalyzeHolder holder = loadYaml("thread-snapshot.yml", ProfileStackAnalyzeHolder.class);
for (ProfileStackAnalyze analyze : holder.getList()) { for (ProfileStackAnalyze analyze : holder.getList()) {
analyze.analyzeAndAssert(); analyze.analyzeAndAssert(MAX_ANALYZE_COUNT);
} }
} }
......
...@@ -18,9 +18,15 @@ ...@@ -18,9 +18,15 @@
package org.apache.skywalking.oap.server.core.profile.analyze; package org.apache.skywalking.oap.server.core.profile.analyze;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import lombok.Data; import lombok.Data;
import org.apache.skywalking.oap.server.core.profile.ProfileThreadSnapshotRecord;
import org.apache.skywalking.oap.server.core.query.entity.BasicTrace;
import org.apache.skywalking.oap.server.core.query.entity.ProfileStackTree; import org.apache.skywalking.oap.server.core.query.entity.ProfileStackTree;
import org.apache.skywalking.oap.server.core.storage.profile.IProfileThreadSnapshotQueryDAO;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
...@@ -31,9 +37,10 @@ public class ProfileStackAnalyze { ...@@ -31,9 +37,10 @@ public class ProfileStackAnalyze {
private ProfileStackData data; private ProfileStackData data;
private List<ProfileStackElementMatcher> expected; private List<ProfileStackElementMatcher> expected;
public void analyzeAndAssert() { public void analyzeAndAssert(int maxAnalyzeCount) throws IOException {
List<ProfileStack> stacks = data.transform(); List<ProfileThreadSnapshotRecord> stacks = data.transform();
List<ProfileStackTree> trees = new ProfileAnalyzer(null, 100, 500).analyze(stacks);
List<ProfileStackTree> trees = buildAnalyzer(stacks, maxAnalyzeCount).analyze(null, 0, 0).getTrees();
assertNotNull(trees); assertNotNull(trees);
assertEquals(trees.size(), expected.size()); assertEquals(trees.size(), expected.size());
...@@ -42,4 +49,43 @@ public class ProfileStackAnalyze { ...@@ -42,4 +49,43 @@ public class ProfileStackAnalyze {
} }
} }
private ProfileAnalyzer buildAnalyzer(List<ProfileThreadSnapshotRecord> stacks, int maxAnalyzeCount) throws IOException {
ProfileAnalyzer analyzer = new ProfileAnalyzer(null, 2, maxAnalyzeCount);
analyzer.profileThreadSnapshotQueryDAO = new ThreadSnapshotDAO(stacks);
return analyzer;
}
static class ThreadSnapshotDAO implements IProfileThreadSnapshotQueryDAO {
private final List<ProfileThreadSnapshotRecord> stacks;
public ThreadSnapshotDAO(List<ProfileThreadSnapshotRecord> stacks) {
this.stacks = stacks;
}
@Override
public List<BasicTrace> queryProfiledSegments(String taskId) throws IOException {
return null;
}
@Override
public int queryMinSequence(String segmentId, long start, long end) throws IOException {
return 0;
}
@Override
public int queryMaxSequence(String segmentId, long start, long end) throws IOException {
return stacks.size();
}
@Override
public List<ProfileThreadSnapshotRecord> queryRecords(String segmentId, int minSequence, int maxSequence) throws IOException {
return stacks.stream()
.filter(s -> s.getSequence() >= minSequence)
.filter(s -> s.getSequence() < maxSequence)
.collect(Collectors.toList());
}
}
} }
...@@ -20,6 +20,8 @@ package org.apache.skywalking.oap.server.core.profile.analyze; ...@@ -20,6 +20,8 @@ package org.apache.skywalking.oap.server.core.profile.analyze;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import lombok.Data; import lombok.Data;
import org.apache.skywalking.apm.network.language.profile.ThreadStack;
import org.apache.skywalking.oap.server.core.profile.ProfileThreadSnapshotRecord;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -30,14 +32,15 @@ public class ProfileStackData { ...@@ -30,14 +32,15 @@ public class ProfileStackData {
private int limit; private int limit;
private List<String> snapshots; private List<String> snapshots;
public List<ProfileStack> transform() { public List<ProfileThreadSnapshotRecord> transform() {
ArrayList<ProfileStack> result = new ArrayList<>(snapshots.size()); ArrayList<ProfileThreadSnapshotRecord> result = new ArrayList<>(snapshots.size());
for (int i = 0; i < snapshots.size(); i++) { for (int i = 0; i < snapshots.size(); i++) {
ProfileStack stack = new ProfileStack(); ProfileThreadSnapshotRecord stack = new ProfileThreadSnapshotRecord();
stack.setSequence(i); stack.setSequence(i);
stack.setDumpTime(i * limit); stack.setDumpTime(i * limit);
stack.setStack(Splitter.on("-").splitToList(snapshots.get(i))); ThreadStack stackData = ThreadStack.newBuilder().addAllCodeSignatures(Splitter.on("-").splitToList(snapshots.get(i))).build();
stack.setStackBinary(stackData.toByteArray());
result.add(stack); result.add(stack);
} }
......
...@@ -200,3 +200,23 @@ list: ...@@ -200,3 +200,23 @@ list:
- code: E - code: E
count: 1 count: 1
duration: 0:0 duration: 0:0
# case 7(only analyze first 10 snapshots):
- data:
limit: 10
snapshots:
- A
- A
- A
- A
- A
- A
- A
- A
- A
- A
- A
expected:
- code: A
count: 10
duration: 90:90
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册