From 6b9b024c91ac71ecbc49fd36d0500c52cde01794 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Fri, 31 Aug 2012 16:14:12 +0200 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/storage/file/GC.java | 45 ++++++++++++++++--- 1 file 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 60d9cd0c0..1c2b95932 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.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 RepoStatistics { * 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 RepoStatistics { public RepoStatistics getStatistics() throws IOException { RepoStatistics ret = new RepoStatistics(); Collection 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; }