continue; if (!spec.typeMatches(v.getType().getName())) { continue;
rt = new ResourceType(resourceTypeId, resourceTypeName, resourceTypeDesc, statCount); if (dump) { System.out.println("ResourceType id=" + resourceTypeId + " name=" + resourceTypeName rt = new ResourceType(resourceTypeId, resourceTypeName, statCount); if (dump) { System.out.println( rt.addStatDescriptor(this, i, statName, isCounter, largerBetter, typeCode, units, desc); if (dump) { System.out.println(" " + i + "=" + statName + " isCtr=" + isCounter + " largerBetter="
for (int i = 0; i < this.resourceTypeTable.length; i++) { if (this.resourceTypeTable[i] != null) { if (this.resourceTypeTable[i].close()) { this.resourceTypeTable[i] = null; } else {
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(); } }
StatDescriptor[] stats = resourceInstTable[resourceInstId].getType().getStats(); for (int i = 0; i < stats.length; i++) { long v;
this.values = values; this.filter = this.values[0].getFilter(); String typeName = this.values[0].getType().getName(); String statName = this.values[0].getDescriptor().getName(); int bestTypeIdx = 0; "Cannot combine values with different filters."); if (!typeName.equals(this.values[i].getType().getName())) { throw new IllegalArgumentException( "Cannot combine values with different types.");
System.out.print(" instId=" + resourceInstId); StatDescriptor[] stats = resourceInstTable[resourceInstId].getType().getStats(); int statOffset = dataIn.readUnsignedByte(); while (statOffset != ILLEGAL_STAT_OFFSET) {
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ResourceInst other = (ResourceInst) obj; if (id != other.id) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; if (this.firstTSidx != other.firstTSidx) { return false; } return true; } }
protected ResourceInst(StatArchiveFile archive, int uniqueId, String name, long id, ResourceType type, boolean loaded) { this.loaded = loaded; this.archive = archive; this.name = name; this.id = id; Assert.assertTrue(type != null); this.type = type; if (loaded) { StatDescriptor[] stats = type.getStats(); this.values = new SimpleValue[stats.length]; for (int i = 0; i < stats.length; i++) { if (archive.loadStat(stats[i], this)) { this.values[i] = new SimpleValue(this, stats[i]); } else { this.values[i] = null; } } } else { this.values = null; } }
boolean loadInstance(String textId, long numericId, ResourceType type) { if (!type.isLoaded()) { return false; } if (filters == null || filters.length == 0) { return true; } else { for (int i = 0; i < filters.length; i++) { if (filters[i].typeMatches(type.getName())) { if (filters[i].instanceMatches(textId, numericId)) { StatDescriptor[] stats = type.getStats(); for (int j = 0; j < stats.length; j++) { if (stats[j].isLoaded()) { if (filters[i].statMatches(stats[j].getName())) { return true; } } } } } } return false; } }
/** * Frees up any resources no longer needed after the archive file is closed. Returns true if * this resource is no longer needed. */ protected boolean close() { if (isLoaded()) { for (int i = 0; i < stats.length; i++) { if (stats[i] != null) { if (!stats[i].isLoaded()) { stats[i] = null; } } } return false; } else { return true; } }
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; } }
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); } } }
boolean loadStatDescriptor(StatDescriptor stat, ResourceType type) { // note we don't have instance data yet if (!type.isLoaded()) { return false; } if (filters == null || filters.length == 0) { return true; } else { for (int i = 0; i < filters.length; i++) { if (filters[i].statMatches(stat.getName()) && filters[i].typeMatches(type.getName())) { return true; } } stat.unload(); return false; } }
/** * 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; }
/** * 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(); }
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]); } } } } } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; }