未验证 提交 b28c7d72 编写于 作者: 静夜思朝颜's avatar 静夜思朝颜 提交者: GitHub

Add profile multiple time ranges unit test (#4420)

* adding unit for multiple time ranges analyze

* remove un-use import
上级 fa0b3df3
...@@ -94,20 +94,23 @@ public class ProfileAnalyzer { ...@@ -94,20 +94,23 @@ public class ProfileAnalyzer {
} }
protected SequenceSearch getAllSequenceRange(String segmentId, List<ProfileAnalyzeTimeRange> timeRanges) throws IOException { protected SequenceSearch getAllSequenceRange(String segmentId, List<ProfileAnalyzeTimeRange> timeRanges) throws IOException {
return timeRanges.parallelStream().map(r -> { final List<SequenceSearch> searches = timeRanges.parallelStream().map(r -> {
try { try {
return getAllSequenceRange(segmentId, r.getStart(), r.getEnd()); return getAllSequenceRange(segmentId, r.getStart(), r.getEnd());
} catch (IOException e) { } catch (IOException e) {
LOGGER.warn(e.getMessage(), e); LOGGER.warn(e.getMessage(), e);
return null; return null;
} }
}).filter(Objects::nonNull).reduce(new SequenceSearch(0), SequenceSearch::combine); }).filter(Objects::nonNull).collect(Collectors.toList());
// using none parallels to combine nodes
return searches.stream().reduce(new SequenceSearch(0), SequenceSearch::combine);
} }
protected 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(include last seqeucne)
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) + 1;
// data not found // data not found
if (maxSequence <= 0) { if (maxSequence <= 0) {
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.profile.analyze; package org.apache.skywalking.oap.server.core.profile.analyze;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -41,12 +40,10 @@ public class ProfileStackAnalyze { ...@@ -41,12 +40,10 @@ public class ProfileStackAnalyze {
private List<ProfileStackElementMatcher> expected; private List<ProfileStackElementMatcher> expected;
public void analyzeAndAssert(int maxAnalyzeCount) throws IOException { public void analyzeAndAssert(int maxAnalyzeCount) throws IOException {
List<ProfileThreadSnapshotRecord> stacks = data.transform(); List<ProfileThreadSnapshotRecord> stacks = data.transformSnapshots();
final List<ProfileAnalyzeTimeRange> ranges = data.transformTimeRanges();
final ProfileAnalyzeTimeRange range = new ProfileAnalyzeTimeRange(); List<ProfileStackTree> trees = buildAnalyzer(stacks, maxAnalyzeCount).analyze(null, ranges).getTrees();
range.setStart(0);
range.setEnd(0);
List<ProfileStackTree> trees = buildAnalyzer(stacks, maxAnalyzeCount).analyze(null, Collections.singletonList(range)).getTrees();
assertNotNull(trees); assertNotNull(trees);
assertEquals(trees.size(), expected.size()); assertEquals(trees.size(), expected.size());
...@@ -76,11 +73,21 @@ public class ProfileStackAnalyze { ...@@ -76,11 +73,21 @@ public class ProfileStackAnalyze {
@Override @Override
public int queryMinSequence(String segmentId, long start, long end) throws IOException { public int queryMinSequence(String segmentId, long start, long end) throws IOException {
for (ProfileThreadSnapshotRecord stack : stacks) {
if (stack.getDumpTime() >= start) {
return stack.getSequence();
}
}
return 0; return 0;
} }
@Override @Override
public int queryMaxSequence(String segmentId, long start, long end) throws IOException { public int queryMaxSequence(String segmentId, long start, long end) throws IOException {
for (int i = stacks.size() - 1; i >= 0; i--) {
if (stacks.get(i).getDumpTime() <= end) {
return stacks.get(i).getSequence();
}
}
return stacks.size(); return stacks.size();
} }
......
...@@ -22,6 +22,7 @@ import com.google.common.base.Splitter; ...@@ -22,6 +22,7 @@ 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.apm.network.language.profile.ThreadStack;
import org.apache.skywalking.oap.server.core.profile.ProfileThreadSnapshotRecord; import org.apache.skywalking.oap.server.core.profile.ProfileThreadSnapshotRecord;
import org.apache.skywalking.oap.server.core.query.entity.ProfileAnalyzeTimeRange;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -30,9 +31,10 @@ import java.util.List; ...@@ -30,9 +31,10 @@ import java.util.List;
public class ProfileStackData { public class ProfileStackData {
private int limit; private int limit;
private String timeRanges;
private List<String> snapshots; private List<String> snapshots;
public List<ProfileThreadSnapshotRecord> transform() { public List<ProfileThreadSnapshotRecord> transformSnapshots() {
ArrayList<ProfileThreadSnapshotRecord> 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++) {
...@@ -47,4 +49,19 @@ public class ProfileStackData { ...@@ -47,4 +49,19 @@ public class ProfileStackData {
return result; return result;
} }
public List<ProfileAnalyzeTimeRange> transformTimeRanges() {
final String[] timeRangeString = this.timeRanges.split(",");
final ArrayList<ProfileAnalyzeTimeRange> ranges = new ArrayList<>();
for (String timeRange : timeRangeString) {
final ProfileAnalyzeTimeRange range = new ProfileAnalyzeTimeRange();
final String[] startEndTimes = timeRange.split("-");
range.setStart(Integer.parseInt(startEndTimes[0]) * limit);
range.setEnd(Integer.parseInt(startEndTimes[1]) * limit);
ranges.add(range);
}
return ranges;
}
} }
...@@ -24,6 +24,7 @@ list: ...@@ -24,6 +24,7 @@ list:
# case 1 # case 1
- data: - data:
limit: 10 limit: 10
timeRanges: 0-2
snapshots: snapshots:
- A-B-C - A-B-C
- A-B - A-B
...@@ -48,6 +49,7 @@ list: ...@@ -48,6 +49,7 @@ list:
# case 2 # case 2
- data: - data:
limit: 10 limit: 10
timeRanges: 0-1
snapshots: snapshots:
- A-B-C - A-B-C
- B-C-D - B-C-D
...@@ -78,6 +80,7 @@ list: ...@@ -78,6 +80,7 @@ list:
# case 3 # case 3
- data: - data:
limit: 10 limit: 10
timeRanges: 0-4
snapshots: snapshots:
- A-B-C-D - A-B-C-D
- A-B - A-B
...@@ -104,6 +107,7 @@ list: ...@@ -104,6 +107,7 @@ list:
# case 4: # case 4:
- data: - data:
limit: 10 limit: 10
timeRanges: 0-3
snapshots: snapshots:
- A-B-C - A-B-C
- A-B-C-A - A-B-C-A
...@@ -139,6 +143,7 @@ list: ...@@ -139,6 +143,7 @@ list:
# case 5: # case 5:
- data: - data:
limit: 10 limit: 10
timeRanges: 0-3
snapshots: snapshots:
- A-B-C - A-B-C
- A-B-B-C - A-B-B-C
...@@ -177,6 +182,7 @@ list: ...@@ -177,6 +182,7 @@ list:
# case 6: # case 6:
- data: - data:
limit: 10 limit: 10
timeRanges: 0-2
snapshots: snapshots:
- A-B-C - A-B-C
- A-B - A-B
...@@ -204,6 +210,7 @@ list: ...@@ -204,6 +210,7 @@ list:
# case 7(only analyze first 10 snapshots): # case 7(only analyze first 10 snapshots):
- data: - data:
limit: 10 limit: 10
timeRanges: 0-10
snapshots: snapshots:
- A - A
- A - A
...@@ -220,3 +227,20 @@ list: ...@@ -220,3 +227,20 @@ list:
- code: A - code: A
count: 10 count: 10
duration: 90:90 duration: 90:90
# case 8(multiple time ranges)
- data:
limit: 10
timeRanges: 0-2,4-5
snapshots:
- A
- A
- A
- A-C
- A
- A
- A-D
expected:
- code: A
count: 5
duration: 30:30
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册