resourceInstTable[resourceInstId] = new ResourceInst(this, resourceInstId, name, id, resourceTypeTable[resourceTypeId], loadInstance); if (dump) { StatDescriptor[] stats = resourceInstTable[resourceInstId].getType().getStats(); for (int i = 0; i < stats.length; i++) { long v; Byte.valueOf(stats[i].getTypeCode()))); resourceInstTable[resourceInstId].initialValue(i, v);
/** * Returns a string representation of this object. */ @Override public String toString() { StringBuffer result = new StringBuffer(); result.append(name).append(", ").append(id).append(", ").append(type.getName()).append(": \"") .append(archive.formatTimeMillis(getFirstTimeMillis())).append('\"'); if (!active) { result.append(" inactive"); } result.append(" samples=" + getSampleCount()); return result.toString(); }
public void load() throws IOException { if (cleanDatabaseOnLoad) { doCreateEmptyDatabase(); } statValueCache.clear(); statValueEmpty.clear(); final StatArchiveReader reader = new StatArchiveReader(new File[] { archiveFileName }, statFilters, false); for (Object r : reader.getResourceInstList()) { final StatArchiveReader.ResourceInst ri = (StatArchiveReader.ResourceInst) r; if (statFilters != null && statFilters.length > 0 && !statFilters[0].typeMatches(ri.getType().getName())) { // Filter out measurement types not in the allowed types list continue; } String measurementName = ri.getType().getName() + ":" + ri.getName(); LOG.info("Measurement [" + measurementName + "], Samples: " + ri.getSampleCount() + ", Fields: " + ri.getStatValues().length); doPrepareMeasurementLoad(); for (int measurementIndex = 0; measurementIndex < ri.getSampleCount(); measurementIndex++) { StatArchiveReader.StatValue[] measurementFields = ri.getStatValues(); long measurementTimestamp = measurementFields[0].getRawAbsoluteTimeStamps()[measurementIndex]; doLoadMeasurement(measurementName, ri.getType().getName(), measurementIndex, measurementTimestamp, measurementFields); } doCompleteMeasurementLoad(); } }
while (it.hasNext()) { ResourceInst inst = (ResourceInst) it.next(); StatValue values[] = inst.getStatValues(); boolean firstTime = true; for (int i = 0; i < values.length; i++) { if (firstTime) { firstTime = false; System.out.println(inst.toString());
for (int i = 0; i < this.resourceInstTable.length; i++) { if (this.resourceInstTable[i] != null) { if (this.resourceInstTable[i].close()) { this.resourceInstTable[i] = null; } else {
System.out.print(" instId=" + resourceInstId); StatDescriptor[] stats = resourceInstTable[resourceInstId].getType().getStats(); int statOffset = dataIn.readUnsignedByte(); while (statOffset != ILLEGAL_STAT_OFFSET) { Byte.valueOf(stats[statOffset].getTypeCode()))); if (resourceInstTable[resourceInstId].addValueSample(statOffset, statDeltaBits)) { if (dump) { System.out.print(" [" + statOffset + "]=" + statDeltaBits); for (int i = 0; i < resourceInstTable.length; i++) { ResourceInst inst = resourceInstTable[i]; if (inst != null && inst.isActive()) { inst.addTimeStamp();
@Override public double[] getSnapshots() { double[] result; int startIdx = getStartIdx(); int endIdx = getEndIdx(startIdx); int resultSize = (endIdx - startIdx) + 1; if (filter != FILTER_NONE && resultSize > 1) { long[] timestamps = null; if (filter == FILTER_PERSEC) { timestamps = resource.getAllRawTimeStamps(); } result = new double[resultSize - 1]; int tsIdx = resource.getFirstTimeStampIdx() + startIdx; double[] values = series.getValuesEx(descriptor.getTypeCode(), startIdx, resultSize); for (int i = 0; i < result.length; i++) { double valueDelta = values[i + 1] - values[i]; if (filter == FILTER_PERSEC) { double timeDelta = (timestamps[tsIdx + i + 1] - timestamps[tsIdx + i]); // millis valueDelta /= (timeDelta / 1000); // per second } result[i] = valueDelta; } } else { result = series.getValuesEx(descriptor.getTypeCode(), startIdx, resultSize); } calcStats(result); return result; }
@Override public long[] getRawAbsoluteTimeStamps() { int startIdx = getStartIdx(); int endIdx = getEndIdx(startIdx); int resultSize = (endIdx - startIdx) + 1; if (resultSize <= 0) { return new long[0]; } else { long[] result = new long[resultSize]; long[] timestamps = resource.getAllRawTimeStamps(); int tsIdx = resource.getFirstTimeStampIdx() + startIdx; long base = resource.getTimeBase(); for (int i = 0; i < resultSize; i++) { result[i] = base + timestamps[tsIdx + i]; } return result; } }
boolean loadStat(StatDescriptor stat, ResourceInst resource) { ResourceType type = resource.getType(); if (!resource.isLoaded() || !type.isLoaded() || !stat.isLoaded()) { return false; } if (filters == null || filters.length == 0) { return true; } else { String textId = resource.getName(); long numericId = resource.getId(); for (int i = 0; i < filters.length; i++) { if (filters[i].statMatches(stat.getName()) && filters[i].typeMatches(type.getName()) && filters[i].instanceMatches(textId, numericId)) { return true; } } return false; } }
private int getEndIdx(int startIdx) { int endIdx = series.getSize() - 1; if (endTime != -1) { long endTimeStamp = endTime - resource.getTimeBase(); long[] timestamps = resource.getAllRawTimeStamps(); endIdx = startIdx - 1; for (int i = resource.getFirstTimeStampIdx() + startIdx; i < resource.getFirstTimeStampIdx() + series.getSize(); i++) { if (timestamps[i] >= endTimeStamp) { break; } endIdx++; } Assert.assertTrue(endIdx == startIdx - 1 || timestamps[endIdx] < endTimeStamp); } return endIdx; }
public void dump(PrintWriter stream) { stream.print("archive=" + archiveName); if (info != null) { info.dump(stream); } for (int i = 0; i < resourceTypeTable.length; i++) { if (resourceTypeTable[i] != null) { resourceTypeTable[i].dump(stream); } } stream.print("time="); timeSeries.dump(stream); for (int i = 0; i < resourceInstTable.length; i++) { if (resourceInstTable[i] != null) { resourceInstTable[i].dump(stream); } } }
/** * Gets the value of the stat in the current instance given the stat name. * * @param name the name of the stat to find in the current instance * @return the value that matches the name or null if the instance does not have a stat of the * given name * */ public StatValue getStatValue(String name) { StatValue result = null; StatDescriptor desc = getType().getStat(name); if (desc != null) { result = values[desc.getOffset()]; } return result; }
private int getStartIdx() { int startIdx = 0; if (startTime != -1) { long startTimeStamp = startTime - resource.getTimeBase(); long[] timestamps = resource.getAllRawTimeStamps(); for (int i = resource.getFirstTimeStampIdx(); i < resource.getFirstTimeStampIdx() + series.getSize(); i++) { if (timestamps[i] >= startTimeStamp) { break; } startIdx++; } } return startIdx; }
@Override public ResourceType getType() { return this.resource.getType(); }
@Test public void differentFirstTSidxIsNotEqual() throws Exception { ResourceInst resourceInst1 = new ResourceInst(this.archive1, 0, "name", 0, this.resourceType, false); setFirstTSidx(resourceInst1, 1); ResourceInst resourceInst2 = new ResourceInst(this.archive1, 0, "name", 0, this.resourceType, false); setFirstTSidx(resourceInst2, 2); assertThat(resourceInst1).isNotEqualTo(resourceInst2); }
@Test public void sameFirstTSidxEquals() throws Exception { ResourceInst resourceInst1 = new ResourceInst(this.archive1, 0, "name", 0, this.resourceType, false); setFirstTSidx(resourceInst1, 1); ResourceInst resourceInst2 = new ResourceInst(this.archive1, 0, "name", 0, this.resourceType, false); setFirstTSidx(resourceInst2, 1); assertThat(resourceInst1).isEqualTo(resourceInst2); }
protected void makeInactive() { this.active = false; lastTSidx = archive.getTimeStamps().getSize() - 1; close(); // this frees up unused memory now that no more samples }
void matchSpec(StatSpec spec, List matchedValues) { if (spec.typeMatches(this.type.getName())) { if (spec.instanceMatches(this.getName(), this.getId())) { for (int statIdx = 0; statIdx < values.length; statIdx++) { if (values[statIdx] != null) { if (spec.statMatches(values[statIdx].getDescriptor().getName())) { matchedValues.add(values[statIdx]); } } } } } }