Java Code Examples for net.openhft.chronicle.core.Jvm#isDebug()

The following examples show how to use net.openhft.chronicle.core.Jvm#isDebug() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemoryLongColumn.java    From Chronicle-TimeSeries with GNU Lesser General Public License v3.0 5 votes vote down vote up
public InMemoryLongColumn(TimeSeries timeSeries, String name, BytesLongLookup lookup, long capacity) {
    super(timeSeries, name);
    this.lookup = lookup;
    long value = lookup.sizeFor(capacity);
    this.bytes = Jvm.isDebug()
            ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value)))
            : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value);
}
 
Example 2
Source File: InMemoryLongColumn.java    From Chronicle-TimeSeries with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void ensureCapacity(long capacity) {
    long cap = lookup.sizeFor(capacity);
    if (cap > bytes.realCapacity()) {
        long value = lookup.sizeFor(capacity);
        BytesStore bytes2 = Jvm.isDebug()
                ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value)))
                : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value);
        bytes2.write(0, bytes);
        bytes.release();
        bytes = bytes2;
    }
}
 
Example 3
Source File: NetworkLog.java    From Chronicle-Network with Apache License 2.0 5 votes vote down vote up
public void idle() {
    if (!Jvm.isDebug() || !LOG.isDebugEnabled()) return;
    long now = System.currentTimeMillis();
    if (now - lastOut > 2000) {
        lastOut = now;
        Jvm.debug().on(getClass(), desc + " idle");
    }
}
 
Example 4
Source File: TraceLock.java    From Chronicle-Network with Apache License 2.0 4 votes vote down vote up
@NotNull
public static ReentrantLock create() {
    return Jvm.isDebug() ? new TraceLock() : new ReentrantLock();
}
 
Example 5
Source File: NetworkLog.java    From Chronicle-Network with Apache License 2.0 4 votes vote down vote up
public void log(@NotNull ByteBuffer bytes, int start, int end) {
    if (!Jvm.isDebug() || !LOG.isDebugEnabled()) return;

    // avoid inlining this.
    log0(bytes, start, end);
}
 
Example 6
Source File: NetworkContext.java    From Chronicle-Network with Apache License 2.0 4 votes vote down vote up
@Nullable
default ConnectionListener acquireConnectionListener() {
    return Jvm.isDebug() ? ConnectionListeners.LOGGING : ConnectionListeners.NONE;
}
 
Example 7
Source File: RareAppenderLatencyTest.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@Test
public void testRareAppenderLatency() throws InterruptedException, ExecutionException {
    System.setProperty("ignoreHeaderCountIfNumberOfExcerptsBehindExceeds", "" + (1 << 12));

    if (Jvm.isDebug())
        // this is a performance test so should not be run in debug mode
        return;

    assert (isAssertionsOn = true);

    if (isAssertionsOn)
        // this is a performance test so should not be run with assertions turned on
        return;

    System.out.println("starting test");
    String pathname = OS.getTarget() + "/testRareAppenderLatency-" + System.nanoTime();
    new File(pathname).deleteOnExit();

    // Shared queue between two threads appending. One appends very rarely, another heavily.
    ChronicleQueue queue = SingleChronicleQueueBuilder.binary(pathname)
            .rollCycle(RollCycles.HOURLY)
            .build();

    String text = getText();

    // Write a some messages with an appender from Main thread.
    ExcerptAppender rareAppender = queue.acquireAppender();
    for (int i = 0; i < RARE_MSGS; i++) {
        try (DocumentContext ctx = rareAppender.writingDocument()) {
            ctx.wire()
                    .write(() -> "ts").int64(System.currentTimeMillis())
                    .write(() -> "msg").text(text);
        }
    }

    // Write a bunch of messages from another thread.
    Future f = appenderES.submit(() -> {
        ExcerptAppender appender = queue.acquireAppender();
        long start = System.currentTimeMillis();
        for (int i = 0; i < HEAVY_MSGS; i++) {
            try (DocumentContext ctx = appender.writingDocument()) {
                ctx.wire()
                        .write(() -> "ts").int64(System.currentTimeMillis())
                        .write(() -> "msg").text(text);
            }
            if (appenderES.isShutdown())
                return;
        }

        System.out.println("Wrote heavy " + HEAVY_MSGS + " msgs in " + (System.currentTimeMillis() - start) + " ms");
    });

    f.get();

    // Write a message from the Main thread again (this will have unacceptable latency!)
    rareAppender = queue.acquireAppender();
    long now = System.currentTimeMillis();
    try (DocumentContext ctx = rareAppender.writingDocument()) {
        ctx.wire()
                .write(() -> "ts").int64(System.currentTimeMillis())
                .write(() -> "msg").text(text);
    }
    long l = System.currentTimeMillis() - now;

    // Write another message from the Main thread (this will be fast since we are caught up)
    now = System.currentTimeMillis();
    try (DocumentContext ctx = rareAppender.writingDocument()) {
        ctx.wire()
                .write(() -> "ts").int64(System.currentTimeMillis())
                .write(() -> "msg").text(text);
    }
    System.out.println("Wrote first rare one in " + l + " ms");
    System.out.println("Wrote another rare one in " + (System.currentTimeMillis() - now) + " ms");

    assertFalse("Appending from rare thread latency too high!", l > 150);
}