/** * Test equal restriction. */ @Test public void equalsTrue() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.equal("id", 1L)); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(true)); }
/** * 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(); }
int cacheHash = getCacheHash(timerData.getPlatformIdent(), timerData.getMethodIdent(), aggregationTimestamp); aggTimerData = new DatabaseAggregatedTimerData(new Timestamp(aggregationTimestamp), timerData.getPlatformIdent(), timerData.getSensorTypeIdent(), timerData.getMethodIdent()); map.put(cacheHash, aggTimerData); queue.add(aggTimerData); TimerData oldest = queue.poll(); if (null != oldest) { map.remove(getCacheHash(oldest.getPlatformIdent(), oldest.getMethodIdent(), oldest.getTimeStamp().getTime())); persistList.add(oldest); count = elementCount.decrementAndGet(); aggTimerData.aggregateTimerData(timerData); } finally { persistAllLock.unlock();
/** * 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(); }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) { TimerData oldest = queue.poll(); while (oldest != null) { map.remove(getCacheHash(oldest.getPlatformIdent(), oldest.getMethodIdent(), oldest.getTimeStamp().getTime())); TimerDataAggregator.super.create(oldest); elementCount.decrementAndGet(); oldest = queue.poll(); } } });
return new StyledString(TextFormatter.getMethodWithParameters(methodIdent)); case INVOCATION_AFFILLIATION: int percentage = (int) (data.getInvocationAffiliationPercentage() * 100); int invocations = 0; if (null != data.getInvocationParentsIdSet()) { invocations = data.getInvocationParentsIdSet().size(); return new StyledString(String.valueOf(data.getCount())); case AVERAGE: if (data.isTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getAverage(), timeDecimalPlaces)); } else { return emptyStyledString; if (data.isTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getMin(), timeDecimalPlaces)); } else { return emptyStyledString; if (data.isTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getMax(), timeDecimalPlaces)); } else { return emptyStyledString; if (data.isTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getDuration(), timeDecimalPlaces)); } else { return emptyStyledString;
return Longs.compare(o1.getCount(), o2.getCount()); case AVERAGE: return Double.compare(o1.getAverage(), o2.getAverage()); case MIN: return Double.compare(o1.getMin(), o2.getMin()); case MAX: 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()); case CPUMIN: return Double.compare(o1.getCpuMin(), o2.getCpuMin()); case CPUMAX: return Double.compare(o1.getCpuMax(), o2.getCpuMax()); case CPUDURATION: return Double.compare(o1.getCpuDuration(), o2.getCpuDuration()); case EXCLUSIVEAVERAGE: return Double.compare(o1.getExclusiveAverage(), o2.getExclusiveAverage()); case EXCLUSIVEMIN: return Double.compare(o1.getExclusiveMin(), o2.getExclusiveMin()); case EXCLUSIVEMAX: return Double.compare(o1.getExclusiveMax(), o2.getExclusiveMax()); case EXCLUSIVEDURATION: return Double.compare(o1.getExclusiveDuration(), o2.getExclusiveDuration()); case CHARTING: return Boolean.valueOf(o1.isCharting()).compareTo(Boolean.valueOf(o2.isCharting())); default:
assertThat(timerData.getPlatformIdent(), is(platformId)); assertThat(timerData.getMethodIdent(), is(methodIdTwo)); assertThat(timerData.getSensorTypeIdent(), is(sensorTypeId)); 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.getCpuDuration(), is((thirdCpuTimerValue - secondCpuTimerValue) / 1000000.0d)); assertThat(timerData.getCpuMin(), is((thirdCpuTimerValue - secondCpuTimerValue) / 1000000.0d)); assertThat(timerData.getCpuMax(), is((thirdCpuTimerValue - secondCpuTimerValue) / 1000000.0d)); assertThat(timerData.isCharting(), is(false)); assertThat(timerData.getPlatformIdent(), is(platformId)); assertThat(timerData.getMethodIdent(), is(methodIdOne)); assertThat(timerData.getSensorTypeIdent(), is(sensorTypeId)); 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.getCpuDuration(), is((fourthCpuTimerValue - firstCpuTimerValue) / 1000000.0d)); assertThat(timerData.getCpuMin(), is((fourthCpuTimerValue - firstCpuTimerValue) / 1000000.0d)); assertThat(timerData.getCpuMax(), is((fourthCpuTimerValue - firstCpuTimerValue) / 1000000.0d)); assertThat(timerData.isCharting(), is(false));
public void noSetterInteractions() { TimerData timerData = mock(TimerData.class); when(timerData.getTimeStamp()).thenReturn(new Timestamp(new Date().getTime())); when(timerData.getPlatformIdent()).thenReturn(10L); when(timerData.getMethodIdent()).thenReturn(20L); verify(timerData, times(0)).setCount(anyLong()); verify(timerData, times(0)).setCpuDuration(anyDouble()); verify(timerData, times(0)).calculateCpuMax(anyDouble()); verify(timerData, times(0)).calculateCpuMin(anyDouble()); verify(timerData, times(0)).setDuration(anyDouble()); verify(timerData, times(0)).setExclusiveCount(anyLong()); verify(timerData, times(0)).setExclusiveDuration(anyDouble()); verify(timerData, times(0)).calculateExclusiveMax(anyDouble()); verify(timerData, times(0)).calculateExclusiveMin(anyDouble()); verify(timerData, times(0)).setId(anyLong()); verify(timerData, times(0)).calculateMax(anyDouble()); verify(timerData, times(0)).setMethodIdent(anyLong()); verify(timerData, times(0)).calculateMin(anyDouble()); verify(timerData, times(0)).setParameterContentData((Set<ParameterContentData>) anyObject()); verify(timerData, times(0)).setPlatformIdent(anyLong()); verify(timerData, times(0)).setSensorTypeIdent(anyLong()); verify(timerData, times(0)).setTimeStamp((Timestamp) anyObject()); verify(timerData, times(0)).setVariance(anyDouble());
/** * {@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()); } } }
DetailsCellContent[] total = new DetailsCellContent[] { new DetailsCellContent(NumberFormatter.formatLong(timerData.getCount())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getAverage())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getMin())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getMax())) }; table.addContentRow("Total:", null, total); if (timerData.isCpuMetricDataAvailable()) { DetailsCellContent[] cpu = new DetailsCellContent[] { new DetailsCellContent(NumberFormatter.formatLong(timerData.getCount())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getCpuAverage())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getCpuMin())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getCpuMax())) }; table.addContentRow("CPU:", null, cpu); if (timerData.isExclusiveTimeDataAvailable()) { DetailsCellContent[] exclusive = new DetailsCellContent[] { new DetailsCellContent(NumberFormatter.formatLong(timerData.getCount())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getExclusiveAverage())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getExclusiveMin())), new DetailsCellContent(NumberFormatter.formatDouble(timerData.getExclusiveMax())) }; table.addContentRow("Exclusive:", null, exclusive);
assertThat(timerData.getPlatformIdent(), is(platformId)); assertThat(timerData.getMethodIdent(), is(methodId)); assertThat(timerData.getSensorTypeIdent(), is(sensorTypeId)); 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.isCharting(), is(true)); assertThat(timerData.getPlatformIdent(), is(platformId)); assertThat(timerData.getMethodIdent(), is(methodId)); assertThat(timerData.getSensorTypeIdent(), is(sensorTypeId)); 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)); assertThat(timerData.isCharting(), is(true));
when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getMethodIdent()).thenReturn(METHOD_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getMin()).thenReturn(RandomUtils.nextDouble()); when(data.getMax()).thenReturn(RandomUtils.nextDouble()); when(data.getAverage()).thenReturn(RandomUtils.nextDouble()); when(data.getCpuMin()).thenReturn(RandomUtils.nextDouble()); when(data.getCpuMax()).thenReturn(RandomUtils.nextDouble()); when(data.getCpuAverage()).thenReturn(RandomUtils.nextDouble()); 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(getFields(pointBuilder), hasEntry(Series.Methods.FIELD_MIN_DURATION, (Object) data.getMin())); assertThat(getFields(pointBuilder), hasEntry(Series.Methods.FIELD_DURATION, (Object) data.getAverage())); assertThat(getFields(pointBuilder), hasEntry(Series.Methods.FIELD_MAX_DURATION, (Object) data.getMax())); assertThat(getFields(pointBuilder), hasEntry(Series.Methods.FIELD_MIN_CPU_TIME, (Object) data.getCpuMin())); assertThat(getFields(pointBuilder), hasEntry(Series.Methods.FIELD_CPU_TIME, (Object) data.getCpuAverage())); assertThat(getFields(pointBuilder), hasEntry(Series.Methods.FIELD_MAX_CPU_TIME, (Object) data.getCpuMax()));
/** * @return Returns {@link AbstractWriteDataProcessor} for caching the {@link TimerData} view. */ @Bean @Lazy @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public AbstractWriteDataProcessor getTimerDataCachingDataProcessor() { IIndexQuery query = timerDataQueryFactory.getAggregatedTimerDataQuery(new TimerData(), null, null); IAggregator<TimerData> aggregator = Aggregators.TIMER_DATA_AGGREGATOR; return new QueryCachingDataProcessor<>(query, aggregator); }
switch (enumId) { case COUNT: return new StyledString(Long.toString(data.getCount())); case AVERAGE: return new StyledString(NumberFormatter.formatDouble(data.getAverage())); case MIN: return new StyledString(NumberFormatter.formatDouble(data.getMin())); case MAX: return new StyledString(NumberFormatter.formatDouble(data.getMax())); case DURATION: return new StyledString(NumberFormatter.formatDouble(data.getDuration())); case EXCLUSIVEAVERAGE: if (data.isExclusiveTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getExclusiveAverage())); } else { return new StyledString(""); if (data.isExclusiveTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getExclusiveMax())); } else { return new StyledString(""); if (data.isExclusiveTimeDataAvailable()) { return new StyledString(NumberFormatter.formatDouble(data.getExclusiveMin())); } else { return new StyledString("");
/** * {@inheritDoc} */ @Override protected void addFields(TimerData data, Builder builder) { // fields builder.addField(Series.Methods.FIELD_MIN_DURATION, data.getMin()); builder.addField(Series.Methods.FIELD_DURATION, data.getAverage()); builder.addField(Series.Methods.FIELD_MAX_DURATION, data.getMax()); builder.addField(Series.Methods.FIELD_MIN_CPU_TIME, data.getCpuMin()); builder.addField(Series.Methods.FIELD_CPU_TIME, data.getCpuAverage()); builder.addField(Series.Methods.FIELD_MAX_CPU_TIME, data.getCpuMax()); builder.addField(Series.Methods.FIELD_COUNT, data.getCount()); }
/** * Tests that persist list saving includes correct elements being saved. */ @Test public void saveAllInPersistList() { aggregator.maxElements = 1; TimerData timerData1 = new TimerData(new Timestamp(System.currentTimeMillis()), 10L, 20L, 30L); TimerData timerData2 = new TimerData(new Timestamp(System.currentTimeMillis()), 100L, 200L, 300L); aggregator.processTimerData(timerData1); aggregator.processTimerData(timerData2); aggregator.saveAllInPersistList(); ArgumentCaptor<DatabaseAggregatedTimerData> argument = ArgumentCaptor.forClass(DatabaseAggregatedTimerData.class); verify(entityManager, times(1)).persist(argument.capture()); assertThat(argument.getValue(), is(instanceOf(DatabaseAggregatedTimerData.class))); assertThat(argument.getValue().getPlatformIdent(), is(timerData1.getPlatformIdent())); assertThat(argument.getValue().getSensorTypeIdent(), is(timerData1.getSensorTypeIdent())); assertThat(argument.getValue().getMethodIdent(), is(timerData1.getMethodIdent())); }
@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))); }
/** * {@inheritDoc} */ @Override public IAggregatedData<TimerData> getClone(TimerData timerData) { AggregatedTimerData clone = new AggregatedTimerData(); clone.setPlatformIdent(timerData.getPlatformIdent()); clone.setSensorTypeIdent(timerData.getSensorTypeIdent()); clone.setMethodIdent(timerData.getMethodIdent()); clone.setCharting(timerData.isCharting()); return clone; }
/** * Removes all data from the upper plot and sets the {@link TimerData} objects on the plot. * * @param map * The data to set on the plot. */ protected void setDurationPlotData(Map<Object, List<E>> map) { for (YIntervalSeriesImproved series : durationSeries) { series.clear(); for (Entry<Object, List<E>> entry : map.entrySet()) { if (series.getKey().equals(entry.getKey())) { for (E data : entry.getValue()) { series.add(data.getTimeStamp().getTime(), data.getAverage(), data.getMin(), data.getMax(), false); } break; } } series.fireSeriesChanged(); } }