-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simulator support for LIRS2's traces
- Loading branch information
Showing
17 changed files
with
172 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/BinaryTraceWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* A skeletal implementation that writes to the trace file as binary data. | ||
* | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public abstract class BinaryTraceWriter implements TraceWriter { | ||
private final DataOutputStream writer; | ||
|
||
protected BinaryTraceWriter(OutputStream output) { | ||
this.writer = new DataOutputStream(output); | ||
} | ||
|
||
protected DataOutputStream writer() { | ||
return writer; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
writer.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,11 @@ | |
|
||
import java.io.BufferedOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent; | ||
import com.google.common.base.Stopwatch; | ||
|
||
import picocli.CommandLine; | ||
|
@@ -38,7 +34,7 @@ | |
* into Java. | ||
* <p> | ||
* <pre>{@code | ||
* ./gradlew :simulator:rewrite \ | ||
* ./gradlew :simulator:rewrite -q \ | ||
* -PinputFormat=? \ | ||
* -PinputFiles=? \ | ||
* -PoutputFile=? \ | ||
|
@@ -47,11 +43,10 @@ | |
* | ||
* @author [email protected] (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 List<String> inputFiles = 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<String> 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<AccessEvent> 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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
...main/java/com/github/benmanes/caffeine/cache/simulator/parser/climb/ClimbTraceReader.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
...ithub/benmanes/caffeine/cache/simulator/parser/cloud_physics/CloudPhysicsTraceReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
* <a href="https://github.com/zhongch4g/LIRS2">traces</a>. | ||
* | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class CloudPhysicsTraceReader extends BinaryTraceReader { | ||
|
||
public CloudPhysicsTraceReader(String filePath) { | ||
super(filePath); | ||
} | ||
|
||
@Override | ||
public Set<Characteristic> characteristics() { | ||
return ImmutableSet.of(); | ||
} | ||
|
||
@Override | ||
protected AccessEvent readEvent(DataInputStream input) throws IOException { | ||
return AccessEvent.forKey(Integer.toUnsignedLong(input.readInt())); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ithub/benmanes/caffeine/cache/simulator/parser/cloud_physics/CloudPhysicsTraceWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] (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); | ||
} | ||
} |
Oops, something went wrong.