8334765: JFR: Log chunk waste
Reviewed-by: mgronlun
This commit is contained in:
parent
b2930c5aee
commit
55c7969461
src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/filter
test/jdk/jdk/jfr/jvm
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,6 +30,8 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import jdk.jfr.consumer.RecordedEvent;
|
||||
@ -56,6 +58,7 @@ public final class ChunkWriter implements Closeable {
|
||||
private final RecordingInput input;
|
||||
private final RecordingOutput output;
|
||||
private final Predicate<RecordedEvent> filter;
|
||||
private final Map<String, Long> waste = new HashMap<>();
|
||||
|
||||
private long chunkStartPosition;
|
||||
private boolean chunkComplete;
|
||||
@ -178,6 +181,16 @@ public final class ChunkWriter implements Closeable {
|
||||
pools = new LongMap<>();
|
||||
chunkComplete = true;
|
||||
lastCheckpoint = 0;
|
||||
if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.DEBUG)) {
|
||||
// Log largest waste first
|
||||
waste.entrySet().stream()
|
||||
.sorted((a, b) -> b.getValue().compareTo(a.getValue()))
|
||||
.forEach(entry -> {
|
||||
String msg = "Total chunk waste by " + entry.getKey() + ": " + entry.getValue() + " bytes.";
|
||||
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.DEBUG, msg);
|
||||
});
|
||||
}
|
||||
waste.clear();
|
||||
}
|
||||
|
||||
private void writeMetadataEvent(ChunkHeader header) throws IOException {
|
||||
@ -216,6 +229,20 @@ public final class ChunkWriter implements Closeable {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.DEBUG)) {
|
||||
for (CheckpointPool pool : event.getPools()) {
|
||||
for (PoolEntry pe : pool.getEntries()) {
|
||||
if (!pe.isTouched()) {
|
||||
String name = pe.getType().getName();
|
||||
long amount = pe.getEndPosition() - pe.getStartPosition();
|
||||
waste.merge(pe.getType().getName(), amount, Long::sum);
|
||||
String msg = "Unreferenced constant ID " + pe.getId() +
|
||||
" of type "+ name + " using " + amount + " bytes.";
|
||||
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
long endPosition = output.position();
|
||||
long size = endPosition - startPosition;
|
||||
output.position(startPosition);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -47,7 +47,7 @@ import jdk.jfr.Configuration;
|
||||
* @requires vm.hasJFR
|
||||
* @library /test/lib /test/jdk
|
||||
* @modules jdk.jfr/jdk.jfr.internal.test
|
||||
* @run main/othervm -XX:TLABSize=2k jdk.jfr.jvm.TestWaste
|
||||
* @run main/othervm -Xlog:jfr+system+parser=debug -XX:TLABSize=2k jdk.jfr.jvm.TestWaste
|
||||
*/
|
||||
public class TestWaste {
|
||||
static List<Object> list = new LinkedList<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user