Estimate memory usage in bytes rather than pixel area, assuming an int per
pixel for now. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2034 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ActionFrames.java,v 1.6 2002/09/17 19:11:13 mdb Exp $
|
// $Id: ActionFrames.java,v 1.7 2002/12/07 02:04:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cast;
|
package com.threerings.cast;
|
||||||
|
|
||||||
@@ -49,4 +49,10 @@ public interface ActionFrames
|
|||||||
* colorizations applied to the frame images.
|
* colorizations applied to the frame images.
|
||||||
*/
|
*/
|
||||||
public ActionFrames cloneColorized (Colorization[] zations);
|
public ActionFrames cloneColorized (Colorization[] zations);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the estimated memory usage in bytes for all images cached
|
||||||
|
* internally for use by the action frames.
|
||||||
|
*/
|
||||||
|
public long getEstimatedMemoryUsage ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: CharacterManager.java,v 1.25 2002/12/07 01:10:25 shaper Exp $
|
// $Id: CharacterManager.java,v 1.26 2002/12/07 02:04:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cast;
|
package com.threerings.cast;
|
||||||
|
|
||||||
@@ -184,15 +184,31 @@ public class CharacterManager
|
|||||||
|
|
||||||
// periodically report our action cache performance
|
// periodically report our action cache performance
|
||||||
if (!_cacheStatThrottle.throttleOp()) {
|
if (!_cacheStatThrottle.throttleOp()) {
|
||||||
|
long size = getEstimatedCacheMemoryUsage();
|
||||||
int[] eff = _frames.getTrackedEffectiveness();
|
int[] eff = _frames.getTrackedEffectiveness();
|
||||||
Log.debug("CharacterManager LRU " +
|
Log.debug("CharacterManager LRU " +
|
||||||
"[hits=" + eff[0] + ", misses=" + eff[1] +
|
"[mem=" + (size / 1024) + "k, size=" + _frames.size() +
|
||||||
", size=" + _frames.size() + "].");
|
", hits=" + eff[0] + ", misses=" + eff[1] + "].");
|
||||||
}
|
}
|
||||||
|
|
||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the estimated memory usage in bytes for all images
|
||||||
|
* currently cached by the cached action frames.
|
||||||
|
*/
|
||||||
|
protected long getEstimatedCacheMemoryUsage ()
|
||||||
|
{
|
||||||
|
long size = 0;
|
||||||
|
Iterator iter = _frames.values().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
ActionFrames frame = (ActionFrames)iter.next();
|
||||||
|
size += frame.getEstimatedMemoryUsage();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the composited animation frames for the specified action
|
* Generates the composited animation frames for the specified action
|
||||||
* for a character with the specified descriptor.
|
* for a character with the specified descriptor.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: CompositedActionFrames.java,v 1.8 2002/09/17 19:11:13 mdb Exp $
|
// $Id: CompositedActionFrames.java,v 1.9 2002/12/07 02:04:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cast;
|
package com.threerings.cast;
|
||||||
|
|
||||||
@@ -114,6 +114,21 @@ public class CompositedActionFrames
|
|||||||
throw new RuntimeException("What you talkin' about Willis?");
|
throw new RuntimeException("What you talkin' about Willis?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface
|
||||||
|
public long getEstimatedMemoryUsage ()
|
||||||
|
{
|
||||||
|
long size = 0;
|
||||||
|
for (int orient = 0; orient < _orientCount; orient++) {
|
||||||
|
for (int ii = 0; ii < _images[orient].length; ii++) {
|
||||||
|
Image image = _images[orient][ii];
|
||||||
|
if (image != null) {
|
||||||
|
size += ImageUtil.getEstimatedMemoryUsage(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected Image getFrame (int orient, int index)
|
protected Image getFrame (int orient, int index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: BundledComponentRepository.java,v 1.19 2002/10/18 23:47:27 shaper Exp $
|
// $Id: BundledComponentRepository.java,v 1.20 2002/12/07 02:04:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cast.bundle;
|
package com.threerings.cast.bundle;
|
||||||
|
|
||||||
@@ -416,6 +416,15 @@ public class BundledComponentRepository
|
|||||||
_set.cloneColorized(zations), _actseq);
|
_set.cloneColorized(zations), _actseq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface
|
||||||
|
public long getEstimatedMemoryUsage ()
|
||||||
|
{
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Can't provide memory usage information since " +
|
||||||
|
"TileSetFrameImage makes use of an underlying tile set " +
|
||||||
|
"and we don't know said tileset's memory usage.");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the requested tile.
|
* Fetches the requested tile.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ImageManager.java,v 1.30 2002/12/07 01:10:25 shaper Exp $
|
// $Id: ImageManager.java,v 1.31 2002/12/07 02:04:32 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.media;
|
package com.threerings.media;
|
||||||
|
|
||||||
@@ -155,9 +155,10 @@ public class ImageManager
|
|||||||
protected void reportCachePerformance ()
|
protected void reportCachePerformance ()
|
||||||
{
|
{
|
||||||
if (!_cacheStatThrottle.throttleOp()) {
|
if (!_cacheStatThrottle.throttleOp()) {
|
||||||
int size = getCachedImageSize() / 1024;
|
long size = ImageUtil.getEstimatedMemoryUsage(
|
||||||
|
_imgs.values().iterator());
|
||||||
int[] eff = _imgs.getTrackedEffectiveness();
|
int[] eff = _imgs.getTrackedEffectiveness();
|
||||||
Log.debug("ImageManager LRU [area=" + size + "k pixels" +
|
Log.debug("ImageManager LRU [mem=" + (size / 1024) + "k" +
|
||||||
", size=" + _imgs.size() + ", hits=" + eff[0] +
|
", size=" + _imgs.size() + ", hits=" + eff[0] +
|
||||||
", misses=" + eff[1] + "].");
|
", misses=" + eff[1] + "].");
|
||||||
}
|
}
|
||||||
@@ -264,21 +265,6 @@ public class ImageManager
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the estimated size of the cached images as the total area
|
|
||||||
* in pixels occupied by all images.
|
|
||||||
*/
|
|
||||||
protected int getCachedImageSize ()
|
|
||||||
{
|
|
||||||
Iterator iter = _imgs.values().iterator();
|
|
||||||
int size = 0;
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
Image image = (Image)iter.next();
|
|
||||||
size += (image.getWidth(null) * image.getHeight(null));
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A reference to the resource manager via which we load image data
|
/** A reference to the resource manager via which we load image data
|
||||||
* by default. */
|
* by default. */
|
||||||
protected ResourceManager _rmgr;
|
protected ResourceManager _rmgr;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ImageUtil.java,v 1.18 2002/11/15 09:29:40 shaper Exp $
|
// $Id: ImageUtil.java,v 1.19 2002/12/07 02:04:32 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.media.util;
|
package com.threerings.media.util;
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ import java.awt.image.Raster;
|
|||||||
import java.awt.image.WritableRaster;
|
import java.awt.image.WritableRaster;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
@@ -527,6 +528,33 @@ public class ImageUtil
|
|||||||
tbounds.height = lastrow - firstrow + 1;
|
tbounds.height = lastrow - firstrow + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the estimated memory usage in bytes for the specified
|
||||||
|
* image.
|
||||||
|
*/
|
||||||
|
public static long getEstimatedMemoryUsage (Image image)
|
||||||
|
{
|
||||||
|
int area = image.getWidth(null) * image.getHeight(null);
|
||||||
|
// TODO: we assume an int per pixel for now, but should really
|
||||||
|
// study the sample model if it's a buffered image to do more
|
||||||
|
// intelligent estimation.
|
||||||
|
return (area * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the estimated memory usage in bytes for all images in the
|
||||||
|
* supplied iterator.
|
||||||
|
*/
|
||||||
|
public static long getEstimatedMemoryUsage (Iterator iter)
|
||||||
|
{
|
||||||
|
long size = 0;
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Image image = (Image)iter.next();
|
||||||
|
size += getEstimatedMemoryUsage(image);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the default graphics configuration for this VM.
|
* Obtains the default graphics configuration for this VM.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user