private boolean initRecorders(int backupRecordersCount) { recordersList = new ArrayList<>(backupRecordersCount + 1); for (int i = 0; i < backupRecordersCount + 1; ++i) { Recorders recorders = new Recorders(new AtomicReferenceArray<Recorder>(MethodTagMaintainer.MAX_NUM)); recordersList.add(recorders); } curRecorders = recordersList.get(curIndex % recordersList.size()); return true; }
public Recorder getRecorder(int methodTagId) { return curRecorders.getRecorder(methodTagId); }
try { final Recorders tmpCurRecorders = curRecorders; tmpCurRecorders.setStartTime(lastTimeSliceStartTime); tmpCurRecorders.setStopTime(lastTimeSliceStartTime + millTimeSlice); nextRecorders.setStartTime(lastTimeSliceStartTime + millTimeSlice); nextRecorders.setStopTime(lastTimeSliceStartTime + 2 * millTimeSlice); nextRecorders.setWriting(true); nextRecorders.resetRecorder(); curRecorders = nextRecorders; tmpCurRecorders.setWriting(false); backgroundExecutor.execute(new Runnable() { @Override
@Override public void run() { if (tmpCurRecorders.isWriting()) { Logger.warn("RecorderMaintainer.backgroundExecutor the tmpCurRecorders is writing!!! Please increase `MillTimeSlice` or increase `RecorderTurntableNum`!!!P1"); return; methodMetricsProcessor.beforeProcess(tmpCurRecorders.getStartTime(), tmpCurRecorders.getStartTime(), tmpCurRecorders.getStopTime()); int actualSize = methodTagMaintainer.getMethodTagCount(); for (int i = 0; i < actualSize; ++i) { Recorder recorder = tmpCurRecorders.getRecorder(i); if (recorder == null || !recorder.hasRecord()) { continue; if (tmpCurRecorders.isWriting()) { Logger.warn("RecorderMaintainer.backgroundExecutor the tmpCurRecorders is writing!!! Please increase `MillTimeSlice` or increase `RecorderTurntableNum`!!!P2"); break; MethodMetrics metrics = MethodMetricsCalculator.calPerfStats(recorder, methodTag, tmpCurRecorders.getStartTime(), tmpCurRecorders.getStopTime()); methodMetricsProcessor.process(metrics, tmpCurRecorders.getStartTime(), tmpCurRecorders.getStartTime(), tmpCurRecorders.getStopTime()); methodMetricsProcessor.afterProcess(tmpCurRecorders.getStartTime(), tmpCurRecorders.getStartTime(), tmpCurRecorders.getStopTime()); Logger.debug("RecorderMaintainer.backgroundProcessor finished!!! cost: " + (System.currentTimeMillis() - start) + "ms");
@Override public void addRecorder(int methodTagId, ProfilingParams params) { for (int i = 0; i < recordersList.size(); ++i) { Recorders recorders = recordersList.get(i); recorders.setRecorder(methodTagId, createRecorder(methodTagId, params.getMostTimeThreshold(), params.getOutThresholdCount())); } } }