private static void addResourceInstsToSet(final File archiveFile, final Set<ResourceInst> resourceInsts) throws IOException { StatArchiveReader reader = new StatArchiveReader(new File[] {archiveFile}, new StatSpec[] {}, true); for (Iterator<ResourceInst> it = reader.getResourceInstList().iterator(); it.hasNext();) { resourceInsts.add(it.next()); } }
@Override int fill(double[] values, int valueOffset, int typeCode, int skipCount) { int fillcount = values.length - valueOffset; // space left in values int maxCount = count - skipCount; // maximum values this interval can produce if (fillcount > maxCount) { fillcount = maxCount; } for (int i = 0; i < fillcount; i++) { values[valueOffset + i] = bitsToDouble(typeCode, bitArray[skipCount + i]); } return fillcount; }
@Override public int size() { int result = 0; StatArchiveReader.StatArchiveFile[] archives = getArchives(); for (int i = 0; i < archives.length; i++) { result += archives[i].resourceInstSize; } return result; } }
boolean interrupted = false; try { reader = new StatArchiveReader((File[]) archiveNames.toArray(new File[archiveNames.size()]), specs, !monitor); StatArchiveReader.StatArchiveFile[] archives = reader.getArchives(); for (int i = 0; i < archives.length; i++) { System.out.println(archives[i].getArchiveInfo().toString()); Iterator it = reader.getResourceInstList().iterator(); while (it.hasNext()) { ResourceInst inst = (ResourceInst) it.next(); new HashMap<CombinedResources, List<StatValue>>(); for (int i = 0; i < specs.length; i++) { StatValue[] values = reader.matchSpec(specs[i]); if (values.length == 0) { if (!quiet) { while (!reader.update()) { try { Thread.sleep(1000); if (reader != null) { try { reader.close(); } catch (IOException ignore) {
/** * Simple utility to read and dump statistic archive. */ public static void main(String args[]) throws IOException { String archiveName = null; if (args.length > 1) { System.err.println("Usage: [archiveName]"); ExitCode.FATAL.doSystemExit(); } else if (args.length == 1) { archiveName = args[0]; } else { archiveName = "statArchive.gfs"; } StatArchiveReader reader = new StatArchiveReader(archiveName); System.out.println("DEBUG: memory used = " + reader.getMemoryUsed()); reader.close(); }
private static void addResourceInstsToSet(final File archiveFile, final String specString, final Set<ResourceInst> resourceInsts) throws IOException { StatSpec statSpec = new StatSpec(specString); StatArchiveReader reader = new StatArchiveReader(new File[] {archiveFile}, new StatSpec[] {statSpec}, true); StatValue[] statValues = reader.matchSpec(statSpec); for (StatValue statValue : statValues) { for (ResourceInst resourceInst : statValue.getResources()) { resourceInsts.add(resourceInst); } } }
/** * Returns an array of stat values that match the specified spec. If nothing matches then an empty * array is returned. */ public StatValue[] matchSpec(StatSpec spec) { if (spec.getCombineType() == StatSpec.GLOBAL) { StatValue[] allValues = matchSpec(new RawStatSpec(spec)); if (allValues.length == 0) { return allValues; } else { ComboValue cv = new ComboValue(allValues); // need to save this in reader's combo value list return new StatValue[] {cv}; } } else { List l = new ArrayList(); StatArchiveReader.StatArchiveFile[] archives = getArchives(); for (int i = 0; i < archives.length; i++) { StatArchiveFile f = archives[i]; if (spec.archiveMatches(f.getFile())) { f.matchSpec(spec, l); } } StatValue[] result = new StatValue[l.size()]; return (StatValue[]) l.toArray(result); } }
/** * Creates a StatArchiveReader that will read the named archive file. * * @param autoClose if its <code>true</code> then the reader will close input files as soon as it * finds their end. * @throws IOException if <code>archiveName</code> could not be opened read, or closed. */ public StatArchiveReader(File[] archiveNames, ValueFilter[] filters, boolean autoClose) throws IOException { this.archives = new StatArchiveFile[archiveNames.length]; this.dump = Boolean.getBoolean("StatArchiveReader.dumpall"); for (int i = 0; i < archiveNames.length; i++) { this.archives[i] = new StatArchiveFile(this, archiveNames[i], dump, filters); } update(false, autoClose); if (this.dump || Boolean.getBoolean("StatArchiveReader.dump")) { this.dump(new PrintWriter(System.out)); } }
/** * Checks to see if any archives have changed since the StatArchiverReader instance was created or * last updated. If an archive has additional samples then those are read the resource instances * maintained by the reader are updated. * <p> * Once closed a reader can no longer be updated. * * @return true if update read some new data. * @throws IOException if an archive could not be opened read, or closed. */ public boolean update() throws IOException { return update(true, false); }
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(); } }
@Override int fill(double[] values, int valueOffset, int typeCode, int skipCount) { int fillcount = values.length - valueOffset; // space left in values int maxCount = count - skipCount; // maximum values this interval can produce if (fillcount > maxCount) { fillcount = maxCount; } long bitValue = firstValue; for (int i = 0; i < skipCount; i++) { bitValue += bitIntervals[i]; } for (int i = 0; i < fillcount; i++) { bitValue += bitIntervals[skipCount + i]; values[valueOffset + i] = bitsToDouble(typeCode, bitValue); } return fillcount; }
@Override public Object get(int idx) { int archiveIdx = 0; StatArchiveReader.StatArchiveFile[] archives = getArchives(); for (int i = 0; i < archives.length; i++) { StatArchiveFile f = archives[i]; if (idx < (archiveIdx + f.resourceInstSize)) { return f.resourceInstTable[idx - archiveIdx]; } archiveIdx += f.resourceInstSize; } return null; }
@Override int fill(double[] values, int valueOffset, int typeCode, int skipCount) { int fillcount = values.length - valueOffset; // space left in values int maxCount = count - skipCount; // maximum values this interval can produce if (fillcount > maxCount) { fillcount = maxCount; } long bitValue = firstValue; for (int i = 0; i < skipCount; i++) { bitValue += bitIntervals[i]; } for (int i = 0; i < fillcount; i++) { bitValue += bitIntervals[skipCount + i]; values[valueOffset + i] = bitsToDouble(typeCode, bitValue); } return fillcount; }
private int getMemoryUsed() { int result = 0; StatArchiveReader.StatArchiveFile[] archives = getArchives(); for (int i = 0; i < archives.length; i++) { StatArchiveFile f = archives[i]; result += f.getMemoryUsed(); } return result; }
@Override int fill(double[] values, int valueOffset, int typeCode, int skipCount) { int fillcount = values.length - valueOffset; // space left in values int maxCount = count - skipCount; // maximum values this interval can produce if (fillcount > maxCount) { fillcount = maxCount; } long bitValue = firstValue; for (int i = 0; i < skipCount; i++) { bitValue += bitIntervals[i]; } for (int i = 0; i < fillcount; i++) { bitValue += bitIntervals[skipCount + i]; values[valueOffset + i] = bitsToDouble(typeCode, bitValue); } return fillcount; }
private void dump(PrintWriter stream) { StatArchiveReader.StatArchiveFile[] archives = getArchives(); for (int i = 0; i < archives.length; i++) { StatArchiveFile f = archives[i]; f.dump(stream); } }
@Override int fill(double[] values, int valueOffset, int typeCode, int skipCount) { int fillcount = values.length - valueOffset; // space left in values int maxCount = count - skipCount; // maximum values this interval can produce if (fillcount > maxCount) { fillcount = maxCount; } double value = bitsToDouble(typeCode, getBits()); for (int i = 0; i < fillcount; i++) { values[valueOffset + i] = value; } return fillcount; }
/** * Closes all archives. */ @Override public void close() throws IOException { if (!this.closed) { StatArchiveReader.StatArchiveFile[] archives = getArchives(); for (int i = 0; i < archives.length; i++) { StatArchiveFile f = archives[i]; f.close(); } this.closed = true; } }
@Override int fill(double[] values, int valueOffset, int typeCode, int skipCount) { int fillcount = values.length - valueOffset; // space left in values int maxCount = count - skipCount; // maximum values this interval can produce if (fillcount > maxCount) { fillcount = maxCount; } long base = getBits(); long interval = getInterval(); base += skipCount * interval; for (int i = 0; i < fillcount; i++) { values[valueOffset + i] = bitsToDouble(typeCode, base); base += interval; } return fillcount; }
private boolean update(boolean doReset, boolean autoClose) throws IOException { if (this.closed) { return false; } boolean result = false; StatArchiveReader.StatArchiveFile[] archives = getArchives(); for (int i = 0; i < archives.length; i++) { StatArchiveFile f = archives[i]; if (f.update(doReset)) { result = true; } if (autoClose) { f.close(); } } return result; }