Add profile multiple time ranges unit test (#4420)
* adding unit for multiple time ranges analyze * remove un-use import
This commit is contained in:
parent
fa0b3df369
commit
b28c7d728e
|
|
@ -94,20 +94,23 @@ public class ProfileAnalyzer {
|
|||
}
|
||||
|
||||
protected SequenceSearch getAllSequenceRange(String segmentId, List<ProfileAnalyzeTimeRange> timeRanges) throws IOException {
|
||||
return timeRanges.parallelStream().map(r -> {
|
||||
final List<SequenceSearch> searches = timeRanges.parallelStream().map(r -> {
|
||||
try {
|
||||
return getAllSequenceRange(segmentId, r.getStart(), r.getEnd());
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn(e.getMessage(), e);
|
||||
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 {
|
||||
// query min and max sequence
|
||||
// query min and max sequence(include last seqeucne)
|
||||
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
|
||||
if (maxSequence <= 0) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
package org.apache.skywalking.oap.server.core.profile.analyze;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -41,12 +40,10 @@ public class ProfileStackAnalyze {
|
|||
private List<ProfileStackElementMatcher> expected;
|
||||
|
||||
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();
|
||||
range.setStart(0);
|
||||
range.setEnd(0);
|
||||
List<ProfileStackTree> trees = buildAnalyzer(stacks, maxAnalyzeCount).analyze(null, Collections.singletonList(range)).getTrees();
|
||||
List<ProfileStackTree> trees = buildAnalyzer(stacks, maxAnalyzeCount).analyze(null, ranges).getTrees();
|
||||
|
||||
assertNotNull(trees);
|
||||
assertEquals(trees.size(), expected.size());
|
||||
|
|
@ -76,11 +73,21 @@ public class ProfileStackAnalyze {
|
|||
|
||||
@Override
|
||||
public int queryMinSequence(String segmentId, long start, long end) throws IOException {
|
||||
for (ProfileThreadSnapshotRecord stack : stacks) {
|
||||
if (stack.getDumpTime() >= start) {
|
||||
return stack.getSequence();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import com.google.common.base.Splitter;
|
|||
import lombok.Data;
|
||||
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.query.entity.ProfileAnalyzeTimeRange;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -30,9 +31,10 @@ import java.util.List;
|
|||
public class ProfileStackData {
|
||||
|
||||
private int limit;
|
||||
private String timeRanges;
|
||||
private List<String> snapshots;
|
||||
|
||||
public List<ProfileThreadSnapshotRecord> transform() {
|
||||
public List<ProfileThreadSnapshotRecord> transformSnapshots() {
|
||||
ArrayList<ProfileThreadSnapshotRecord> result = new ArrayList<>(snapshots.size());
|
||||
|
||||
for (int i = 0; i < snapshots.size(); i++) {
|
||||
|
|
@ -47,4 +49,19 @@ public class ProfileStackData {
|
|||
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:
|
|||
# case 1
|
||||
- data:
|
||||
limit: 10
|
||||
timeRanges: 0-2
|
||||
snapshots:
|
||||
- A-B-C
|
||||
- A-B
|
||||
|
|
@ -48,6 +49,7 @@ list:
|
|||
# case 2
|
||||
- data:
|
||||
limit: 10
|
||||
timeRanges: 0-1
|
||||
snapshots:
|
||||
- A-B-C
|
||||
- B-C-D
|
||||
|
|
@ -78,6 +80,7 @@ list:
|
|||
# case 3
|
||||
- data:
|
||||
limit: 10
|
||||
timeRanges: 0-4
|
||||
snapshots:
|
||||
- A-B-C-D
|
||||
- A-B
|
||||
|
|
@ -104,6 +107,7 @@ list:
|
|||
# case 4:
|
||||
- data:
|
||||
limit: 10
|
||||
timeRanges: 0-3
|
||||
snapshots:
|
||||
- A-B-C
|
||||
- A-B-C-A
|
||||
|
|
@ -139,6 +143,7 @@ list:
|
|||
# case 5:
|
||||
- data:
|
||||
limit: 10
|
||||
timeRanges: 0-3
|
||||
snapshots:
|
||||
- A-B-C
|
||||
- A-B-B-C
|
||||
|
|
@ -177,6 +182,7 @@ list:
|
|||
# case 6:
|
||||
- data:
|
||||
limit: 10
|
||||
timeRanges: 0-2
|
||||
snapshots:
|
||||
- A-B-C
|
||||
- A-B
|
||||
|
|
@ -204,6 +210,7 @@ list:
|
|||
# case 7(only analyze first 10 snapshots):
|
||||
- data:
|
||||
limit: 10
|
||||
timeRanges: 0-10
|
||||
snapshots:
|
||||
- A
|
||||
- A
|
||||
|
|
@ -220,3 +227,20 @@ list:
|
|||
- code: A
|
||||
count: 10
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue