while (it.hasNext()) { ComboValue v = (ComboValue) it.next(); if (!spec.statMatches(v.getDescriptor().getName())) { continue;
protected void addStatDescriptor(StatArchiveFile archive, int offset, String name, boolean isCounter, boolean largerBetter, byte typeCode, String units, String desc) { StatDescriptor descriptor = new StatDescriptor(name, offset, isCounter, largerBetter, typeCode, units, desc); this.stats[offset] = descriptor; if (archive.loadStatDescriptor(descriptor, this)) { descriptorMap.put(name, descriptor); } }
public void dump(PrintWriter stream) { if (loaded) { stream.println(name + ": " + desc); for (int i = 0; i < stats.length; i++) { stats[i].dump(stream); } } }
/** * Computes a name for the provided measurement field. * @param measurementField field to compute the measurement name for. * @return Returns a measurement name for the provided measurementField */ public String getMeasurementFieldName(StatArchiveReader.StatValue measurementField) { return measurementField.getDescriptor().getName(); }
for (int i = 0; i < stats.length; i++) { long v; switch (stats[i].getTypeCode()) { case BOOLEAN_CODE: v = dataIn.readByte(); default: throw new IOException(String.format("unexpected typeCode value %s", Byte.valueOf(stats[i].getTypeCode())));
this.filter = this.values[0].getFilter(); String typeName = this.values[0].getType().getName(); String statName = this.values[0].getDescriptor().getName(); int bestTypeIdx = 0; for (int i = 1; i < this.values.length; i++) { "Cannot combine values with different types."); if (!statName.equals(this.values[i].getDescriptor().getName())) { throw new IllegalArgumentException( "Cannot combine different stats."); if (this.values[i].getDescriptor().isCounter()) { if (!this.values[i].getDescriptor().isLargerBetter()) { .isCounter() == this.values[bestTypeIdx].getDescriptor().isLargerBetter()) { if (this.values[i].getDescriptor().isLargerBetter()) { if (this.values[bestTypeIdx].getDescriptor().isCounter() == this.values[bestTypeIdx] .getDescriptor().isLargerBetter()) {
while (statOffset != ILLEGAL_STAT_OFFSET) { long statDeltaBits; switch (stats[statOffset].getTypeCode()) { case BOOLEAN_CODE: statDeltaBits = dataIn.readByte(); default: throw new IOException(String.format("unexpected typeCode value %s", Byte.valueOf(stats[statOffset].getTypeCode())));
private static void printStatValue(StatArchiveReader.StatValue v, long startTime, long endTime, boolean nofilter, boolean persec, boolean persample, boolean prunezeros, boolean details) { v = v.createTrimmed(startTime, endTime); if (nofilter) { v.setFilter(StatArchiveReader.StatValue.FILTER_NONE); } else if (persec) { v.setFilter(StatArchiveReader.StatValue.FILTER_PERSEC); } else if (persample) { v.setFilter(StatArchiveReader.StatValue.FILTER_PERSAMPLE); } if (prunezeros) { if (v.getSnapshotsMinimum() == 0.0 && v.getSnapshotsMaximum() == 0.0) { return; } } System.out.println(" " + v.toString()); if (details) { System.out.print(" values="); double[] snapshots = v.getSnapshots(); for (int i = 0; i < snapshots.length; i++) { System.out.print(' '); System.out.print(snapshots[i]); } System.out.println(); String desc = v.getDescriptor().getDescription(); if (desc != null && desc.length() > 0) { System.out.println(" " + desc); } } }
@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; }
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; } }
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; }
protected SimpleValue(ResourceInst resource, StatDescriptor sd) { this.resource = resource; if (sd.isCounter()) { this.filter = FILTER_PERSEC; } else { this.filter = FILTER_NONE; } this.descriptor = sd; this.series = new BitSeries(); this.statsValid = false; }
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]); } } } } } }
protected void dump(PrintWriter stream) { calcStats(); stream.print(" " + descriptor.getName() + "="); stream.print("[size=" + getSnapshotsSize() + " min=" + nf.format(min) + " max=" + nf.format(max) + " avg=" + nf.format(avg) + " stddev=" + nf.format(stddev) + "]"); if (Boolean.getBoolean("StatArchiveReader.dumpall")) { series.dump(stream); } else { stream.println(); } }
@Override public double[] getRawSnapshots() { int startIdx = getStartIdx(); int endIdx = getEndIdx(startIdx); int resultSize = (endIdx - startIdx) + 1; return series.getValuesEx(descriptor.getTypeCode(), startIdx, resultSize); }