diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java index cf9aceae58..26e0546bc7 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java @@ -31,6 +31,7 @@ import com.github.benmanes.caffeine.cache.simulator.parser.camelab.CamelabTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.cloud_physics.CloudPhysicsTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.corda.CordaTraceReader; +import com.github.benmanes.caffeine.cache.simulator.parser.glcache.GLCacheTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.gradle.GradleTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.kaggle.OutbrainTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.lirs.LirsTraceReader; @@ -69,6 +70,7 @@ public enum TraceFormat { CAMELAB(CamelabTraceReader::new), CLOUD_PHYSICS(CloudPhysicsTraceReader::new), CORDA(CordaTraceReader::new), + GL_CACHE(GLCacheTraceReader::new), GRADLE(GradleTraceReader::new), LIRS(LirsTraceReader::new), LRB(LrbTraceReader::new), diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/glcache/GLCacheTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/glcache/GLCacheTraceReader.java new file mode 100644 index 0000000000..2d06e699af --- /dev/null +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/glcache/GLCacheTraceReader.java @@ -0,0 +1,62 @@ +/* + * Copyright 2023 Ben Manes. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.benmanes.caffeine.cache.simulator.parser.glcache; + +import static com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic.WEIGHTED; + +import java.io.DataInputStream; +import java.io.IOException; +import java.util.Set; + +import com.github.benmanes.caffeine.cache.simulator.parser.BinaryTraceReader; +import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent; +import com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic; + +/** + * A reader for the trace files provided by the author of GL-Cache. See + * traces. + * + * @author ben.manes@gmail.com (Ben Manes) + */ +public final class GLCacheTraceReader extends BinaryTraceReader { + + public GLCacheTraceReader(String filePath) { + super(filePath); + } + + @Override + public Set characteristics() { + return Set.of(WEIGHTED); + } + + @Override + protected AccessEvent readEvent(DataInputStream input) throws IOException { + /* + * struct { + * uint32_t timestamp; + * uint64_t obj_id; + * uint32_t obj_size; + * int64_t next_access_vtime; // -1 if no next access + * } + */ + input.readInt(); + long key = input.readLong(); + int weight = input.readInt(); + input.readLong(); + + return AccessEvent.forKeyAndWeight(key, weight); + } +} diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/glcache/package-info.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/glcache/package-info.java new file mode 100644 index 0000000000..8727e2f92f --- /dev/null +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/glcache/package-info.java @@ -0,0 +1,4 @@ +@CheckReturnValue +package com.github.benmanes.caffeine.cache.simulator.parser.glcache; + +import com.google.errorprone.annotations.CheckReturnValue;