+++ /dev/null
-/*
- * Copyright (c) 2024 Jacek Centkowski <geminica.programs@gmail.com> and others.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Distribution License v. 1.0 which is available at
- * https://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-package org.eclipse.jgit.internal.storage.file;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.util.stream.StreamSupport;
-
-import org.eclipse.jgit.lib.PersonIdent;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.junit.Test;
-
-public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase {
- @Test
- public void testShouldReportZeroObjectsForInitializedRepo()
- throws IOException {
- assertEquals(0L, gc.getStatistics().numberOfPackFilesSinceBitmap);
- }
-
- @Test
- public void testShouldReportAllPackFilesWhenNoGcWasPerformed()
- throws Exception {
- tr.packAndPrune();
- long result = gc.getStatistics().numberOfPackFilesSinceBitmap;
-
- assertEquals(repo.getObjectDatabase().getPacks().size(), result);
- }
-
- @Test
- public void testShouldReportNoObjectsDirectlyAfterGc() throws Exception {
- // given
- addCommit(null);
- gc.gc().get();
- assertEquals(1L, repositoryBitmapFiles());
- assertEquals(0L, gc.getStatistics().numberOfPackFilesSinceBitmap);
- }
-
- @Test
- public void testShouldReportNewObjectsSinceGcWhenRepositoryProgresses()
- throws Exception {
- // commit & gc
- RevCommit parent = addCommit(null);
- gc.gc().get();
- assertEquals(1L, repositoryBitmapFiles());
-
- // progress & pack
- addCommit(parent);
- tr.packAndPrune();
-
- assertEquals(1L, gc.getStatistics().numberOfPackFilesSinceBitmap);
- }
-
- @Test
- public void testShouldReportNewObjectsFromTheLatestBitmapWhenRepositoryProgresses()
- throws Exception {
- // commit & gc
- RevCommit parent = addCommit(null);
- gc.gc().get();
- assertEquals(1L, repositoryBitmapFiles());
-
- // progress & gc
- parent = addCommit(parent);
- gc.gc().get();
- assertEquals(2L, repositoryBitmapFiles());
-
- // progress & pack
- addCommit(parent);
- tr.packAndPrune();
-
- assertEquals(1L, gc.getStatistics().numberOfPackFilesSinceBitmap);
- }
-
- private RevCommit addCommit(RevCommit parent) throws Exception {
- return tr.branch("master").commit()
- .author(new PersonIdent("repo-metrics", "repo@metrics.com"))
- .parent(parent).create();
- }
-
- private long repositoryBitmapFiles() throws IOException {
- return StreamSupport
- .stream(Files
- .newDirectoryStream(repo.getObjectDatabase()
- .getPackDirectory().toPath(), "pack-*.bitmap")
- .spliterator(), false)
- .count();
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2024 Jacek Centkowski <geminica.programs@gmail.com> and others.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.eclipse.jgit.internal.storage.file;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Collection;
+import java.util.stream.StreamSupport;
+
+import org.eclipse.jgit.internal.storage.file.GC.RepoStatistics;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.junit.Test;
+
+public class GcSinceBitmapStatisticsTest extends GcTestCase {
+ @Test
+ public void testShouldReportZeroPacksAndObjectsForInitializedRepo()
+ throws IOException {
+ RepoStatistics s = gc.getStatistics();
+ assertEquals(0L, s.numberOfPackFilesSinceBitmap);
+ assertEquals(0L, s.numberOfObjectsSinceBitmap);
+ }
+
+ @Test
+ public void testShouldReportAllPackFilesWhenNoGcWasPerformed()
+ throws Exception {
+ tr.packAndPrune();
+ long result = gc.getStatistics().numberOfPackFilesSinceBitmap;
+
+ assertEquals(repo.getObjectDatabase().getPacks().size(), result);
+ }
+
+ @Test
+ public void testShouldReportAllObjectsWhenNoGcWasPerformed()
+ throws Exception {
+ tr.packAndPrune();
+
+ assertEquals(
+ getNumberOfObjectsInPacks(repo.getObjectDatabase().getPacks()),
+ gc.getStatistics().numberOfObjectsSinceBitmap);
+ }
+
+ @Test
+ public void testShouldReportNoPacksDirectlyAfterGc() throws Exception {
+ // given
+ addCommit(null);
+ gc.gc().get();
+ assertEquals(1L, repositoryBitmapFiles());
+ assertEquals(0L, gc.getStatistics().numberOfPackFilesSinceBitmap);
+ }
+
+ @Test
+ public void testShouldReportNoObjectsDirectlyAfterGc() throws Exception {
+ // given
+ addCommit(null);
+ assertEquals(2L, gc.getStatistics().numberOfObjectsSinceBitmap);
+
+ gc.gc().get();
+ assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap);
+ }
+
+ @Test
+ public void testShouldReportNewPacksSinceGcWhenRepositoryProgresses()
+ throws Exception {
+ // commit & gc
+ RevCommit parent = addCommit(null);
+ gc.gc().get();
+ assertEquals(1L, repositoryBitmapFiles());
+
+ // progress & pack
+ addCommit(parent);
+ tr.packAndPrune();
+
+ assertEquals(1L, gc.getStatistics().numberOfPackFilesSinceBitmap);
+ }
+
+ @Test
+ public void testShouldReportNewObjectsSinceGcWhenRepositoryProgresses()
+ throws Exception {
+ // commit & gc
+ RevCommit parent = addCommit(null);
+ gc.gc().get();
+ assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap);
+
+ // progress & pack
+ addCommit(parent);
+ assertEquals(1L, gc.getStatistics().numberOfObjectsSinceBitmap);
+
+ tr.packAndPrune();
+ assertEquals(3L, gc.getStatistics().numberOfObjectsSinceBitmap);
+ }
+
+ @Test
+ public void testShouldReportNewPacksFromTheLatestBitmapWhenRepositoryProgresses()
+ throws Exception {
+ // commit & gc
+ RevCommit parent = addCommit(null);
+ gc.gc().get();
+ assertEquals(1L, repositoryBitmapFiles());
+
+ // progress & gc
+ parent = addCommit(parent);
+ gc.gc().get();
+ assertEquals(2L, repositoryBitmapFiles());
+
+ // progress & pack
+ addCommit(parent);
+ tr.packAndPrune();
+
+ assertEquals(1L, gc.getStatistics().numberOfPackFilesSinceBitmap);
+ }
+
+ @Test
+ public void testShouldReportNewObjectsFromTheLatestBitmapWhenRepositoryProgresses()
+ throws Exception {
+ // commit & gc
+ RevCommit parent = addCommit(null);
+ gc.gc().get();
+
+ // progress & gc
+ parent = addCommit(parent);
+ gc.gc().get();
+ assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap);
+
+ // progress & pack
+ addCommit(parent);
+ assertEquals(1L, gc.getStatistics().numberOfObjectsSinceBitmap);
+
+ tr.packAndPrune();
+ assertEquals(4L, gc.getStatistics().numberOfObjectsSinceBitmap);
+ }
+
+ private RevCommit addCommit(RevCommit parent) throws Exception {
+ return tr.branch("master").commit()
+ .author(new PersonIdent("repo-metrics", "repo@metrics.com"))
+ .parent(parent).create();
+ }
+
+ private long repositoryBitmapFiles() throws IOException {
+ return StreamSupport
+ .stream(Files
+ .newDirectoryStream(repo.getObjectDatabase()
+ .getPackDirectory().toPath(), "pack-*.bitmap")
+ .spliterator(), false)
+ .count();
+ }
+
+ private long getNumberOfObjectsInPacks(Collection<Pack> packs) {
+ return packs.stream().mapToLong(pack -> {
+ try {
+ return pack.getObjectCount();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }).sum();
+ }
+}
*/
public long numberOfPackFilesSinceBitmap;
+ /**
+ * The number of objects stored in pack files and as loose object
+ * created after the last bitmap generation.
+ */
+ public long numberOfObjectsSinceBitmap;
+
/**
* The number of objects stored as loose objects.
*/
b.append(", numberOfPackFiles=").append(numberOfPackFiles); //$NON-NLS-1$
b.append(", numberOfPackFilesSinceBitmap=") //$NON-NLS-1$
.append(numberOfPackFilesSinceBitmap);
+ b.append(", numberOfObjectsSinceBitmap=") //$NON-NLS-1$
+ .append(numberOfObjectsSinceBitmap);
b.append(", numberOfLooseObjects=").append(numberOfLooseObjects); //$NON-NLS-1$
b.append(", numberOfLooseRefs=").append(numberOfLooseRefs); //$NON-NLS-1$
b.append(", numberOfPackedRefs=").append(numberOfPackedRefs); //$NON-NLS-1$
public RepoStatistics getStatistics() throws IOException {
RepoStatistics ret = new RepoStatistics();
Collection<Pack> packs = repo.getObjectDatabase().getPacks();
+ long latestBitmapTime = Long.MIN_VALUE;
for (Pack p : packs) {
- ret.numberOfPackedObjects += p.getIndex().getObjectCount();
+ long packedObjects = p.getIndex().getObjectCount();
+ ret.numberOfPackedObjects += packedObjects;
ret.numberOfPackFiles++;
ret.sizeOfPackedObjects += p.getPackFile().length();
if (p.getBitmapIndex() != null) {
ret.numberOfBitmaps += p.getBitmapIndex().getBitmapCount();
+ latestBitmapTime = p.getFileSnapshot().lastModifiedInstant()
+ .toEpochMilli();
} else {
ret.numberOfPackFilesSinceBitmap++;
+ ret.numberOfObjectsSinceBitmap += packedObjects;
}
}
File objDir = repo.getObjectsDirectory();
continue;
ret.numberOfLooseObjects++;
ret.sizeOfLooseObjects += f.length();
+ if (f.lastModified() > latestBitmapTime) {
+ ret.numberOfObjectsSinceBitmap ++;
+ }
}
}
}