Mercurial > hg > blitz_condensed
view src/org/dancres/blitz/SearchTasks.java @ 22:b7e52953b7a6
Add some cache/memory statistics to help spot potential exhaustion and other tuning issues.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Fri, 28 Aug 2009 17:23:33 +0100 |
parents | 3dc0c5604566 |
children |
line wrap: on
line source
package org.dancres.blitz; import org.dancres.blitz.stats.BlockingOpsStat; import org.dancres.blitz.stats.MissedOpsStat; import org.dancres.blitz.stats.Stat; import org.dancres.blitz.stats.StatGenerator; import org.dancres.blitz.stats.StatsBoard; import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger; import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong; /** * Tracks the number ouf outstanding blocked operations (take and read) */ class SearchTasks { private static SearchTasks theTasks = new SearchTasks(); private AtomicInteger theTakeCount = new AtomicInteger(); private AtomicInteger theReadCount = new AtomicInteger(); private AtomicLong theMissedTakes = new AtomicLong(); private AtomicLong theMissedReads = new AtomicLong(); public static SearchTasks get() { return theTasks; } private SearchTasks() { StatsBoard.get().add(new BlockingStatGenerator()); StatsBoard.get().add(new MissedStatGenerator()); } public void add(MatchTask aTask) { if (aTask.getVisitor().isDeleter()) theTakeCount.incrementAndGet(); else theReadCount.incrementAndGet(); } public void remove(MatchTask aTask, boolean didMiss) { if (aTask.getVisitor().isDeleter()) { theTakeCount.decrementAndGet(); if (didMiss) theMissedTakes.incrementAndGet(); } else { theReadCount.decrementAndGet(); if (didMiss) theMissedReads.incrementAndGet(); } } private class BlockingStatGenerator implements StatGenerator { private long theStatId = StatGenerator.UNSET_ID; public long getId() { return theStatId; } public void setId(long anId) { theStatId = anId; } public Stat generate() { return new BlockingOpsStat( theStatId, theReadCount.intValue(), theTakeCount.intValue()); } } private class MissedStatGenerator implements StatGenerator { private long theStatId = StatGenerator.UNSET_ID; public long getId() { return theStatId; } public void setId(long anId) { theStatId = anId; } public Stat generate() { return new MissedOpsStat( theStatId, theMissedReads.longValue(), theMissedTakes.longValue()); } } }