/** * Aggregate this timerData with the provided timerData. * * @param timerData * timerData of invocationSequenceData to be aggregated */ public void aggregate(TimerData timerData) { this.duration += timerData.getDuration(); this.cpuDuration += timerData.getCpuDuration(); this.exclusiveDuration += timerData.getExclusiveDuration(); this.exclusiveCount += timerData.getExclusiveCount(); }
/** * Default constructor. * * @param timerData * the timerData that is taken into account */ public DiagnosisTimerData(final TimerData timerData) { if (timerData == null) { throw new IllegalArgumentException("TimerData cannot be null!"); } this.duration = timerData.getDuration(); this.cpuDuration = timerData.getCpuDuration(); this.exclusiveDuration = timerData.getExclusiveDuration(); if (timerData instanceof SqlStatementData) { SqlStatementData sqlStatementData = (SqlStatementData) timerData; this.metaData.put(MetaDataType.SQL, sqlStatementData.getSql()); } else if (timerData instanceof HttpTimerData) { HttpTimerData httpTimerData = (HttpTimerData) timerData; this.metaData.put(MetaDataType.URI, httpTimerData.getHttpInfo().getUri()); } }
@Override public boolean matches(Object argument) { if (!DatabaseAggregatedTimerData.class.equals(argument.getClass())) { return false; } TimerData timerData = (TimerData) argument; assertThat(timerData.getCount() % count, is(equalTo(0L))); assertThat(timerData.getMin(), is(equalTo(min))); assertThat(timerData.getMax(), is(equalTo(max))); assertThat(timerData.getAverage(), is(equalTo(average))); assertThat(timerData.getDuration() / timerData.getCount(), is(equalTo(average))); assertThat(timerData.getCpuMin(), is(equalTo(min))); assertThat(timerData.getCpuMax(), is(equalTo(max))); assertThat(timerData.getCpuAverage(), is(equalTo(average))); assertThat(timerData.getCpuDuration() / timerData.getCount(), is(equalTo(average))); assertThat(timerData.getExclusiveMin(), is(equalTo(min))); assertThat(timerData.getExclusiveMax(), is(equalTo(max))); assertThat(timerData.getExclusiveAverage(), is(equalTo(average))); return true; } }));
return Double.compare(o1.getMax(), o2.getMax()); case DURATION: return Double.compare(o1.getDuration(), o2.getDuration()); case CPUAVERAGE: return Double.compare(o1.getCpuAverage(), o2.getCpuAverage());
@Test public void noMethodIdent() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); when(cachedDataService.getMethodIdentForId(METHOD_ID)).thenReturn(null); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getMethodIdent()).thenReturn(METHOD_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(RandomUtils.nextDouble()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Methods.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), not(hasKey(Series.Methods.TAG_CLASS_FQN))); assertThat(getTags(pointBuilder), not(hasKey(Series.Methods.TAG_METHOD_NAME))); assertThat(getTags(pointBuilder), not(hasKey(Series.Methods.TAG_METHOD_SIGNATURE))); }
@Test public void noPlatform() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(null); when(cachedDataService.getMethodIdentForId(METHOD_ID)).thenReturn(methodIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getMethodIdent()).thenReturn(METHOD_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(RandomUtils.nextDouble()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Methods.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), not(hasKey(Series.TAG_AGENT_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.Methods.TAG_CLASS_FQN, String.valueOf(FQN))); assertThat(getTags(pointBuilder), hasEntry(Series.Methods.TAG_METHOD_NAME, String.valueOf(METHOD))); assertThat(getTags(pointBuilder), hasEntry(Series.Methods.TAG_METHOD_SIGNATURE, String.valueOf(METHOD_SIG))); }
assertThat(timerData.getTimeStamp(), is(not(nullValue()))); assertThat(timerData.getCount(), is(1L)); assertThat(timerData.getDuration(), is(thirdTimerValue - secondTimerValue)); assertThat(timerData.getMin(), is(thirdTimerValue - secondTimerValue)); assertThat(timerData.getMax(), is(thirdTimerValue - secondTimerValue)); assertThat(timerData.getTimeStamp(), is(not(nullValue()))); assertThat(timerData.getCount(), is(1L)); assertThat(timerData.getDuration(), is(fourthTimerValue - firstTimerValue)); assertThat(timerData.getMin(), is(fourthTimerValue - firstTimerValue)); assertThat(timerData.getMax(), is(fourthTimerValue - firstTimerValue));
assertThat(timerData.getTimeStamp(), is(not(nullValue()))); assertThat(timerData.getCount(), is(1L)); assertThat(timerData.getDuration(), is(secondTimerValue - firstTimerValue)); assertThat(timerData.getMin(), is(secondTimerValue - firstTimerValue)); assertThat(timerData.getMax(), is(secondTimerValue - firstTimerValue));
assertThat(timerData.getTimeStamp(), is(not(nullValue()))); assertThat(timerData.getCount(), is(1L)); assertThat(timerData.getDuration(), is(secondTimerValue - firstTimerValue)); assertThat(timerData.getMin(), is(secondTimerValue - firstTimerValue)); assertThat(timerData.getMax(), is(secondTimerValue - firstTimerValue)); assertThat(timerData.getTimeStamp(), is(not(nullValue()))); assertThat(timerData.getCount(), is(1L)); assertThat(timerData.getDuration(), is(fourthTimerValue - thirdTimerValue)); assertThat(timerData.getMin(), is(fourthTimerValue - thirdTimerValue)); assertThat(timerData.getMax(), is(fourthTimerValue - thirdTimerValue));
/** * Calculates the duration starting from this invocation sequence data element. Includes span * duration as last resource if the span ident exists on the data. * * @param data * the <code>InvocationSequenceData</code> object. * @param spanService * Span service providing the additional span information if needed. * @return the duration starting from this invocation sequence data element. */ public static double calculateDuration(InvocationSequenceData data, ISpanService spanService) { if (InvocationSequenceDataHelper.hasTimerData(data)) { return data.getTimerData().getDuration(); } else if (InvocationSequenceDataHelper.hasSQLData(data)) { return data.getSqlStatementData().getDuration(); } else if ((null != spanService) && hasSpanIdent(data)) { Span span = spanService.get(data.getSpanIdent()); if ((span != null) && !References.FOLLOWS_FROM.equals(span.getReferenceType())) { return span.getDuration(); } } if (InvocationSequenceDataHelper.isRootElementInSequence(data)) { return data.getDuration(); } return -1.0d; }
/** * Process timer data if one exists in the invData object and passes it to the chained * processors. * * @param entityManager * {@link EntityManager} needed for DB persistence. * @param invData * Invocation data to be processed. * @param topInvocationParent * Top invocation object. * @param exclusiveDurationDelta * Duration to subtract from timer duration to get the exclusive duration. */ private void processTimerData(EntityManager entityManager, InvocationSequenceData invData, InvocationSequenceData topInvocationParent, double exclusiveDurationDelta) { TimerData timerData = invData.getTimerData(); if (null != timerData) { double exclusiveTime = invData.getTimerData().getDuration() - exclusiveDurationDelta; timerData.setExclusiveCount(1L); timerData.setExclusiveDuration(exclusiveTime); timerData.calculateExclusiveMax(exclusiveTime); timerData.calculateExclusiveMin(exclusiveTime); timerData.addInvocationParentId(topInvocationParent.getId()); passToChainedProcessors(invData.getTimerData(), entityManager); } }
/** * {@inheritDoc} */ @Override public DetailsTable generate(DefaultData defaultData, RepositoryDefinition repositoryDefinition, Composite parent, FormToolkit toolkit) { TimerData timerData = (TimerData) defaultData; DetailsTable table = new DetailsTable(parent, toolkit, "Duration Info", 1); // then the total duration DetailsCellContent[] total = new DetailsCellContent[] { new DetailsCellContent(NumberFormatter.formatDouble(timerData.getDuration())) }; table.addContentRow("Total (ms):", null, total); if (timerData.isCpuMetricDataAvailable()) { // then the total duration DetailsCellContent[] cpu = new DetailsCellContent[] { new DetailsCellContent(NumberFormatter.formatDouble(timerData.getCpuDuration())) }; table.addContentRow("CPU (ms):", null, cpu); } if (timerData.isExclusiveTimeDataAvailable()) { // then the exclusive DetailsCellContent[] exclusive = new DetailsCellContent[] { new DetailsCellContent(NumberFormatter.formatDouble(timerData.getExclusiveDuration())) }; table.addContentRow("Exclusive (ms):", null, exclusive); } return table; }
exclusiveDurationDelta += child.getTimerData().getDuration(); } else if (null != child.getSqlStatementData()) {
/** * Aggregates the values given in the supplied timer data parameter to the objects data. * * @param timerData * Data to be aggregated into current object. */ public void aggregateTimerData(TimerData timerData) { super.aggregateInvocationAwareData(timerData); this.setCount(this.getCount() + timerData.getCount()); this.setDuration(this.getDuration() + timerData.getDuration()); this.calculateMax(timerData.getMax()); this.calculateMin(timerData.getMin()); if (timerData.isCpuMetricDataAvailable()) { this.setCpuDuration(this.getCpuDuration() + timerData.getCpuDuration()); this.calculateCpuMax(timerData.getCpuMax()); this.calculateCpuMin(timerData.getCpuMin()); } if (timerData.isExclusiveTimeDataAvailable()) { this.addExclusiveDuration(timerData.getExclusiveDuration()); this.setExclusiveCount(this.getExclusiveCount() + timerData.getExclusiveCount()); this.calculateExclusiveMax(timerData.getExclusiveMax()); this.calculateExclusiveMin(timerData.getExclusiveMin()); } this.charting = this.charting | timerData.isCharting(); }
case DURATION: if (InvocationSequenceDataHelper.hasTimerData(o1) && InvocationSequenceDataHelper.hasTimerData(o2)) { return Double.compare(o1.getTimerData().getDuration(), o2.getTimerData().getDuration()); } else { return Double.compare(o1.getDuration(), o2.getDuration());
return new StyledString(NumberFormatter.formatDouble(data.getMax())); case DURATION: return new StyledString(NumberFormatter.formatDouble(data.getDuration())); case EXCLUSIVEAVERAGE: if (data.isExclusiveTimeDataAvailable()) {
/** * {@inheritDoc} * <p> * This method does not aggregate the {@link InvocationAwareData} because it is not needed in * the database. */ @Override public void aggregateTimerData(TimerData timerData) { this.setCount(this.getCount() + timerData.getCount()); this.setDuration(this.getDuration() + timerData.getDuration()); this.calculateMax(timerData.getMax()); this.calculateMin(timerData.getMin()); if (timerData.isCpuMetricDataAvailable()) { this.setCpuDuration(this.getCpuDuration() + timerData.getCpuDuration()); this.calculateCpuMin(timerData.getCpuMin()); this.calculateCpuMax(timerData.getCpuMax()); } if (timerData.isExclusiveTimeDataAvailable()) { this.addExclusiveDuration(timerData.getExclusiveDuration()); this.setExclusiveCount(this.getExclusiveCount() + timerData.getExclusiveCount()); this.calculateExclusiveMin(timerData.getExclusiveMin()); this.calculateExclusiveMax(timerData.getExclusiveMax()); } } }
case DURATION: if (InvocationSequenceDataHelper.hasTimerData(data)) { return new StyledString(NumberFormatter.formatDouble(data.getTimerData().getDuration())); } else {
return new StyledString(NumberFormatter.formatDouble(data.getDuration(), timeDecimalPlaces)); } else { return emptyStyledString;
return new StyledString(NumberFormatter.formatDouble(data.getDuration())); } else { return emptyStyledString;