aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java9
-rw-r--r--src/test/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCacheTest.java21
2 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java b/src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java
index a4406d7e43..3e608cf2da 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java
@@ -281,7 +281,10 @@ public class CompactPersistentActionCache implements ActionCache {
@Override
public synchronized String toString() {
StringBuilder builder = new StringBuilder();
- builder.append("Action cache (" + map.size() + " records):\n");
+ // map.size() - 1 to avoid counting the validation key.
+ builder.append("Action cache (" + (map.size() - 1) + " records):\n");
+ int size = map.size() > 1000 ? 10 : map.size();
+ int ct = 0;
for (Map.Entry<Integer, byte[]> entry: map.entrySet()) {
if (entry.getKey() == VALIDATION_KEY) { continue; }
String content;
@@ -292,6 +295,10 @@ public class CompactPersistentActionCache implements ActionCache {
}
builder.append("-> ").append(indexer.getStringForIndex(entry.getKey())).append("\n")
.append(content).append(" packed_len = ").append(entry.getValue().length).append("\n");
+ if (++ct > size) {
+ builder.append("...");
+ break;
+ }
}
return builder.toString();
}
diff --git a/src/test/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCacheTest.java b/src/test/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCacheTest.java
index 05b26fb9ec..d306327e80 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCacheTest.java
@@ -14,6 +14,8 @@
package com.google.devtools.build.lib.actions.cache;
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -160,6 +162,25 @@ public class CompactPersistentActionCacheTest {
entry.toString();
}
+ private void assertToStringIsntTooBig(int numRecords) throws Exception {
+ for (int i = 0; i < numRecords; i++) {
+ putKey(Integer.toString(i));
+ }
+ String val = cache.toString();
+ assertThat(val).startsWith("Action cache (" + numRecords + " records):\n");
+ assertWithMessage(val).that(val.length()).isAtMost(2000);
+ // Cache was too big to print out fully.
+ if (numRecords > 10) {
+ assertThat(val).endsWith("...");
+ }
+ }
+
+ @Test
+ public void testToStringIsntTooBig() throws Exception {
+ assertToStringIsntTooBig(3);
+ assertToStringIsntTooBig(3000);
+ }
+
private static void assertKeyEquals(ActionCache cache1, ActionCache cache2, String key) {
Object entry = cache1.get(key);
assertNotNull(entry);