|
| 1 | +/* |
| 2 | + * Copyright 2020 Ben Manes. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.github.benmanes.caffeine.cache.simulator.parser.camelab; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | +import java.util.stream.LongStream; |
| 20 | + |
| 21 | +import com.github.benmanes.caffeine.cache.simulator.parser.TextTraceReader; |
| 22 | +import com.github.benmanes.caffeine.cache.simulator.parser.TraceReader.KeyOnlyTraceReader; |
| 23 | + |
| 24 | +/** |
| 25 | + * A reader for the trace files provided by |
| 26 | + * <a href="https://trace.camelab.org/2016/03/01/flash.html">Camelab</a>. |
| 27 | + * |
| 28 | + * @author ben.manes@gmail.com (Ben Manes) |
| 29 | + */ |
| 30 | +public final class CamelabTraceReader extends TextTraceReader implements KeyOnlyTraceReader { |
| 31 | + static final int BLOCK_SIZE = 512; |
| 32 | + |
| 33 | + public CamelabTraceReader(String filePath) { |
| 34 | + super(filePath); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public LongStream keys() throws IOException { |
| 39 | + return lines().flatMapToLong(line -> { |
| 40 | + String[] array = line.split(" ", 5); |
| 41 | + char readWrite = Character.toLowerCase(array[1].charAt(0)); |
| 42 | + if (readWrite == 'w') { |
| 43 | + return LongStream.empty(); |
| 44 | + } |
| 45 | + |
| 46 | + long startAddress = Long.parseLong(array[2]); |
| 47 | + int requestSize = Integer.parseInt(array[3]); |
| 48 | + long[] blocks = new long[requestSize]; |
| 49 | + for (int i = 0; i < requestSize; i++) { |
| 50 | + blocks[i] = startAddress + (i * BLOCK_SIZE); |
| 51 | + } |
| 52 | + return LongStream.of(blocks); |
| 53 | + }); |
| 54 | + } |
| 55 | +} |
0 commit comments