private ResourceInstance allocateResourceInstance(ResourceType type, Statistics s) { if (logger.isTraceEnabled(LogMarker.STATISTICS_VERBOSE)) { logger.trace(LogMarker.STATISTICS_VERBOSE, "SampleCollector#allocateResourceInstance type={}, s={}", type, s); } ResourceInstance resourceInstance = new ResourceInstance(this.resourceInstId, s, type); this.resourceInstMap.put(s, resourceInstance); this.resourceInstId++; return resourceInstance; }
this.dataOut.writeInt(resourceInstance.getId()); if (this.trace && (traceStatisticsName == null || traceStatisticsName.equals(resourceInstance.getStatistics().getTextId())) && (traceStatisticsTypeName == null || traceStatisticsTypeName .equals(resourceInstance.getResourceType().getStatisticsType().getName()))) { this.traceDataOut .println("destroyedResourceInstance#writeByte RESOURCE_INSTANCE_DELETE_TOKEN: " + RESOURCE_INSTANCE_DELETE_TOKEN); this.traceDataOut.println("destroyedResourceInstance#writeInt resourceInstance.getId(): " + resourceInstance.getId());
protected void monitorStatistics(final long millisTimeStamp, final List<ResourceInstance> resourceInstances) { if (!this.statistics.isEmpty()) { Map<StatisticId, Number> stats = new HashMap<>(); for (ResourceInstance resource : resourceInstances) { if (this.statistics.contains(resource.getStatistics())) { ResourceType resourceType = resource.getResourceType(); StatisticDescriptor[] sds = resourceType.getStatisticDescriptors(); int[] updatedStats = resource.getUpdatedStats(); for (int i = 0; i < updatedStats.length; i++) { int idx = updatedStats[i]; StatisticDescriptorImpl sdi = (StatisticDescriptorImpl) sds[idx]; SimpleStatisticId statId = new SimpleStatisticId(sdi, resource.getStatistics()); long rawbits = resource.getLatestStatValues()[idx]; stats.put(statId, sdi.getNumberForRawBits(rawbits)); } } } if (!stats.isEmpty()) { MapBasedStatisticsNotification notification = new MapBasedStatisticsNotification( millisTimeStamp, StatisticsNotification.Type.VALUE_CHANGED, stats); notifyListeners(notification); } } }
StatisticDescriptor[] stats = ri.getResourceType().getStatisticDescriptors(); if (ri.getStatistics().isClosed()) { continue; long[] statValues = ri.getPreviousStatValues(); statValues[i] = ri.getRawStatValue(stats[i]); updatedStats[i] = i; int updatedStatsIdx = 0; for (int i = 0; i < stats.length; i++) { long value = ri.getRawStatValue(stats[i]); if (value != statValues[i]) { statValues[i] = value; ri.setUpdatedStats(updatedStats); ri.setLatestStatValues(statValues); updatedResources.add(ri); ri.setPreviousStatValues(ri.getLatestStatValues());
|| traceStatisticsName.equals(ri.getStatistics().getTextId())) && (traceStatisticsTypeName == null || traceStatisticsTypeName .equals(ri.getResourceType().getStatisticsType().getName()))) { this.traceDataOut.println("writeSample#writeSample for ri=" + ri); if (ri.getStatistics().isClosed()) { return; StatisticDescriptor[] stats = ri.getResourceType().getStatisticDescriptors(); if (stats.length > 254) { throw new Error("StatisticsType " + ri.getResourceType().getStatisticsType().getName() + " has too many stats: " + stats.length); long[] previousStatValues = ri.getPreviousStatValues(); if (isDebugEnabled_STATISTICS) { logger.trace(LogMarker.STATISTICS_VERBOSE, ri.setPreviousStatValues(previousStatValues); try { for (int i = 0; i < stats.length; i++) { long value = ri.getLatestStatValues()[i]; if (!checkForChange || value != previousStatValues[i]) { long delta = checkForChange ? value - previousStatValues[i] : value; if (!wroteInstId) { wroteInstId = true; writeResourceInst(ri.getId()); || traceStatisticsName.equals(ri.getStatistics().getTextId()))
@Test public void testNotificationResourceInstances() throws Exception { final int resourceInstanceCount = 100; final List<ResourceInstance> resourceInstances = new ArrayList<ResourceInstance>(); for (int i = 0; i < resourceInstanceCount; i++) { resourceInstances.add(new ResourceInstance(i, null, null)); } StatMonitorHandler handler = new StatMonitorHandler(); TestStatisticsMonitor monitor = new TestStatisticsMonitor(); handler.addMonitor(monitor); handler.sampled(NanoTimer.getTime(), Collections.unmodifiableList(resourceInstances)); waitForNotificationCount(monitor, 1, 2 * 1000, 10, false); final List<ResourceInstance> notificationResourceInstances = monitor.getResourceInstances(); assertNotNull(notificationResourceInstances); assertEquals(resourceInstances, notificationResourceInstances); assertEquals(resourceInstanceCount, notificationResourceInstances.size()); int i = 0; for (ResourceInstance resourceInstance : notificationResourceInstances) { assertEquals(i, resourceInstance.getId()); i++; } }
List<ResourceType> allocatedResourceTypes = new ArrayList<ResourceType>(); for (ResourceInstance resourceInstance : resources) { ResourceType resourceType = resourceInstance.getResourceType(); if (!allocatedResourceTypes.contains(resourceType)) {
ResourceInstance resourceInstance = allocatedResourceInstanceInfo.getResourceInstance(); assertNotNull(resourceInstance); assertEquals(0, resourceInstance.getId()); assertEquals(1, resourceInstance.getUpdatedStats().length); assertEquals(1, resourceInstance.getLatestStatValues().length); // TODO: is this correct? Statistics statistics = resourceInstance.getStatistics(); assertNotNull(statistics); assertTrue(statistics == st1_1); assertEquals("st1_1_text", statistics.getTextId()); assertEquals("ST1_name", statistics.getType().getName()); assertTrue(resourceType == resourceInstance.getResourceType());
if (statResource.getResourceType().getStatisticDescriptors().length >= ILLEGAL_STAT_OFFSET) { throw new InternalGemFireException( String.format("Could not archive type %s because it had more than %s statistics.", new Object[] {statResource.getResourceType().getStatisticsType().getName(), Integer.valueOf(ILLEGAL_STAT_OFFSET - 1)})); if (statResource.getStatistics().isClosed()) { return; try { this.dataOut.writeByte(RESOURCE_INSTANCE_CREATE_TOKEN); this.dataOut.writeInt(statResource.getId()); this.dataOut.writeUTF(statResource.getStatistics().getTextId()); this.dataOut.writeLong(statResource.getStatistics().getNumericId()); this.dataOut.writeInt(statResource.getResourceType().getId()); if (this.trace && (traceStatisticsName == null || traceStatisticsName.equals(statResource.getStatistics().getTextId())) && (traceStatisticsTypeName == null || traceStatisticsTypeName .equals(statResource.getResourceType().getStatisticsType().getName()))) { traceResourceInstId = statResource.getId(); this.traceDataOut.println("writeHeader traceResourceInstId: " + traceResourceInstId); this.traceDataOut + RESOURCE_INSTANCE_CREATE_TOKEN); this.traceDataOut.println( "allocatedResourceInstance#writeInt statResource.getId(): " + statResource.getId()); this.traceDataOut
ResourceInstance resourceInstance = allocatedResourceInstanceInfo.getResourceInstance(); assertNotNull(resourceInstance); assertEquals(0, resourceInstance.getId()); assertEquals(0, resourceInstance.getUpdatedStats().length); assertEquals(1, resourceInstance.getLatestStatValues().length); // TODO: is this correct? Statistics statistics = resourceInstance.getStatistics(); assertNotNull(statistics); assertTrue(statistics == st1_1); assertEquals("st1_1_text", statistics.getTextId()); assertEquals("ST1_name", statistics.getType().getName()); assertTrue(resourceType == resourceInstance.getResourceType()); resourceInstance = allocatedResourceInstanceInfo.getResourceInstance(); assertNotNull(resourceInstance); assertEquals(1, resourceInstance.getId()); assertEquals(1, resourceInstance.getUpdatedStats().length); assertEquals(1, resourceInstance.getLatestStatValues().length); // TODO: is this correct? statistics = resourceInstance.getStatistics(); assertNotNull(statistics); assertTrue(statistics == st1_2); assertEquals("st1_2_text", statistics.getTextId()); assertEquals("ST1_name", statistics.getType().getName()); assertTrue(resourceType == resourceInstance.getResourceType()); resourceInstance = allocatedResourceInstanceInfo.getResourceInstance(); assertNotNull(resourceInstance); assertEquals(2, resourceInstance.getId());