/** * Sorts list with aggregated {@link InvocationSequenceData} with the help of the summed * up exclusive times. */ @Override public int compare(AggregatedDiagnosisData o1, AggregatedDiagnosisData o2) { return Double.compare(o2.getAggregatedDiagnosisTimerData().getExclusiveDuration(), o1.getAggregatedDiagnosisTimerData().getExclusiveDuration()); } });
/** * Gets the {@link AggregatedDiagnosisData} with all the TimeWastingOperations. Just the * {@link InvocationSequenceData} with highest exclusive time are considered as * TimeWastingOperations. * * @param timeWastingOperationsCandidates * {@link AggregatedDiagnosisData} which are considered as candidates to be * TimeWastingOperations. * @return Returns the list of {@link AggregatedDiagnosisData} which are TimeWastingOperations. */ private List<AggregatedDiagnosisData> getTimeWastingOperations(List<AggregatedDiagnosisData> timeWastingOperationsCandidates) { List<AggregatedDiagnosisData> timeWastingOperations = new ArrayList<>(); double sumExecTime = 0; double globalContextDuration = globalContext.getDuration(); for (AggregatedDiagnosisData aggregatedDiagnosisData : timeWastingOperationsCandidates) { double aggregatedDataExclusiveDuration = aggregatedDiagnosisData.getAggregatedDiagnosisTimerData().getExclusiveDuration(); if ((sumExecTime < (PROPORTION * globalContextDuration)) || (aggregatedDataExclusiveDuration > baseline) || (aggregatedDiagnosisData.getAggregatedDiagnosisTimerData().getExclusiveCount() >= METHODEXECUTIONCOUNT)) { // increase sumExclusiveTime by duration of Time Wasting Operation. sumExecTime += aggregatedDataExclusiveDuration; timeWastingOperations.add(aggregatedDiagnosisData); } } return timeWastingOperations; }
/** * Gets the most significant cluster in the list. * * @param causeClusters * List of clusters to get the most significant. * @return Returns the most significant cluster in the list. */ private CauseCluster getSignificantCluster(List<CauseCluster> causeClusters) { // Checks if there is already a cluster with higher duration ratio // from overallExclusiveDuration. CauseCluster significantCluster = getHighDurationCluster(causeClusters, timeWastingOperation.getAggregatedDiagnosisTimerData().getExclusiveDuration()); // Iterates as long as there is no significantCluster. while ((null == significantCluster) && !stopClustering) { calculateDistancesToNextCluster(causeClusters); causeClusters = mergeClusters(causeClusters); significantCluster = getHighDurationCluster(causeClusters, timeWastingOperation.getAggregatedDiagnosisTimerData().getExclusiveDuration()); } // This rule does not return the Problem Context directly, but the significant cluster. // The Problem Context is the deepest node in the invocation tree that subsumes all // InvocationSequenceData the significant cluster holds and can be accessed via // cluster.getCommonContext(). return significantCluster; }
RootCause rootCause = new RootCause(rootCauseInvocations.get().getMethodIdent(), rootCauseInvocations.get().getAggregatedDiagnosisTimerData()); ProblemOccurrence problem = new ProblemOccurrence(inputInvocationSequence, globalContext.get(), problemContext.get().getCommonContext(), rootCause, causeStructure.get().getCauseType(), causeStructure.get().getSourceType());
@Test public void causeTypeMustBeIterativeWhenTheChildInvocationsOfTheRootCauseAreIterativeAndHasARegularTimerData() { Timestamp defDate = new Timestamp(new Date().getTime()); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); TimerData timerData = new TimerData(currentTime, 10L, 20L, 30L); AggregatedDiagnosisTimerData aggregatedTimerData = new AggregatedDiagnosisTimerData(timerData); Random random = new Random(); long platformIdent = random.nextLong(); long sensorTypeIdent = random.nextLong(); long methodIdentEqual = new Long(108); long methodIdentDiff = random.nextLong(); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); childSequence.setTimerData(timerData); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); parentSequence.setTimerData(timerData); InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); grandParentSequence.setTimerData(timerData); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData()); rawInvocations.add(childSequence); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getParentSequence()).thenReturn(parentSequence); when(commonContext.getTimerData()).thenReturn(timerData); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerData); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE)); }
@Test public void causeTypeMustBeIterativeWhenTheChildInvocationsOfTheRootCauseAreIterativeAndHasAHttpTimerData() { Timestamp defDate = new Timestamp(new Date().getTime()); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); HttpTimerData timerDataHttp = new HttpTimerData(currentTime, 10L, 20L, 30L); AggregatedDiagnosisTimerData aggregatedTimerDataHttp = new AggregatedDiagnosisTimerData(timerDataHttp); Random random = new Random(); long platformIdent = random.nextLong(); long sensorTypeIdent = random.nextLong(); long methodIdentEqual = new Long(108); long methodIdentDiff = random.nextLong(); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); childSequence.setTimerData(timerDataHttp); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); parentSequence.setTimerData(timerDataHttp); InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); grandParentSequence.setTimerData(timerDataHttp); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData()); rawInvocations.add(childSequence); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getParentSequence()).thenReturn(parentSequence); when(commonContext.getTimerData()).thenReturn(timerDataHttp); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerDataHttp); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE)); }
when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerDataSql);
when(rootCause.getMethodIdent()).thenReturn(detectedProblemContext.getNestedSequences().get(0).getMethodIdent()); when(rootCause.size()).thenReturn(2); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerData); when(rootCause.getAggregationKey()).thenReturn(detectedProblemContext.getNestedSequences().get(0).getMethodIdent()); when(problemContext.getCommonContext()).thenReturn(commonContext);
timeWastingOperationTimerData.setDuration(2000); AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData);
timeWastingOperationTimerData.setDuration(2200); AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData);
timeWastingOperationTimerData.setDuration(Short.MAX_VALUE); AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(expectedProblemContext.getNestedSequences()); when(globalContext.getNestedSequences()).thenReturn(rootInvocation.getNestedSequences());
timeWastingOperationTimerData.setDuration(4600); AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(expectedProblemContext.getNestedSequences()); when(globalContext.getNestedSequences()).thenReturn(rootInvocation.getNestedSequences());