Browse Source

Track read IO for DfsReader

Compute how much disk IO a DfsReader is performing, and how long the
sum of those operations took on this reader instance. Implementations
of DFS and interested applications can get the stats by calling the
new DfsReader.getIoStats() method at or after close().

Change-Id: If585741301f29182617933d6406d4a70497f2ca7
stable-4.9
Shawn Pearce 8 years ago
parent
commit
562de51239
  1. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java
  2. 22
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
  3. 21
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
  4. 139
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReaderIoStats.java

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java

@ -322,6 +322,7 @@ public final class DfsBlockCache {
HashEntry e1 = table.get(slot);
DfsBlock v = scan(e1, key, position);
if (v != null) {
ctx.stats.blockCacheHit++;
statHit.incrementAndGet();
return v;
}
@ -334,6 +335,7 @@ public final class DfsBlockCache {
if (e2 != e1) {
v = scan(e2, key, position);
if (v != null) {
ctx.stats.blockCacheHit++;
statHit.incrementAndGet();
creditSpace(blockSize);
return v;

22
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java

@ -251,6 +251,8 @@ public final class DfsPackFile {
PackIndex idx;
try {
ctx.stats.readIdx++;
long start = System.nanoTime();
ReadableChannel rc = ctx.db.openFile(packDesc, INDEX);
try {
InputStream in = Channels.newInputStream(rc);
@ -260,10 +262,11 @@ public final class DfsPackFile {
bs = (wantSize / bs) * bs;
else if (bs <= 0)
bs = wantSize;
in = new BufferedInputStream(in, bs);
idx = PackIndex.read(in);
idx = PackIndex.read(new BufferedInputStream(in, bs));
ctx.stats.readIdxBytes += rc.position();
} finally {
rc.close();
ctx.stats.readIdxMicros += elapsedMicros(start);
}
} catch (EOFException e) {
invalid = true;
@ -286,6 +289,10 @@ public final class DfsPackFile {
}
}
private static long elapsedMicros(long start) {
return (System.nanoTime() - start) / 1000L;
}
final boolean isGarbage() {
return packDesc.getPackSource() == UNREACHABLE_GARBAGE;
}
@ -314,6 +321,8 @@ public final class DfsPackFile {
long size;
PackBitmapIndex idx;
try {
ctx.stats.readBitmap++;
long start = System.nanoTime();
ReadableChannel rc = ctx.db.openFile(packDesc, BITMAP_INDEX);
try {
InputStream in = Channels.newInputStream(rc);
@ -329,6 +338,8 @@ public final class DfsPackFile {
} finally {
size = rc.position();
rc.close();
ctx.stats.readIdxBytes += size;
ctx.stats.readIdxMicros += elapsedMicros(start);
}
} catch (EOFException e) {
IOException e2 = new IOException(MessageFormat.format(
@ -777,6 +788,8 @@ public final class DfsPackFile {
if (invalid)
throw new PackInvalidException(getPackName());
ctx.stats.readBlock++;
long start = System.nanoTime();
ReadableChannel rc = ctx.db.openFile(packDesc, PACK);
try {
int size = blockSize(rc);
@ -803,6 +816,7 @@ public final class DfsPackFile {
byte[] buf = new byte[size];
rc.position(pos);
int cnt = read(rc, ByteBuffer.wrap(buf, 0, size));
ctx.stats.readBlockBytes += cnt;
if (cnt != size) {
if (0 <= len) {
throw new EOFException(MessageFormat.format(
@ -824,10 +838,10 @@ public final class DfsPackFile {
length = len = rc.size();
}
DfsBlock v = new DfsBlock(key, pos, buf);
return v;
return new DfsBlock(key, pos, buf);
} finally {
rc.close();
ctx.stats.readBlockMicros += elapsedMicros(start);
}
}

21
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java

@ -104,14 +104,12 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
/** Database this reader loads objects from. */
final DfsObjDatabase db;
private Inflater inf;
final DfsReaderIoStats.Accumulator stats = new DfsReaderIoStats.Accumulator();
private Inflater inf;
private DfsBlock block;
private DeltaBaseCache baseCache;
private DfsPackFile last;
private boolean avoidUnreachable;
DfsReader(DfsObjDatabase db) {
@ -170,6 +168,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
PackList packList = db.getPackList();
resolveImpl(packList, id, matches);
if (matches.size() < MAX_RESOLVE_MATCHES && packList.dirty()) {
stats.scanPacks++;
resolveImpl(db.scanPacks(packList), id, matches);
}
return matches;
@ -198,6 +197,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
if (hasImpl(packList, objectId)) {
return true;
} else if (packList.dirty()) {
stats.scanPacks++;
return hasImpl(db.scanPacks(packList), objectId);
}
return false;
@ -234,6 +234,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
return checkType(ldr, objectId, typeHint);
}
if (packList.dirty()) {
stats.scanPacks++;
ldr = openImpl(db.scanPacks(packList), objectId);
if (ldr != null) {
return checkType(ldr, objectId, typeHint);
@ -316,6 +317,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
List<FoundObject<T>> r = new ArrayList<>();
findAllImpl(packList, pending, r);
if (!pending.isEmpty() && packList.dirty()) {
stats.scanPacks++;
findAllImpl(db.scanPacks(packList), pending, r);
}
for (T t : pending) {
@ -452,7 +454,6 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
final IOException findAllError = error;
return new AsyncObjectSizeQueue<T>() {
private FoundObject<T> cur;
private long sz;
@Override
@ -718,9 +719,10 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
for (int dstoff = 0;;) {
int n = inf.inflate(dstbuf, dstoff, dstbuf.length - dstoff);
dstoff += n;
if (inf.finished() || (headerOnly && dstoff == dstbuf.length))
if (inf.finished() || (headerOnly && dstoff == dstbuf.length)) {
stats.inflatedBytes += dstoff;
return dstoff;
if (inf.needsInput()) {
} else if (inf.needsInput()) {
pin(pack, position);
position += block.setInput(position, inf);
} else if (n == 0)
@ -764,6 +766,11 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
block = null;
}
/** @return IO statistics accumulated by this reader. */
public DfsReaderIoStats getIoStats() {
return new DfsReaderIoStats(stats);
}
/** Release the current window cursor. */
@Override
public void close() {

139
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReaderIoStats.java

@ -0,0 +1,139 @@
/*
* Copyright (C) 2017, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.internal.storage.dfs;
/** IO statistics for a {@link DfsReader}. */
public class DfsReaderIoStats {
/** POJO to accumulate IO statistics. */
public static class Accumulator {
/** Number of times the reader explicitly called scanPacks. */
long scanPacks;
/** Total number of complete pack indexes read into memory. */
long readIdx;
/** Total number of complete bitmap indexes read into memory. */
long readBitmap;
/** Total number of bytes read from indexes. */
long readIdxBytes;
/** Total microseconds spent reading pack or bitmap indexes. */
long readIdxMicros;
/** Total number of block cache hits. */
long blockCacheHit;
/** Total number of discrete blocks read from pack file(s). */
long readBlock;
/** Total number of compressed bytes read as block sized units. */
long readBlockBytes;
/** Total microseconds spent reading {@link #readBlock} blocks. */
long readBlockMicros;
/** Total number of bytes decompressed. */
long inflatedBytes;
Accumulator() {
}
}
private final Accumulator stats;
DfsReaderIoStats(Accumulator stats) {
this.stats = stats;
}
/** @return number of times the reader explicitly called scanPacks. */
public long getScanPacks() {
return stats.scanPacks;
}
/** @return total number of complete pack indexes read into memory. */
public long getReadPackIndexCount() {
return stats.readIdx;
}
/** @return total number of complete bitmap indexes read into memory. */
public long getReadBitmapIndexCount() {
return stats.readBitmap;
}
/** @return total number of bytes read from indexes. */
public long getReadIndexBytes() {
return stats.readIdxBytes;
}
/** @return total microseconds spent reading pack or bitmap indexes. */
public long getReadIndexMicros() {
return stats.readIdxMicros;
}
/** @return total number of block cache hits. */
public long getBlockCacheHits() {
return stats.blockCacheHit;
}
/** @return total number of discrete blocks read from pack file(s). */
public long getReadBlocksCount() {
return stats.readBlock;
}
/** @return total number of compressed bytes read as block sized units. */
public long getReadBlocksBytes() {
return stats.readBlockBytes;
}
/** @return total microseconds spent reading blocks. */
public long getReadBlocksMicros() {
return stats.readBlockMicros;
}
/** @return total number of bytes decompressed. */
public long getInflatedBytes() {
return stats.inflatedBytes;
}
}
Loading…
Cancel
Save