public class MemoryWatch extends Statistic
Runtime.totalMemory()
and
Runtime.freeMemory()
as needed.
If you enableGCBeforeStartStop()
the this will also cause calls to Runtime.gc()
.
Beware that stops and starts may have significant and unpredictable overhead.
Use with care.
Use
Timing.createMemoryWatch(String)
to create.
count, enableMinMax, enableStdDev
Modifier and Type | Method and Description |
---|---|
void |
clearCumulative()
Resets cumulative time and count to zero.
|
void |
clearCumulative(boolean silently)
Resets cumulative time and count to zero.
|
int |
compareTo(org.mitre.poorMan.javaTiming.HasName ot) |
static long |
currentUsage()
Convenience method to get the current total memory - the current
free memory.
|
MemoryWatch |
enableGCBeforeStartStop()
Enable attempted memory recovery before every start() and
stop().
|
MemoryWatch |
enableMinMax()
Enable tracking of min and max.
|
MemoryWatch |
enableStdDev()
Enable computation of standard deviation.
|
boolean |
equals(java.lang.Object o)
Equality is determined by a unique id which is
assigned upon instantiation.
|
java.lang.String |
getCompositeName() |
java.lang.String |
getLocationInCodeString()
The returned string reflects the java class, method, and line number
at which the StopWatch was created.
|
java.lang.String |
getName() |
long |
getStartMemory()
The memory usage upon start.
|
protected int |
getUniqueId() |
int |
hashCode() |
boolean |
isStarted() |
static void |
recoverMemory()
Instruct java to cleanup memory.
|
MemoryWatch |
setUnits(java.lang.String units,
double multiplier)
Specify the units and the multiplier to use.
|
MemoryWatch |
start()
Starts the counter in nanoseconds
|
MemoryWatch |
startAtSameMemAs(MemoryWatch other)
Set the start memory to be
the same as that of another.
|
void |
stop()
Stops the counter, advances the count by one, and adds to the accumulated memory
|
void |
stop(int countIncrement)
Stops the counter, adds to the accumulated memory, and adds the specified
count increment (instead of 1) to the count.
|
java.lang.String |
summarize() |
void |
summarize(java.util.Formatter formatter)
Builds a summary of the metric
|
void |
summarize(java.lang.StringBuilder sb)
Appends a summary line for the metric using the specified StringBuilder.
|
MemoryWatch |
suppressIfCountIsZero()
This indicates that the MemoryWatch summary line
should not be output to the screen with
Timing.dumpTimings(java.lang.String) is called
if the getCount() value is zero. |
MemoryWatch |
suppressIfValueIsZero()
This indicates that the MemoryWatch summary line
should not be output to the screen with
Timing.dumpTimings(java.lang.String) is called
if the getCount() value is zero. |
void |
tallyAndContinue()
Stops the counter and restarts it in such
a way that no time is lost between stop and start.
|
java.lang.String |
toString() |
public final long getStartMemory()
public final MemoryWatch setUnits(java.lang.String units, double multiplier)
public static long currentUsage()
public final MemoryWatch start()
public final MemoryWatch startAtSameMemAs(MemoryWatch other)
public final MemoryWatch enableGCBeforeStartStop()
public final void stop()
public final void stop(int countIncrement)
public final boolean isStarted()
public void summarize(java.util.Formatter formatter)
public final MemoryWatch suppressIfCountIsZero()
Timing.dumpTimings(java.lang.String)
is called
if the getCount()
value is zero.
Once this call is invoked its effect cannot be undone.public final MemoryWatch suppressIfValueIsZero()
Timing.dumpTimings(java.lang.String)
is called
if the getCount()
value is zero.
Once this call is invoked its effect cannot be undone.public final void tallyAndContinue()
myMemoryWatch.stop()
followed by myMemoryWatch.start()
there is a chance that the nanosecond timer will advance and
you will appear to have time unaccounted for.
This can be helpful in loops where you wish to measure each
iteration of the loop and are carefully accounting for all elapsed time.public static void recoverMemory()
public MemoryWatch enableStdDev()
enableStdDev
in class Statistic
public MemoryWatch enableMinMax()
enableMinMax
in class Statistic
public final void clearCumulative(boolean silently)
silently
- if false then a message is written to the log file indicating that the StopWatch was cleared.public final void clearCumulative()
clearCumulative(true)
public final int compareTo(org.mitre.poorMan.javaTiming.HasName ot)
compareTo
in interface java.lang.Comparable<org.mitre.poorMan.javaTiming.HasName>
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String getCompositeName()
public java.lang.String getLocationInCodeString()
public java.lang.String getName()
protected int getUniqueId()
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public void summarize(java.lang.StringBuilder sb)
public java.lang.String summarize()