/** * 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; }
/** * Aggregate by adding a new InvocationSequenceData. * * @param invocationSequenceData * InvocationSequenceData to be added to the aggregation */ public void aggregate(InvocationSequenceData invocationSequenceData) { TimerData timerData = null; switch (sourceType) { case DATABASE: timerData = invocationSequenceData.getSqlStatementData(); break; case HTTP: case TIMERDATA: timerData = invocationSequenceData.getTimerData(); break; default: throw new IllegalStateException("Source type unknown."); } // aggregate the timer data if (aggregatedDiagnosisTimerData == null) { aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timerData); } else { aggregatedDiagnosisTimerData.aggregate(timerData); } // save involved invocation rawInvocationsSequenceElements.add(invocationSequenceData); }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } RootCause other = (RootCause) obj; if (this.methodIdent != other.methodIdent) { return false; } if (this.aggregatedDiagnosisTimerData == null) { if (other.aggregatedDiagnosisTimerData != null) { return false; } } else if (!this.aggregatedDiagnosisTimerData.equals(other.aggregatedDiagnosisTimerData)) { return false; } return true; }
new AggregatedDiagnosisTimerData(InvocationSequenceDataHelper.getTimerDataOrSQLData(globalContext.get()))); ProblemOccurrence problem = new ProblemOccurrence(inputInvocationSequence, globalContext.get(), rootCause); problems.add(problem);
/** * 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()); } });
/** * {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + (int) (this.methodIdent ^ (this.methodIdent >>> 32)); result = (prime * result) + ((this.aggregatedDiagnosisTimerData == null) ? 0 : this.aggregatedDiagnosisTimerData.hashCode()); return result; }
@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)); }
/** * 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; }
/** * {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + ((this.aggregatedDiagnosisTimerData == null) ? 0 : this.aggregatedDiagnosisTimerData.hashCode()); result = (prime * result) + ((this.aggregationKey == null) ? 0 : this.aggregationKey.hashCode()); result = (prime * result) + (int) (this.methodIdent ^ (this.methodIdent >>> 32)); result = (prime * result) + ((this.rawInvocationsSequenceElements == null) ? 0 : this.rawInvocationsSequenceElements.hashCode()); result = (prime * result) + ((this.sourceType == null) ? 0 : this.sourceType.hashCode()); return result; }
/** * Add fields to builder. * * @param data * ProblemOccurrence instance * @param builder * Builder that can be used to create influx points. */ protected void addFields(ProblemOccurrence data, Builder builder) { builder.addField(Series.ProblemOccurrenceInformation.FIELD_INVOCATION_ROOT_DURATION, data.getRequestRoot().getDiagnosisTimerData().getDuration()); builder.addField(Series.ProblemOccurrenceInformation.FIELD_GLOBAL_CONTEXT_METHOD_EXCLUSIVE_TIME, data.getGlobalContext().getDiagnosisTimerData().getExclusiveDuration()); builder.addField(Series.ProblemOccurrenceInformation.FIELD_ROOTCAUSE_METHOD_EXCLUSIVE_TIME, data.getRootCause().getAggregatedDiagnosisTimerData().getExclusiveDuration()); builder.addField(Series.ProblemOccurrenceInformation.FIELD_ROOTCAUSE_METHOD_EXCLUSIVE_COUNT, data.getRootCause().getAggregatedDiagnosisTimerData().getExclusiveCount()); }
@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)); }
@BeforeMethod public void init() { when(problemOccurrence.getApplicationNameIdent()).thenReturn(APP_ID); when(problemOccurrence.getBusinessTransactionNameIdent()).thenReturn(BUSINESS_TX_ID); when(problemOccurrence.getProblemContext()).thenReturn(invocationIdentifier); when(problemOccurrence.getRequestRoot()).thenReturn(invocationIdentifier); when(problemOccurrence.getGlobalContext()).thenReturn(invocationIdentifier); when(problemOccurrence.getCauseType()).thenReturn(causeType); when(problemOccurrence.getSourceType()).thenReturn(sourceType); when(problemOccurrence.getRootCause()).thenReturn(rootCause); when(invocationIdentifier.getDiagnosisTimerData()).thenReturn(diagnosisTimerData); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData); when(diagnosisTimerData.getDuration()).thenReturn(DURATION); when(diagnosisTimerData.getExclusiveDuration()).thenReturn(EXCLUSIVE_DURATION); when(aggregatedDiagnosisTimerData.getExclusiveDuration()).thenReturn(EXCLUSIVE_DURATION); when(applicationData.getName()).thenReturn(APPLICATION_NAME); when(businessTransactionData.getName()).thenReturn(BUSINESS_TX); when(methodIdent.getMethodName()).thenReturn(METHOD); when(methodIdent.getFQN()).thenReturn(FQN); }
return false; } else if (!this.aggregatedDiagnosisTimerData.equals(other.aggregatedDiagnosisTimerData)) { return false;
Timestamp currentTime = new Timestamp(System.currentTimeMillis()); SqlStatementData timerDataSql = new SqlStatementData(currentTime, 10L, 20L, 30L); AggregatedDiagnosisTimerData aggregatedTimerDataSql = new AggregatedDiagnosisTimerData(timerDataSql); Random random = new Random(); long platformIdent = random.nextLong();
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();
timeWastingOperationTimerData.setExclusiveDuration(2000); timeWastingOperationTimerData.setDuration(2000); AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData);
timeWastingOperationTimerData.setExclusiveDuration(Short.MAX_VALUE); timeWastingOperationTimerData.setDuration(Short.MAX_VALUE); AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(expectedProblemContext.getNestedSequences());
timeWastingOperationTimerData.setExclusiveDuration(2000); timeWastingOperationTimerData.setDuration(2200); AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData);
timeWastingOperationTimerData.setExclusiveDuration(4600); timeWastingOperationTimerData.setDuration(4600); AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(expectedProblemContext.getNestedSequences());