Skip to content

Commit d96d23b

Browse files
committed
Log bytes written to disk when client app shuts down
1 parent 8af391e commit d96d23b

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

ulyp-agent-core/src/main/java/com/ulyp/agent/AgentShutdownHook.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ulyp.agent;
22

33
import com.ulyp.agent.queue.RecordingEventQueue;
4+
import com.ulyp.core.util.ByteSize;
45
import com.ulyp.storage.writer.RecordingDataWriter;
56
import lombok.extern.slf4j.Slf4j;
67

@@ -17,6 +18,8 @@ public void run() {
1718
return;
1819
}
1920

21+
log.info("Shutting down the agent conext. Will wait for recording data to be flushed to disk...");
22+
2023
RecordingEventQueue recordingEventQueue = ctx.getRecordingEventQueue();
2124
try {
2225
recordingEventQueue.sync(Duration.ofSeconds(30));
@@ -35,6 +38,8 @@ public void run() {
3538
} catch (TimeoutException e) {
3639
// ignore
3740
}
41+
long totalBytesWritten = storageWriter.estimateBytesWritten();
42+
log.info("Total bytes written to file: {}", ByteSize.toHumanReadable(totalBytesWritten));
3843
storageWriter.close();
3944
}
4045
}

ulyp-storage/src/main/java/com/ulyp/storage/writer/PerTypeStats.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ public void reset() {
1818

1919
}
2020

21-
public long getTotalCount() {
22-
return totalCount.get();
23-
}
24-
25-
public void addToCount(long delta) {
26-
totalCount.addAndGet(delta);
27-
}
28-
2921
public long getTotalBytes() {
3022
return totalBytes.getByteSize();
3123
}

ulyp-storage/src/main/java/com/ulyp/storage/writer/StatsRecordingDataWriter.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212

1313
import java.time.Duration;
1414
import java.util.concurrent.TimeoutException;
15+
import java.util.concurrent.atomic.AtomicLong;
1516

1617
@Slf4j
1718
public 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

Comments
 (0)