@Test (timeout = 3000) public void microBenchmark() throws Exception { String prefix = temp.newFolder("test4-benchmark").getAbsolutePath(); Slot slot = new Slot(prefix, (100 * 1024 * 1024)); Timber.LogEvent event = makeLogEvent(0); int numMessages = 100000; long start = System.currentTimeMillis(); for (int i = 0; i < numMessages; i++) { slot.write(event); } long duration = System.currentTimeMillis() - start; long rate = (numMessages * 1000) / duration; log.info("Slot microbenchmark: "+ numMessages + " in " + duration + " ms," + " rate = " + rate + " msg/sec"); }
public WriteReport write(final Timber.LogEvent event) throws IOException { if (null == currentWriter) { if (closed) { throw new IllegalStateException("Slot was closed"); } currentFile = findNextSlotFile(); numBytesInFile = currentFile.length(); currentWriter = new RecordWriter( new BufferedOutputStream( new FileOutputStream(currentFile, true), outputBufferSize)); writeCount = 0; } final long startOffset = numBytesInFile; numBytesInFile += currentWriter.write(event); writeCount++; final WriteReport ret = new WriteReport(currentFile, startOffset, numBytesInFile, writeCount); if (numBytesInFile > maxSize) { closeInternal(); } return ret; }
Slot { public WriteReport write(final Timber.LogEvent event) throws IOException { if (null == currentWriter) { if (closed) { throw new IllegalStateException("Slot was closed"); } currentFile = findNextSlotFile(); numBytesInFile = currentFile.length(); currentWriter = new RecordWriter( new BufferedOutputStream( new FileOutputStream(currentFile, true), outputBufferSize)); writeCount = 0; } final long startOffset = numBytesInFile; numBytesInFile += currentWriter.write(event); writeCount++; final WriteReport ret = new WriteReport(currentFile, startOffset, numBytesInFile, writeCount); if (numBytesInFile > maxSize) { closeInternal(); } return ret; } }
Slot { public WriteReport write(final Timber.LogEvent event) throws IOException { if (null == currentWriter) { if (closed) { throw new IllegalStateException("Slot was closed"); } currentFile = findNextSlotFile(); numBytesInFile = currentFile.length(); currentWriter = new RecordWriter( new BufferedOutputStream( new FileOutputStream(currentFile, true), outputBufferSize)); writeCount = 0; } final long startOffset = numBytesInFile; numBytesInFile += currentWriter.write(event); writeCount++; final WriteReport ret = new WriteReport(currentFile, startOffset, numBytesInFile, writeCount); if (numBytesInFile > maxSize) { closeInternal(); } return ret; } Slot(final String prefix, final long maxSize);  Slot(final String prefix, final long maxSize, final TimeProvider timeProvider); }
Slot { public WriteReport write(final Timber.LogEvent event) throws IOException { if (null == currentWriter) { if (closed) { throw new IllegalStateException("Slot was closed"); } currentFile = findNextSlotFile(); numBytesInFile = currentFile.length(); currentWriter = new RecordWriter( new BufferedOutputStream( new FileOutputStream(currentFile, true), outputBufferSize)); writeCount = 0; } final long startOffset = numBytesInFile; numBytesInFile += currentWriter.write(event); writeCount++; final WriteReport ret = new WriteReport(currentFile, startOffset, numBytesInFile, writeCount); if (numBytesInFile > maxSize) { closeInternal(); } return ret; } Slot(final String prefix, final long maxSize);  Slot(final String prefix, final long maxSize, final TimeProvider timeProvider); WriteReport write(final Timber.LogEvent event); long getNumBytesInFile(); String getCurrentSlotFileName(); void flush(); void close(); String toString(); }
Slot { public WriteReport write(final Timber.LogEvent event) throws IOException { if (null == currentWriter) { if (closed) { throw new IllegalStateException("Slot was closed"); } currentFile = findNextSlotFile(); numBytesInFile = currentFile.length(); currentWriter = new RecordWriter( new BufferedOutputStream( new FileOutputStream(currentFile, true), outputBufferSize)); writeCount = 0; } final long startOffset = numBytesInFile; numBytesInFile += currentWriter.write(event); writeCount++; final WriteReport ret = new WriteReport(currentFile, startOffset, numBytesInFile, writeCount); if (numBytesInFile > maxSize) { closeInternal(); } return ret; } Slot(final String prefix, final long maxSize);  Slot(final String prefix, final long maxSize, final TimeProvider timeProvider); WriteReport write(final Timber.LogEvent event); long getNumBytesInFile(); String getCurrentSlotFileName(); void flush(); void close(); String toString();  }