summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2012-08-31 16:14:12 +0200
committerChristian Halstrick <christian.halstrick@sap.com>2012-08-31 16:14:12 +0200
commit6b9b024c91ac71ecbc49fd36d0500c52cde01794 (patch)
tree40a4949b221571d6a1a2e4ff8fb2a2d9a282824e
parentabd60101b646bfa170e7a4066fd64c32571e4a15 (diff)
downloadjgit-6b9b024c91ac71ecbc49fd36d0500c52cde01794.tar.gz
jgit-6b9b024c91ac71ecbc49fd36d0500c52cde01794.zip
Enhance statistics for repo by sizes and ref-counts
The statistics for a repo now expose how many bytes are used in the filesystem to store all loose/packed objects. The number of packed/loose refs are also exposed. Change-Id: I335a4c7630a2629a86f13a2a5cd99f79a2c2afa4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java45
1 files changed, 40 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java
index 60d9cd0c02..1c2b959323 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java
@@ -74,6 +74,8 @@ import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Ref.Storage;
+import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -716,6 +718,26 @@ public class GC {
* The number of objects stored as loose objects.
*/
public long numberOfLooseObjects;
+
+ /**
+ * The sum of the sizes of all files used to persist loose objects.
+ */
+ public long sizeOfLooseObjects;
+
+ /**
+ * The sum of the sizes of all pack files.
+ */
+ public long sizeOfPackedObjects;
+
+ /**
+ * The number of loose refs.
+ */
+ public long numberOfLooseRefs;
+
+ /**
+ * The number of refs stored in pack files.
+ */
+ public long numberOfPackedRefs;
}
/**
@@ -728,25 +750,38 @@ public class GC {
public RepoStatistics getStatistics() throws IOException {
RepoStatistics ret = new RepoStatistics();
Collection<PackFile> packs = repo.getObjectDatabase().getPacks();
- for (PackFile f : packs)
+ for (PackFile f : packs) {
ret.numberOfPackedObjects += f.getIndex().getObjectCount();
- ret.numberOfPackFiles = packs.size();
+ ret.numberOfPackFiles++;
+ ret.sizeOfPackedObjects += f.getPackFile().length();
+ }
File objDir = repo.getObjectsDirectory();
String[] fanout = objDir.list();
if (fanout != null && fanout.length > 0) {
for (String d : fanout) {
if (d.length() != 2)
continue;
- String[] entries = new File(objDir, d).list();
+ File[] entries = new File(objDir, d).listFiles();
if (entries == null)
continue;
- for (String e : entries) {
- if (e.length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
+ for (File f : entries) {
+ if (f.getName().length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
continue;
ret.numberOfLooseObjects++;
+ ret.sizeOfLooseObjects += f.length();
}
}
}
+
+ RefDatabase refDb = repo.getRefDatabase();
+ for (Ref r : refDb.getRefs(RefDatabase.ALL).values()) {
+ Storage storage = r.getStorage();
+ if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED)
+ ret.numberOfLooseRefs++;
+ if (storage == Storage.PACKED || storage == Storage.LOOSE_PACKED)
+ ret.numberOfPackedRefs++;
+ }
+
return ret;
}