/** * 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]"); System.exit(1); } 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(); }
final StatArchiveReader reader = new StatArchiveReader(archiveFiles, filters, true); final StatValue[] values = reader.matchSpec(statSpec); return values;
@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; }
/** * 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)); } }
reader = new StatArchiveReader(new File[]{archive}, null, false); } catch (IOException e) { fail("Failed to read " + archive); List resources = reader.getResourceInstList(); for (@SuppressWarnings("rawtypes") Iterator iter = resources.iterator(); iter.hasNext();) {
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(); Map<CombinedResources, List<StatValue>> allSpecsMap = 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) {
/** * 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); } }
@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; } }
/** * For internal use only. * <p> * Fetches a statistic reader for the stat spec on matching archives. */ private StatArchiveReader getStatArchiveReader( RuntimeStatSpec statspec ) { try { List archives = statspec.getMatchingArchives(); if ( Log.getLogWriter().fineEnabled() ) { Log.getLogWriter().fine( "Archives: " + archives ); } return new StatArchiveReader( (File[])archives.toArray( new File[ archives.size() ] ), new RuntimeStatSpec[] { statspec }, true); } catch( IOException e ) { throw new StatConfigException( "Unable to read archive", e ); } } }
/** * For internal use only. * <p> * Fetches, trims, and converts the matching statistics using the reader. */ private List readStatistics( StatSpec statspec, TrimSpec trimspec, StatArchiveReader reader ) { List psvs = new ArrayList(); StatArchiveReader.StatValue[] values = reader.matchSpec( statspec ); if ( Log.getLogWriter().finerEnabled() ) { Log.getLogWriter().finer( "Values: " + values ); } for ( int i = 0; i < values.length; i++ ) { StatArchiveReader.StatValue sv = values[i]; if ( Log.getLogWriter().finerEnabled() ) { Log.getLogWriter().finer( "Value: " + sv.toString() ); } PerfStatValue psv = PerfStatReader.getPerfStatValue( statspec, trimspec, sv ); psvs.add( psv ); } if ( Log.getLogWriter().finerEnabled() ) { Log.getLogWriter().finer( "PerfStatValues: " + psvs ); } return psvs.size() == 0 ? null : psvs; }
/** * 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); } private boolean update(boolean doReset, boolean autoClose) throws IOException {
reader = new StatArchiveReader(new File[]{archive}, null, false); } catch (IOException e) { fail("Failed to read " + archive); List resources = reader.getResourceInstList(); assertNotNull(resources); assertFalse(resources.isEmpty());
boolean interrupted = false; try { reader = new StatArchiveReader(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(); Map<CombinedResources, List<StatValue>> allSpecsMap = 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) {
/** * 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); } }
@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; } }
/** * 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); } private boolean update(boolean doReset, boolean autoClose) throws IOException {
final StatArchiveReader reader = new StatArchiveReader( new File[]{new File(archiveFileName)}, null, false); final List resources = reader.getResourceInstList(); assertNotNull(resources); assertEquals(1, resources.size());
/** * 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]"); System.exit(1); } 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(); }
StatArchiveReader reader = new StatArchiveReader( (File[])archives.toArray(new File[archives.size()]), (StatSpec[])statspecs.toArray(new StatSpec[statspecs.size()]), while (it.hasNext()) { StatSpec spec = (StatSpec)it.next(); StatArchiveReader.StatValue[] values = reader.matchSpec(spec); if (Log.getLogWriter().finestEnabled()) { for (int i = 0; i < values.length; i++) {