ProfileAnalyzer { public ProfileAnalyzation analyze(String segmentId, List<ProfileAnalyzeTimeRange> timeRanges) throws IOException { ProfileAnalyzation analyzation = new ProfileAnalyzation(); SequenceSearch sequenceSearch = getAllSequenceRange(segmentId, timeRanges); if (sequenceSearch == null) { analyzation.setTip("Data not found"); return analyzation; } if (sequenceSearch.getTotalSequenceCount() > analyzeSnapshotMaxSize) { analyzation.setTip("Out of snapshot analyze limit, " + sequenceSearch.getTotalSequenceCount() + " snapshots found, but analysis first " + analyzeSnapshotMaxSize + " snapshots only."); } List<ProfileStack> stacks = sequenceSearch.getRanges().parallelStream().map(r -> { try { return getProfileThreadSnapshotQueryDAO().queryRecords(segmentId, r.getMinSequence(), r.getMaxSequence()); } catch (IOException e) { LOGGER.warn(e.getMessage(), e); return Collections.<ProfileThreadSnapshotRecord>emptyList(); } }).flatMap(Collection::stream).map(ProfileStack::deserialize).distinct().collect(Collectors.toList()); final List<ProfileStackTree> trees = analyze(stacks); if (trees != null) { analyzation.getTrees().addAll(trees); } return analyzation; } ProfileAnalyzer(ModuleManager moduleManager, int snapshotAnalyzeBatchSize, int analyzeSnapshotMaxSize); ProfileAnalyzation analyze(String segmentId, List<ProfileAnalyzeTimeRange> timeRanges);  }
@Test public void testAnalyze() throws IOException { ProfileStackAnalyzeHolder holder = loadYaml("thread-snapshot.yml", ProfileStackAnalyzeHolder.class); for (ProfileStackAnalyze analyze : holder.getList()) { analyze.analyzeAndAssert(MAX_ANALYZE_COUNT); } }