*
{@code - * ./gradlew :simulator:rewrite \ + * ./gradlew :simulator:rewrite -q \ * -PinputFormat=? \ * -PinputFiles=? \ * -PoutputFile=? \ @@ -47,11 +43,10 @@ * * @author ben.manes@gmail.com (Ben Manes) */ -@SuppressWarnings({"PMD.ImmutableField", "FieldCanBeFinal"}) public final class Rewriter implements Runnable { - @Option(names = "--inputFiles", required = true, description = "The trace input files. To use " - + "a mix of formats, specify the entry as format:path, e.g. lirs:loop.trace.gz") - private ListinputFiles = new ArrayList<>(); + @Option(names = "--inputFiles", required = true, split = ",", description = "The trace input " + + "files. To use a mix of formats, specify the entry as format:path, e.g. lirs:loop.trace.gz") + private List inputFiles; @Option(names = "--inputFormat", required = true, description = "The default trace input format") private TraceFormat inputFormat; @@ -62,10 +57,10 @@ public final class Rewriter implements Runnable { @Override public void run() { - Stopwatch stopwatch = Stopwatch.createStarted(); - try (OutputStream output = new BufferedOutputStream(Files.newOutputStream(outputFile)); - Stream events = inputFormat.readFiles(inputFiles).events(); - TraceWriter writer = outputFormat.writer(output)) { + var stopwatch = Stopwatch.createStarted(); + try (var output = new BufferedOutputStream(Files.newOutputStream(outputFile)); + var events = inputFormat.readFiles(inputFiles).events(); + var writer = outputFormat.writer(output)) { int[] tick = { 0 }; writer.writeHeader(); events.forEach(event -> { @@ -77,7 +72,8 @@ public void run() { } }); writer.writeFooter(); - System.out.printf("Rewrote %,d events in %s%n", tick[0], stopwatch); + System.out.printf("Rewrote %,d events from %,d inputs in %s%n", + tick[0], inputFiles.size(), stopwatch); } catch (IOException e) { throw new UncheckedIOException(e); } 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 d6c6030196..03edfadb7b 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 @@ -29,7 +29,7 @@ import com.github.benmanes.caffeine.cache.simulator.parser.arc.ArcTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.cache2k.Cache2kTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.camelab.CamelabTraceReader; -import com.github.benmanes.caffeine.cache.simulator.parser.climb.ClimbTraceReader; +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.gradle.GradleTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.kaggle.OutbrainTraceReader; @@ -65,7 +65,7 @@ public enum TraceFormat { ARC(ArcTraceReader::new), CACHE2K(Cache2kTraceReader::new), CAMELAB(CamelabTraceReader::new), - CLIMB(ClimbTraceReader::new), + CLOUD_PHYSICS(CloudPhysicsTraceReader::new), CORDA(CordaTraceReader::new), GRADLE(GradleTraceReader::new), LIRS(LirsTraceReader::new), diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/climb/ClimbTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/climb/ClimbTraceReader.java deleted file mode 100644 index 57bafb5296..0000000000 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/climb/ClimbTraceReader.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2019 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.climb; - -import static java.nio.charset.StandardCharsets.UTF_8; - -import java.io.InputStream; -import java.util.PrimitiveIterator; -import java.util.Scanner; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.stream.LongStream; -import java.util.stream.StreamSupport; - -import com.github.benmanes.caffeine.cache.simulator.parser.TextTraceReader; -import com.github.benmanes.caffeine.cache.simulator.parser.TraceReader.KeyOnlyTraceReader; - -/** - * A reader for the trace files provided by the authors of the AdaptiveClimb algorithm. - * - * @author ben.manes@gmail.com (Ben Manes) - */ -public final class ClimbTraceReader extends TextTraceReader implements KeyOnlyTraceReader { - - public ClimbTraceReader(String filePath) { - super(filePath); - } - - @Override - public LongStream keys() { - TraceIterator iterator = new TraceIterator(readFile()); - return StreamSupport.longStream(Spliterators.spliteratorUnknownSize( - iterator, Spliterator.ORDERED), /* parallel */ false).onClose(iterator::close); - } - - private static final class TraceIterator implements PrimitiveIterator.OfLong { - private final Scanner scanner; - - TraceIterator(InputStream input) { - scanner = new Scanner(input, UTF_8.name()); - } - - @Override - public boolean hasNext() { - return scanner.hasNextLong(); - } - - @Override - public long nextLong() { - return scanner.nextLong(); - } - - public void close() { - scanner.close(); - } - } -} diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/CloudPhysicsTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/CloudPhysicsTraceReader.java new file mode 100644 index 0000000000..f0aac3a80e --- /dev/null +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/CloudPhysicsTraceReader.java @@ -0,0 +1,48 @@ +/* + * Copyright 2021 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.cloud_physics; + +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; +import com.google.common.collect.ImmutableSet; + +/** + * A reader for the trace files provided by the author of LIRS2. See + * traces. + * + * @author ben.manes@gmail.com (Ben Manes) + */ +public final class CloudPhysicsTraceReader extends BinaryTraceReader { + + public CloudPhysicsTraceReader(String filePath) { + super(filePath); + } + + @Override + public Set characteristics() { + return ImmutableSet.of(); + } + + @Override + protected AccessEvent readEvent(DataInputStream input) throws IOException { + return AccessEvent.forKey(Integer.toUnsignedLong(input.readInt())); + } +} diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/CloudPhysicsTraceWriter.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/CloudPhysicsTraceWriter.java new file mode 100644 index 0000000000..d074f4f825 --- /dev/null +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/CloudPhysicsTraceWriter.java @@ -0,0 +1,41 @@ +/* + * Copyright 2021 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.cloud_physics; + +import java.io.IOException; +import java.io.OutputStream; + +import com.github.benmanes.caffeine.cache.simulator.parser.BinaryTraceWriter; +import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent; +import com.google.common.hash.Hashing; + +/** + * A writer for the trace format used by the authors of the LIRS2 algorithm. + * + * @author ben.manes@gmail.com (Ben Manes) + */ +public final class CloudPhysicsTraceWriter extends BinaryTraceWriter { + + public CloudPhysicsTraceWriter(OutputStream output) { + super(output); + } + + @Override + public void writeEvent(int tick, AccessEvent event) throws IOException { + int key = Hashing.murmur3_128().hashLong(event.key()).asInt(); + writer().writeInt(key); + } +} diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/climb/ClimbTraceWriter.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/lirs/LirsTraceWriter.java similarity index 80% rename from simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/climb/ClimbTraceWriter.java rename to simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/lirs/LirsTraceWriter.java index 33bcd57b69..059f7e2196 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/climb/ClimbTraceWriter.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/lirs/LirsTraceWriter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.benmanes.caffeine.cache.simulator.parser.climb; +package com.github.benmanes.caffeine.cache.simulator.parser.lirs; import java.io.IOException; import java.io.OutputStream; @@ -22,13 +22,13 @@ import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent; /** - * A writer for the trace format used by the authors of the AdaptiveClimb simulator. + * A writer for the trace format used by the authors of the LIRS algorithm. * * @author ben.manes@gmail.com (Ben Manes) */ -public final class ClimbTraceWriter extends TextTraceWriter { +public final class LirsTraceWriter extends TextTraceWriter { - public ClimbTraceWriter(OutputStream output) { + public LirsTraceWriter(OutputStream output) { super(output); } diff --git a/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/w106.trace.xz b/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/w106.trace.xz new file mode 100755 index 0000000000..80ed76b183 Binary files /dev/null and b/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/cloud_physics/w106.trace.xz differ diff --git a/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/backf.trace.gz b/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/backf.trace.gz new file mode 100755 index 0000000000..9552814dc8 Binary files /dev/null and b/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/backf.trace.gz differ diff --git a/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/scan.trace.gz b/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/scan.trace.gz new file mode 100644 index 0000000000..2b29389cde Binary files /dev/null and b/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/scan.trace.gz differ diff --git a/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/zigzag.trace.gz b/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/zigzag.trace.gz new file mode 100644 index 0000000000..6d5f2a3d72 Binary files /dev/null and b/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/zigzag.trace.gz differ diff --git a/simulator/src/main/resources/reference.conf b/simulator/src/main/resources/reference.conf index 283aeee48c..dd594ef354 100644 --- a/simulator/src/main/resources/reference.conf +++ b/simulator/src/main/resources/reference.conf @@ -478,24 +478,24 @@ caffeine.simulator { # address: format of UCSD program address traces # address-penalties: format of UCSD program address traces with hit & miss penalties # cache2k: format from the author of the Cache2k library - # camelab: format from the Camelab storage traces - # climb: format from the authors of the AdaptiveClimb algorithm + # camelab: format of the Camelab storage traces + # cloud-physics: format of the Cloud Physics traces # corda: format of Corda traces # gradle: format from the authors of the Gradle build tool # lirs: format from the authors of the LIRS algorithm # lrb: format from the authors of the LRB algorithm - # outbrain: format from Outbrain trace provided on Kaggle + # outbrain: format of Outbrain's trace provided on Kaggle # scarab: format of Scarab Research traces - # snia-cambridge: format from the SNIA MSR Cambridge traces - # snia-k5cloud: format from the SNIA K5cloud traces - # snia-object-store: format from the SNIA IBM ObjectStore traces - # snia-systor: format from the SNIA SYSTOR '17 traces - # snia-tencent-block: format from the SNIA Tencent Block traces - # snia-tencent-photo: format from the SNIA Tencent Photo traces - # twitter: format from the Twitter Cache Cluster traces - # umass-storage: format from the University of Massachusetts storage traces - # umass-youtube: format from the University of Massachusetts youtube traces - # wikipedia: format from the WikiBench request traces + # snia-cambridge: format of the SNIA MSR Cambridge traces + # snia-k5cloud: format of the SNIA K5cloud traces + # snia-object-store: format of the SNIA IBM ObjectStore traces + # snia-systor: format of the SNIA SYSTOR '17 traces + # snia-tencent-block: format of the SNIA Tencent Block traces + # snia-tencent-photo: format of the SNIA Tencent Photo traces + # twitter: format of the Twitter Cache Cluster traces + # umass-storage: format of the University of Massachusetts storage traces + # umass-youtube: format of the University of Massachusetts youtube traces + # wikipedia: format of the WikiBench request traces format = lirs }