Search in sources :

Example 1 with IOMonitor

use of org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor in project jackrabbit-oak by apache.

the class IOTracerRunner method collectDepthFirstTrace.

public void collectDepthFirstTrace(@Nonnull String segmentStore, boolean mmap, int segmentCacheSize, @Nonnull String path, int depth, @Nonnull String output) throws IOException, InvalidFileStoreVersionException {
    checkNotNull(segmentStore);
    checkNotNull(path);
    checkNotNull(output);
    try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(output, true)))) {
        Function<IOMonitor, FileStore> factory = ioMonitor -> newFileStore(fileStoreBuilder(new File(segmentStore)).withMemoryMapping(mmap).withSegmentCacheSize(segmentCacheSize).withIOMonitor(ioMonitor));
        IOTracer ioTracer = newIOTracer(factory, out, DepthFirstTrace.CONTEXT_SPEC);
        ioTracer.collectTrace(new DepthFirstTrace(depth, path, ioTracer::setContext));
    }
}
Also used : PrintWriter(java.io.PrintWriter) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) IOMonitorAdapter(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter) BufferedWriter(java.io.BufferedWriter) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FileWriter(java.io.FileWriter) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) IOException(java.io.IOException) Test(org.junit.Test) FileStoreBuilder.fileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder) Function(java.util.function.Function) String.format(java.lang.String.format) File(java.io.File) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) System.getProperty(java.lang.System.getProperty) Integer.getInteger(java.lang.Integer.getInteger) Assume.assumeTrue(org.junit.Assume.assumeTrue) Nonnull(javax.annotation.Nonnull) Before(org.junit.Before) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) FileWriter(java.io.FileWriter) IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) File(java.io.File) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 2 with IOMonitor

use of org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor in project jackrabbit-oak by apache.

the class IOTracerRunner method collectBreadthFirstTrace.

public void collectBreadthFirstTrace(@Nonnull String segmentStore, boolean mmap, int segmentCacheSize, @Nonnull String path, int depth, @Nonnull String output) throws IOException, InvalidFileStoreVersionException {
    checkNotNull(segmentStore);
    checkNotNull(path);
    checkNotNull(output);
    try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(output, true)))) {
        Function<IOMonitor, FileStore> factory = ioMonitor -> newFileStore(fileStoreBuilder(new File(segmentStore)).withMemoryMapping(mmap).withSegmentCacheSize(segmentCacheSize).withIOMonitor(ioMonitor));
        IOTracer ioTracer = newIOTracer(factory, out, BreadthFirstTrace.CONTEXT_SPEC);
        ioTracer.collectTrace(new BreadthFirstTrace(depth, path, ioTracer::setContext));
    }
}
Also used : PrintWriter(java.io.PrintWriter) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) IOMonitorAdapter(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter) BufferedWriter(java.io.BufferedWriter) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FileWriter(java.io.FileWriter) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) IOException(java.io.IOException) Test(org.junit.Test) FileStoreBuilder.fileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder) Function(java.util.function.Function) String.format(java.lang.String.format) File(java.io.File) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) System.getProperty(java.lang.System.getProperty) Integer.getInteger(java.lang.Integer.getInteger) Assume.assumeTrue(org.junit.Assume.assumeTrue) Nonnull(javax.annotation.Nonnull) Before(org.junit.Before) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) FileWriter(java.io.FileWriter) IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) File(java.io.File) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 3 with IOMonitor

use of org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor in project jackrabbit-oak by apache.

the class IOTracerTest method collectDepthFirstTrace.

