From 0670fce0ae9c103974ae3da70b0d19b70ef91c1f Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Wed, 22 Mar 2023 15:36:28 -0700 Subject: [PATCH] add cachelib traces to the simulator --- .github/actions/run-gradle/action.yml | 2 +- .../examples/hibernate/Repository.java | 2 +- .../hibernate/HibernateCacheTest.java | 2 +- gradle/dependencies.gradle | 4 +- .../cache/simulator/parser/TraceFormat.java | 2 + .../parser/cachelib/CachelibTraceReader.java | 52 +++++++++++++++++++ .../parser/cachelib/package-info.java | 4 ++ simulator/src/main/resources/reference.conf | 1 + 8 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cachelib/CachelibTraceReader.java create mode 100644 simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cachelib/package-info.java diff --git a/.github/actions/run-gradle/action.yml b/.github/actions/run-gradle/action.yml index e929020eee..e638f8e565 100644 --- a/.github/actions/run-gradle/action.yml +++ b/.github/actions/run-gradle/action.yml @@ -47,7 +47,7 @@ runs: version: 'latest' components: 'native-image' github-token: ${{ inputs.token }} - java-version: ${{ env.JAVA_VERSION }} + java-version: '${{ env.JAVA_VERSION }}' - name: Prepare JDK ${{ inputs.java }} shell: bash run: | diff --git a/examples/hibernate/src/main/java/com/github/benmanes/caffeine/examples/hibernate/Repository.java b/examples/hibernate/src/main/java/com/github/benmanes/caffeine/examples/hibernate/Repository.java index ebca68f4a5..629d70ff30 100644 --- a/examples/hibernate/src/main/java/com/github/benmanes/caffeine/examples/hibernate/Repository.java +++ b/examples/hibernate/src/main/java/com/github/benmanes/caffeine/examples/hibernate/Repository.java @@ -67,7 +67,7 @@ public void updateProject(long id, String name) { } } - public void persist(Project project, User user, Skill skill) { + public void persist(User user, Project project, Skill skill) { try (var session = sessionFactory.openSession()) { var txn = session.beginTransaction(); session.persist(project); diff --git a/examples/hibernate/src/test/java/com/github/benmanes/caffeine/examples/hibernate/HibernateCacheTest.java b/examples/hibernate/src/test/java/com/github/benmanes/caffeine/examples/hibernate/HibernateCacheTest.java index 23f0849c98..6ec67a8770 100644 --- a/examples/hibernate/src/test/java/com/github/benmanes/caffeine/examples/hibernate/HibernateCacheTest.java +++ b/examples/hibernate/src/test/java/com/github/benmanes/caffeine/examples/hibernate/HibernateCacheTest.java @@ -137,7 +137,7 @@ private long createData(String userName, String projectName, String skillName) { skill.setName(skillName); - repository.persist(project, user, skill); + repository.persist(user, project, skill); return project.getId(); } } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 7267208d6d..3ae4580d3d 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -29,7 +29,7 @@ ext { cache2k: '2.6.1.Final', checkerFramework: '3.32.0', coherence: '22.06.2', - commonsCompress: '1.22', + commonsCompress: '1.23.0', commonsLang3: '3.12.0', commonsMath3: '3.6.1', commonsIo: '2.11.0', @@ -92,7 +92,7 @@ ext { bnd: '6.4.0', checkstyle: '10.9.2', coveralls: '2.12.2', - dependencyCheck: '8.1.2', + dependencyCheck: '8.2.0', errorprone: '3.0.1', findsecbugs: '1.12.0', forbiddenApis: '3.4', 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 26e0546bc7..cf41cc285c 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 @@ -28,6 +28,7 @@ import com.github.benmanes.caffeine.cache.simulator.parser.address.penalties.AddressPenaltiesTraceReader; 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.cachelib.CachelibTraceReader; 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; @@ -67,6 +68,7 @@ public enum TraceFormat { ADAPT_SIZE(AdaptSizeTraceReader::new), ARC(ArcTraceReader::new), CACHE2K(Cache2kTraceReader::new), + CACHELIB(CachelibTraceReader::new), CAMELAB(CamelabTraceReader::new), CLOUD_PHYSICS(CloudPhysicsTraceReader::new), CORDA(CordaTraceReader::new), diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cachelib/CachelibTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cachelib/CachelibTraceReader.java new file mode 100644 index 0000000000..b25fc749cc --- /dev/null +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cachelib/CachelibTraceReader.java @@ -0,0 +1,52 @@ +/* + * 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.cachelib; + +import static com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic.WEIGHTED; + +import java.util.Set; +import java.util.stream.Stream; + +import com.github.benmanes.caffeine.cache.simulator.parser.TextTraceReader; +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 authors of cachelib. See + * traces. + * + * @author ben.manes@gmail.com (Ben Manes) + */ +public final class CachelibTraceReader extends TextTraceReader { + + public CachelibTraceReader(String filePath) { + super(filePath); + } + + @Override + public Set characteristics() { + return Set.of(WEIGHTED); + } + + @Override + public Stream events() { + return lines().skip(1) + .map(line -> line.split(",")) + .filter(array -> array[1].equals("GET")) + .map(array -> AccessEvent.forKeyAndWeight( + Long.parseLong(array[0]), Integer.parseInt(array[1]))); + } +} diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cachelib/package-info.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cachelib/package-info.java new file mode 100644 index 0000000000..2b48c98a10 --- /dev/null +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/cachelib/package-info.java @@ -0,0 +1,4 @@ +@CheckReturnValue +package com.github.benmanes.caffeine.cache.simulator.parser.cachelib; + +import com.google.errorprone.annotations.CheckReturnValue; diff --git a/simulator/src/main/resources/reference.conf b/simulator/src/main/resources/reference.conf index d63de9dc9a..b807d0fa06 100644 --- a/simulator/src/main/resources/reference.conf +++ b/simulator/src/main/resources/reference.conf @@ -484,6 +484,7 @@ 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 + # cachelib: format from the author of the Cachelib library # camelab: format of the Camelab storage traces # cloud-physics: format of the Cloud Physics traces # corda: format of Corda traces