Search in sources :

Example 1 with LogBuffers

use of io.aeron.LogBuffers in project aeron by real-logic.

the class LogInspector method main.

public static void main(final String[] args) {
    final PrintStream out = System.out;
    if (args.length < 1) {
        out.println("Usage: LogInspector <logFileName> [dump limit in bytes per message]");
        return;
    }
    final String logFileName = args[0];
    final int messageDumpLimit = args.length >= 2 ? Integer.parseInt(args[1]) : Integer.MAX_VALUE;
    try (LogBuffers logBuffers = new LogBuffers(logFileName)) {
        out.println("======================================================================");
        out.format("%s Inspection dump for %s%n", new Date(), logFileName);
        out.println("======================================================================");
        final DataHeaderFlyweight dataHeaderFlyweight = new DataHeaderFlyweight();
        final UnsafeBuffer[] termBuffers = logBuffers.duplicateTermBuffers();
        final int termLength = logBuffers.termLength();
        final UnsafeBuffer metaDataBuffer = logBuffers.metaDataBuffer();
        final int initialTermId = initialTermId(metaDataBuffer);
        out.format("   Is Connected: %s%n", isConnected(metaDataBuffer));
        out.format("Initial term id: %d%n", initialTermId);
        out.format("     Term Count: %d%n", activeTermCount(metaDataBuffer));
        out.format("   Active index: %d%n", indexByTermCount(activeTermCount(metaDataBuffer)));
        out.format("    Term length: %d%n", termLength);
        out.format("     MTU length: %d%n", mtuLength(metaDataBuffer));
        out.format("      Page Size: %d%n", pageSize(metaDataBuffer));
        out.format("   EOS Position: %d%n%n", endOfStreamPosition(metaDataBuffer));
        if (!AERON_LOG_SKIP_DEFAULT_HEADER) {
            dataHeaderFlyweight.wrap(defaultFrameHeader(metaDataBuffer));
            out.format("default %s%n", dataHeaderFlyweight);
        }
        out.println();
        for (int i = 0; i < PARTITION_COUNT; i++) {
            final long rawTail = rawTailVolatile(metaDataBuffer, 0);
            final long termOffset = rawTail & 0xFFFF_FFFFL;
            final int termId = termId(rawTail);
            final int offset = (int) Math.min(termOffset, termLength);
            final int positionBitsToShift = LogBufferDescriptor.positionBitsToShift(termLength);
            out.format("Index %d Term Meta Data termOffset=%d termId=%d rawTail=%d position=%d%n", i, termOffset, termId, rawTail, LogBufferDescriptor.computePosition(termId, offset, positionBitsToShift, initialTermId));
        }
        for (int i = 0; i < PARTITION_COUNT; i++) {
            out.println();
            out.println("======================================================================");
            out.format("Index %d Term Data%n%n", i);
            final UnsafeBuffer termBuffer = termBuffers[i];
            int offset = 0;
            do {
                dataHeaderFlyweight.wrap(termBuffer, offset, termLength - offset);
                out.println(offset + ": " + dataHeaderFlyweight.toString());
                final int frameLength = dataHeaderFlyweight.frameLength();
                if (frameLength < DataHeaderFlyweight.HEADER_LENGTH) {
                    if (0 == frameLength && AERON_LOG_SCAN_OVER_ZEROES) {
                        offset += FrameDescriptor.FRAME_ALIGNMENT;
                        continue;
                    }
                    try {
                        final int limit = min(termLength - (offset + HEADER_LENGTH), messageDumpLimit);
                        out.println(formatBytes(termBuffer, offset + HEADER_LENGTH, limit));
                    } catch (final Exception ex) {
                        System.err.printf("frameLength=%d offset=%d%n", frameLength, offset);
                        ex.printStackTrace();
                    }
                    break;
                }
                final int limit = min(frameLength - HEADER_LENGTH, messageDumpLimit);
                out.println(formatBytes(termBuffer, offset + HEADER_LENGTH, limit));
                offset += BitUtil.align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
            } while (offset < termLength);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) LogBuffers(io.aeron.LogBuffers) Date(java.util.Date)

Example 2 with LogBuffers

use of io.aeron.LogBuffers in project Aeron by real-logic.

the class LogInspector method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
public static void main(final String[] args) {
    final PrintStream out = System.out;
    if (args.length < 1) {
        out.println("Usage: LogInspector <logFileName> [dump limit in bytes per message]");
        return;
    }
    final String logFileName = args[0];
    final int messageDumpLimit = args.length >= 2 ? Integer.parseInt(args[1]) : Integer.MAX_VALUE;
    try (LogBuffers logBuffers = new LogBuffers(logFileName)) {
        out.println("======================================================================");
        out.format("%s Inspection dump for %s%n", new Date(), logFileName);
        out.println("======================================================================");
        final DataHeaderFlyweight dataHeaderFlyweight = new DataHeaderFlyweight();
        final UnsafeBuffer[] termBuffers = logBuffers.duplicateTermBuffers();
        final int termLength = logBuffers.termLength();
        final UnsafeBuffer metaDataBuffer = logBuffers.metaDataBuffer();
        final int initialTermId = initialTermId(metaDataBuffer);
        out.format("   Is Connected: %s%n", isConnected(metaDataBuffer));
        out.format("Initial term id: %d%n", initialTermId);
        out.format("     Term Count: %d%n", activeTermCount(metaDataBuffer));
        out.format("   Active index: %d%n", indexByTermCount(activeTermCount(metaDataBuffer)));
        out.format("    Term length: %d%n", termLength);
        out.format("     MTU length: %d%n", mtuLength(metaDataBuffer));
        out.format("      Page Size: %d%n", pageSize(metaDataBuffer));
        out.format("   EOS Position: %d%n%n", endOfStreamPosition(metaDataBuffer));
        if (!AERON_LOG_SKIP_DEFAULT_HEADER) {
            dataHeaderFlyweight.wrap(defaultFrameHeader(metaDataBuffer));
            out.format("default %s%n", dataHeaderFlyweight);
        }
        out.println();
        for (int i = 0; i < PARTITION_COUNT; i++) {
            final long rawTail = rawTailVolatile(metaDataBuffer, i);
            final long termOffset = rawTail & 0xFFFF_FFFFL;
            final int termId = termId(rawTail);
            final int offset = (int) Math.min(termOffset, termLength);
            final int positionBitsToShift = LogBufferDescriptor.positionBitsToShift(termLength);
            out.format("Index %d Term Meta Data termOffset=%d termId=%d rawTail=%d position=%d%n", i, termOffset, termId, rawTail, LogBufferDescriptor.computePosition(termId, offset, positionBitsToShift, initialTermId));
        }
        for (int i = 0; i < PARTITION_COUNT; i++) {
            out.println();
            out.println("======================================================================");
            out.format("Index %d Term Data%n%n", i);
            final UnsafeBuffer termBuffer = termBuffers[i];
            int offset = 0;
            do {
                dataHeaderFlyweight.wrap(termBuffer, offset, termLength - offset);
                out.println(offset + ": " + dataHeaderFlyweight);
                final int frameLength = dataHeaderFlyweight.frameLength();
                if (frameLength < DataHeaderFlyweight.HEADER_LENGTH) {
                    if (0 == frameLength && AERON_LOG_SCAN_OVER_ZEROES) {
                        offset += FrameDescriptor.FRAME_ALIGNMENT;
                        continue;
                    }
                    try {
                        final int limit = min(termLength - (offset + HEADER_LENGTH), messageDumpLimit);
                        out.println(formatBytes(termBuffer, offset + HEADER_LENGTH, limit));
                    } catch (final Exception ex) {
                        System.err.printf("frameLength=%d offset=%d%n", frameLength, offset);
                        ex.printStackTrace();
                    }
                    break;
                }
                final int limit = min(frameLength - HEADER_LENGTH, messageDumpLimit);
                out.println(formatBytes(termBuffer, offset + HEADER_LENGTH, limit));
                offset += BitUtil.align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
            } while (offset < termLength);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) LogBuffers(io.aeron.LogBuffers) Date(java.util.Date)

Example 3 with LogBuffers

use of io.aeron.LogBuffers in project nd4j by deeplearning4j.

the class LogInspector method main.

public static void main(final String[] args) throws Exception {
    final PrintStream out = System.out;
    if (args.length < 1) {
        out.println("Usage: LogInspector <logFileName> [message dump limit]");
        return;
    }
    final String logFileName = args[0];
    final int messageDumpLimit = args.length >= 2 ? Integer.parseInt(args[1]) : Integer.MAX_VALUE;
    try (LogBuffers logBuffers = new LogBuffers(logFileName, READ_ONLY)) {
        out.println("======================================================================");
        out.format("%s Inspection dump for %s%n", new Date(), logFileName);
        out.println("======================================================================");
        final DataHeaderFlyweight dataHeaderFlyweight = new DataHeaderFlyweight();
        final UnsafeBuffer[] termBuffers = logBuffers.termBuffers();
        final int termLength = logBuffers.termLength();
        final UnsafeBuffer metaDataBuffer = logBuffers.metaDataBuffer();
        out.format("Time of last SM: %s%n", new Date(timeOfLastStatusMessage(metaDataBuffer)));
        out.format("Initial term id: %d%n", initialTermId(metaDataBuffer));
        out.format("   Active index: %d%n", activePartitionIndex(metaDataBuffer));
        out.format("    Term length: %d%n", termLength);
        out.format("     MTU length: %d%n%n", mtuLength(metaDataBuffer));
        if (!SKIP_DEFAULT_HEADER) {
            dataHeaderFlyweight.wrap(defaultFrameHeader(metaDataBuffer));
            out.format("default %s%n", dataHeaderFlyweight);
        }
        out.println();
        for (int i = 0; i < PARTITION_COUNT; i++) {
            final long rawTail = rawTailVolatile(metaDataBuffer, 0);
            final long termOffset = rawTail & 0xFFFF_FFFFL;
            out.format("Index %d Term Meta Data termOffset=%d termId=%d rawTail=%d%n", i, termOffset, termId(rawTail), rawTail);
        }
        for (int i = 0; i < PARTITION_COUNT; i++) {
            out.println("%n======================================================================");
            out.format("Index %d Term Data%n%n", i);
            final UnsafeBuffer termBuffer = termBuffers[i];
            int offset = 0;
            do {
                dataHeaderFlyweight.wrap(termBuffer, offset, termLength - offset);
                out.println(offset + ": " + dataHeaderFlyweight.toString());
                final int frameLength = dataHeaderFlyweight.frameLength();
                if (frameLength < DataHeaderFlyweight.HEADER_LENGTH) {
                    if (0 == frameLength && SCAN_OVER_ZEROES) {
                        offset += FrameDescriptor.FRAME_ALIGNMENT;
                        continue;
                    }
                    try {
                        final int limit = min(termLength - (offset + HEADER_LENGTH), messageDumpLimit);
                        out.println(formatBytes(termBuffer, offset + HEADER_LENGTH, limit));
                    } catch (final Exception ex) {
                        System.out.printf("frameLength=%d offset=%d%n", frameLength, offset);
                        ex.printStackTrace();
                    }
                    break;
                }
                final int limit = min(frameLength - HEADER_LENGTH, messageDumpLimit);
                out.println(formatBytes(termBuffer, offset + HEADER_LENGTH, limit));
                offset += BitUtil.align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
            } while (offset < termLength);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) LogBuffers(io.aeron.LogBuffers) Date(java.util.Date)

Aggregations

LogBuffers (io.aeron.LogBuffers)3 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)3 PrintStream (java.io.PrintStream)3 Date (java.util.Date)3 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)3