BitmapWalker: announce walked objects via listener interface
We want to know what objects had a bitmap in the walk, to see where do they sit in the commit history and evaluate our bitmap selection algorithm. Add a listener interface to the bitmap walker announcing the objects walked and whether they had bitmap. Change-Id: I956fe2ad927a500710d2cbe78ecd4d26f178c266
This commit is contained in:
parent
8db605620b
commit
d3f711ca1d
|
@ -47,6 +47,40 @@ public final class BitmapWalker {
|
||||||
|
|
||||||
private Bitmap prevBitmap;
|
private Bitmap prevBitmap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report events happening during the walk.
|
||||||
|
*
|
||||||
|
* @since 6.8
|
||||||
|
*/
|
||||||
|
public interface BitmapWalkListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The object is in the walk, and it has a bitmap
|
||||||
|
*
|
||||||
|
* @param oid
|
||||||
|
* objectId with a bitmap in the bitmap index
|
||||||
|
*/
|
||||||
|
default void onBitmapFound(ObjectId oid) {
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The object is in the walk but doesn't have bitmap
|
||||||
|
*
|
||||||
|
* @param oid
|
||||||
|
* objectId without a bitmap in the bitmap index
|
||||||
|
*/
|
||||||
|
default void onBitmapNotFound(ObjectId oid) {
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final BitmapWalkListener NO_LISTENER = new BitmapWalkListener() {
|
||||||
|
// Default methods
|
||||||
|
};
|
||||||
|
|
||||||
|
private final BitmapWalkListener listener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a BitmapWalker.
|
* Create a BitmapWalker.
|
||||||
*
|
*
|
||||||
|
@ -56,9 +90,30 @@ public final class BitmapWalker {
|
||||||
*/
|
*/
|
||||||
public BitmapWalker(
|
public BitmapWalker(
|
||||||
ObjectWalk walker, BitmapIndex bitmapIndex, ProgressMonitor pm) {
|
ObjectWalk walker, BitmapIndex bitmapIndex, ProgressMonitor pm) {
|
||||||
|
this(walker, bitmapIndex, pm, NO_LISTENER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a BitmapWalker.
|
||||||
|
*
|
||||||
|
* @param walker
|
||||||
|
* walker to use when traversing the object graph.
|
||||||
|
* @param bitmapIndex
|
||||||
|
* index to obtain bitmaps from.
|
||||||
|
* @param pm
|
||||||
|
* progress monitor to report progress on.
|
||||||
|
* @param listener
|
||||||
|
* listener of event happening during the walk. Use
|
||||||
|
* {@link #NO_LISTENER} for a no-op listener.
|
||||||
|
*
|
||||||
|
* @since 6.8
|
||||||
|
*/
|
||||||
|
public BitmapWalker(ObjectWalk walker, BitmapIndex bitmapIndex,
|
||||||
|
ProgressMonitor pm, BitmapWalkListener listener) {
|
||||||
this.walker = walker;
|
this.walker = walker;
|
||||||
this.bitmapIndex = bitmapIndex;
|
this.bitmapIndex = bitmapIndex;
|
||||||
this.pm = (pm == null) ? NullProgressMonitor.INSTANCE : pm;
|
this.pm = (pm == null) ? NullProgressMonitor.INSTANCE : pm;
|
||||||
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -140,6 +195,7 @@ public BitmapBuilder findObjects(Iterable<? extends ObjectId> start, BitmapBuild
|
||||||
Bitmap bitmap = bitmapIndex.getBitmap(obj);
|
Bitmap bitmap = bitmapIndex.getBitmap(obj);
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
result.or(bitmap);
|
result.or(bitmap);
|
||||||
|
listener.onBitmapFound(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,8 +234,10 @@ private BitmapBuilder findObjectsWalk(Iterable<? extends ObjectId> start, Bitmap
|
||||||
|
|
||||||
for (ObjectId obj : start) {
|
for (ObjectId obj : start) {
|
||||||
Bitmap bitmap = bitmapIndex.getBitmap(obj);
|
Bitmap bitmap = bitmapIndex.getBitmap(obj);
|
||||||
if (bitmap != null)
|
if (bitmap != null) {
|
||||||
bitmapResult.or(bitmap);
|
bitmapResult.or(bitmap);
|
||||||
|
listener.onBitmapFound(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean marked = false;
|
boolean marked = false;
|
||||||
|
@ -208,7 +266,8 @@ private BitmapBuilder findObjectsWalk(Iterable<? extends ObjectId> start, Bitmap
|
||||||
}
|
}
|
||||||
walker.setObjectFilter(new BitmapObjectFilter(bitmapResult));
|
walker.setObjectFilter(new BitmapObjectFilter(bitmapResult));
|
||||||
|
|
||||||
while (walker.next() != null) {
|
ObjectId oid;
|
||||||
|
while ((oid = walker.next()) != null) {
|
||||||
// Iterate through all of the commits. The BitmapRevFilter does
|
// Iterate through all of the commits. The BitmapRevFilter does
|
||||||
// the work.
|
// the work.
|
||||||
//
|
//
|
||||||
|
@ -220,6 +279,7 @@ private BitmapBuilder findObjectsWalk(Iterable<? extends ObjectId> start, Bitmap
|
||||||
// of bitmaps.
|
// of bitmaps.
|
||||||
pm.update(1);
|
pm.update(1);
|
||||||
countOfBitmapIndexMisses++;
|
countOfBitmapIndexMisses++;
|
||||||
|
listener.onBitmapNotFound(oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
RevObject ro;
|
RevObject ro;
|
||||||
|
|
Loading…
Reference in New Issue