@Override public String toString() { return "Stream["+streamType+"/"+Strings.makeSizeString(streamSize.get())+"]"; } @Override
public static String makeBasicUsageString() { int present = (int)Math.round(100.0*SoftlyPresent.getUsageTracker().getPercentagePresent()); return Strings.makeSizeString(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())+" / "+ Strings.makeSizeString(Runtime.getRuntime().maxMemory()) + (Runtime.getRuntime().maxMemory() > Runtime.getRuntime().totalMemory() ? " ("+ Strings.makeSizeString(Runtime.getRuntime().totalMemory()) +" real)" : "") + " memory" + "; " + (present>=0 ? present+"% soft-reference maybe retention (of "+SoftlyPresent.getUsageTracker().getTotalEntries()+"); " : "") + Thread.activeCount()+" threads"; }
System.gc(); System.gc(); long newUsed = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); return "allocated " + Strings.makeSizeString((lastAmount+nextAmount)/2) + (lastAmount<nextAmount ? " +- "+Strings.makeSizeString((nextAmount-lastAmount)/2) : "") +" really free memory in "+Strings.makeSizeString(maxChunk)+" chunks; " +"memory used from "+Strings.makeSizeString(oldUsed)+" -> "+Strings.makeSizeString(newUsed)+" / "+ Strings.makeSizeString(Runtime.getRuntime().totalMemory());
public String getTotalString() { return "totals: out="+Strings.makeSizeString(bytesOut.get())+" in="+Strings.makeSizeString(bytesIn.get()); }
public void testSizeString() { assertEquals(Strings.makeSizeString(-1), "-1 B"); assertEquals(Strings.makeSizeString(0), "0 B"); assertEquals(Strings.makeSizeString(999), "999 B"); assertEquals(Strings.makeSizeString(1024), "1024 B"); assertEquals(Strings.makeSizeString(1234), "1234 B"); assertEquals(Strings.makeSizeString(2345), "2.34 kB"); assertEquals(Strings.makeSizeString(4096), "4.10 kB"); assertEquals(Strings.makeSizeString(4567), "4.57 kB"); assertEquals(Strings.makeSizeString(65535), "65.5 kB"); assertEquals(Strings.makeSizeString(23456789L), "23.5 MB"); assertEquals(Strings.makeSizeString(23456789012L), "23.5 GB"); assertEquals(Strings.makeSizeString(23456789012345L), "23.5 TB"); assertEquals(Strings.makeSizeString(Long.MAX_VALUE), "9223372 TB"); }
@Override public String toString() { return MoreObjects.toStringHelper(this) .add("total", Strings.makeSizeString(total)) .add("free", Strings.makeSizeString(free)) .add("used", Strings.makeSizeString(used)) .add("usedFraction", usedFraction) .toString(); } }
long freeMemory = Runtime.getRuntime().freeMemory(); LOG.info("created "+Strings.makeSizeString(created) + " ... in use: "+Strings.makeSizeString(totalMemory - freeMemory)+" / " + Strings.makeSizeString(totalMemory) + " ... reclaimable: "+Strings.makeSizeString(MemoryUsageTracker.SOFT_REFERENCES.getBytesUsed()) + " ... live refs: "+Strings.makeSizeString(sizeOfActiveReferences(references)) + " ... maxMem="+maxMemory+"; totalMem="+totalMemory+"; usedMem="+(totalMemory-freeMemory));
private void checkValidArchive(String url, long minSize) { byte[] bytes; try { bytes = Streams.readFullyAndClose(ResourceUtils.create(this).getResourceFromUrl(url)); log.info("read "+bytes.length+" bytes from "+url+" for "+JavaClassNames.callerNiceClassAndMethod(1)); } catch (Exception e) { log.warn("Unable to read URL "+url+" for " +JavaClassNames.callerNiceClassAndMethod(1)+ "; this test may require hosted (sonatype/mavencentral) repo to be populated"); Assert.fail("Unable to read URL "+url+"; this test may require hosted (sonatype/mavencentral) repo to be populated"); throw Exceptions.propagate(e); } // confirm this follow redirects! Assert.assertTrue(bytes.length > minSize, "download of "+url+" is suspect ("+Strings.makeSizeString(bytes.length)+")"); // (could also check it is a zip etc) }
@Override public void run() { try { byte[] bytes = Streams.readFullyAndClose(ResourceUtils.create(this).getResourceFromUrl(url)); // confirm this follow redirects! Assert.assertTrue(bytes.length > 100*1000, "download of "+url+" is suspect ("+Strings.makeSizeString(bytes.length)+")"); // (could also check it is a zip etc) } catch (Exception e) { throw Exceptions.propagate(e); } }}); }
if (stream.streamSize.get()!=null) { metadata.add("size", stream.streamSize.get()); metadata.add("sizeText", Strings.makeSizeString(stream.streamSize.get()));