@Test
public void collectDepthFirstTrace() throws IOException, InvalidFileStoreVersionException {
    try (StringWriter out = new StringWriter()) {
        Function<IOMonitor, FileStore> factory = this::createFileStore;
        IOTracer ioTracer = newIOTracer(factory, out, DepthFirstTrace.CONTEXT_SPEC);
        ioTracer.collectTrace(new DepthFirstTrace(2, "/", ioTracer::setContext));
        try (BufferedReader reader = new BufferedReader(new StringReader(out.toString()))) {
            Optional<String> header = reader.lines().findFirst();
            List<String[]> entries = reader.lines().map(line -> line.split(",")).collect(toList());
            assertTrue(header.isPresent());
            assertEquals("timestamp,file,segmentId,length,elapsed,depth,count,path", header.get());
            long now = currentTimeMillis();
            assertTrue("The timestamps of all entries must be in the past", entries.stream().map(// ts
            row -> parseLong(row[0])).allMatch(ts -> ts <= now));
            assertEquals("Expected depths 0 and 1", ImmutableSet.of(0, 1), entries.stream().map(// depth
            row -> parseInt(row[5])).distinct().collect(toSet()));
            assertEquals("Expected max 10 nodes", Optional.of(true), entries.stream().map(// count
            row -> parseInt(row[6])).max(Comparator.naturalOrder()).map(max -> max <= 10));
        }
    }
}
Also used : IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) IOMonitorAdapter(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter) System.currentTimeMillis(java.lang.System.currentTimeMillis) FileStoreBuilder.fileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder) Function(java.util.function.Function) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Nonnull(javax.annotation.Nonnull) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) ImmutableSet(com.google.common.collect.ImmutableSet) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) StringWriter(java.io.StringWriter) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Integer.parseInt(java.lang.Integer.parseInt) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Rule(org.junit.Rule) StringReader(java.io.StringReader) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Long.parseLong(java.lang.Long.parseLong) Comparator(java.util.Comparator) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) Test(org.junit.Test)

Example 4 with IOMonitor

use of org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor in project jackrabbit-oak by apache.

the class IOTracerTest method collectBreadthFirstTrace.

@Test
public void collectBreadthFirstTrace() throws IOException, InvalidFileStoreVersionException {
    try (StringWriter out = new StringWriter()) {
        Function<IOMonitor, FileStore> factory = this::createFileStore;
        IOTracer ioTracer = newIOTracer(factory, out, BreadthFirstTrace.CONTEXT_SPEC);
        ioTracer.collectTrace(new BreadthFirstTrace(2, "/", ioTracer::setContext));
        try (BufferedReader reader = new BufferedReader(new StringReader(out.toString()))) {
            Optional<String> header = reader.lines().findFirst();
            List<String[]> entries = reader.lines().map(line -> line.split(",")).collect(toList());
            assertTrue(header.isPresent());
            assertEquals("timestamp,file,segmentId,length,elapsed,depth,count", header.get());
            long now = currentTimeMillis();
            assertTrue("The timestamps of all entries must be in the past", entries.stream().map(// ts
            row -> parseLong(row[0])).allMatch(ts -> ts <= now));
            assertEquals("Expected depths 0, 1 and 2", ImmutableSet.of(0, 1, 2), entries.stream().map(// depth
            row -> parseInt(row[5])).distinct().collect(toSet()));
            assertEquals("Expected max 10 nodes", Optional.of(true), entries.stream().map(// count
            row -> parseInt(row[6])).max(Comparator.naturalOrder()).map(max -> max <= 10));
        }
    }
}
Also used : IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) IOMonitorAdapter(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter) System.currentTimeMillis(java.lang.System.currentTimeMillis) FileStoreBuilder.fileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder) Function(java.util.function.Function) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Nonnull(javax.annotation.Nonnull) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) ImmutableSet(com.google.common.collect.ImmutableSet) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) StringWriter(java.io.StringWriter) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Integer.parseInt(java.lang.Integer.parseInt) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Rule(org.junit.Rule) StringReader(java.io.StringReader) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Long.parseLong(java.lang.Long.parseLong) Comparator(java.util.Comparator) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) Test(org.junit.Test)

Aggregations

File (java.io.File)4 IOException (java.io.IOException)4 Function (java.util.function.Function)4 Nonnull (javax.annotation.Nonnull)4 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 FileStoreBuilder.fileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder)4 InvalidFileStoreVersionException (org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException)4 IOMonitor (org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor)4 IOMonitorAdapter (org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter)4 IOTracer.newIOTracer (org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer)4 Before (org.junit.Before)4 Test (org.junit.Test)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 StringReader (java.io.StringReader)2