1212
1313import java .time .Duration ;
1414import java .util .concurrent .TimeoutException ;
15+ import java .util .concurrent .atomic .AtomicLong ;
1516
1617@ Slf4j
1718public class StatsRecordingDataWriter implements RecordingDataWriter {
1819
1920 private final RecordingDataWriter delegate ;
20- private final BytesCounter typeBytes ;
21- private final BytesCounter methodBytes ;
22- private final BytesCounter callsBytes ;
23-
24- private final PerTypeStats totalBytesWritten = new PerTypeStats ("Total bytes written" );
21+ private final BytesCounter typeBytesWritten ;
22+ private final BytesCounter methodBytesWritten ;
23+ private final BytesCounter methodCallBytesWritten ;
24+ private final AtomicLong totalBytesWritten = new AtomicLong (0L );
2525
2626 public StatsRecordingDataWriter (Metrics metrics , RecordingDataWriter delegate ) {
2727 this .delegate = delegate ;
28- this .typeBytes = metrics .getOrCreateByteCounter ("writer.bytes.types" );
29- this .methodBytes = metrics .getOrCreateByteCounter ("writer.bytes.methods" );
30- this .callsBytes = metrics .getOrCreateByteCounter ("writer.bytes.calls" );
28+ this .typeBytesWritten = metrics .getOrCreateByteCounter ("writer.bytes.types" );
29+ this .methodBytesWritten = metrics .getOrCreateByteCounter ("writer.bytes.methods" );
30+ this .methodCallBytesWritten = metrics .getOrCreateByteCounter ("writer.bytes.calls" );
3131 }
3232
3333 @ Override
@@ -52,28 +52,28 @@ public void write(RecordingMetadata recordingMetadata) throws StorageException {
5252
5353 @ Override
5454 public void write (SerializedTypeList types ) throws StorageException {
55- totalBytesWritten .addBytes (types .byteLength ());
55+ totalBytesWritten .addAndGet (types .byteLength ());
5656 delegate .write (types );
57- typeBytes .add (types .byteLength (), types .size ());
57+ typeBytesWritten .add (types .byteLength (), types .size ());
5858 }
5959
6060 @ Override
6161 public void write (SerializedRecordedMethodCallList callRecords ) throws StorageException {
62- totalBytesWritten .addBytes (callRecords .bytesWritten ());
62+ totalBytesWritten .addAndGet (callRecords .bytesWritten ());
6363 delegate .write (callRecords );
64- callsBytes .add (callRecords .bytesWritten (), callRecords .size ());
64+ methodCallBytesWritten .add (callRecords .bytesWritten (), callRecords .size ());
6565 }
6666
6767 @ Override
6868 public long estimateBytesWritten () {
69- return totalBytesWritten .getTotalBytes ();
69+ return totalBytesWritten .get ();
7070 }
7171
7272 @ Override
7373 public void write (SerializedMethodList methods ) throws StorageException {
74- totalBytesWritten .addBytes (methods .byteLength ());
74+ totalBytesWritten .addAndGet (methods .byteLength ());
7575 delegate .write (methods );
76- methodBytes .add (methods .byteLength (), methods .size ());
76+ methodBytesWritten .add (methods .byteLength (), methods .size ());
7777 }
7878
7979 @ Override
0 commit comments