Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-JFR: Add new JFR Events: FileReadIOStatisticsEvent, FileWriteIOStatisticsEvent #10

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public final class EventConfigurations {
public static final EventConfiguration SOCKET_READ = JVMSupport.getConfiguration(SocketReadEvent.class);
public static final EventConfiguration SOCKET_WRITE = JVMSupport.getConfiguration(SocketWriteEvent.class);
public static final EventConfiguration FILE_READ = JVMSupport.getConfiguration(FileReadEvent.class);
public static final EventConfiguration FILE_WRITE_IO_STATISTICS = JVMSupport.getConfiguration(FileWriteIOStatisticsEvent.class);
public static final EventConfiguration FILE_READ_IO_STATISTICS = JVMSupport.getConfiguration(FileReadIOStatisticsEvent.class);
public static final EventConfiguration FILE_WRITE = JVMSupport.getConfiguration(FileWriteEvent.class);
public static final EventConfiguration FILE_FORCE = JVMSupport.getConfiguration(FileForceEvent.class);
public static final EventConfiguration ERROR_THROWN = JVMSupport.getConfiguration(ErrorThrownEvent.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.jfr.events;

import jdk.jfr.Category;
import jdk.jfr.Description;
import jdk.jfr.Label;
import jdk.jfr.Name;
import jdk.jfr.StackTrace;
import jdk.jfr.internal.Type;
import java.util.concurrent.atomic.AtomicLong;

@Name(Type.EVENT_NAME_PREFIX + "FileReadIOStatistics")
@Label("FileReadIO Statistics")
@Category({ "Java Application", "Statistics" })
@Description("Read Rate from the FileInputStream, FileChannelImpl, RandomAccessFile")
@StackTrace(false)
public final class FileReadIOStatisticsEvent extends AbstractJDKEvent {

@Label("Read Rate (Bytes per Sec)")
public long readRate;

@Label("Total Accumulated Read Bytes")
public long accRead;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.jfr.events;

import jdk.jfr.Category;
import jdk.jfr.Description;
import jdk.jfr.Label;
import jdk.jfr.Name;
import jdk.jfr.StackTrace;
import jdk.jfr.internal.Type;
import java.util.concurrent.atomic.AtomicLong;

@Name(Type.EVENT_NAME_PREFIX + "FileWriteIOStatistics")
@Label("FileWriteIO Statistics")
@Category({ "Java Application", "Statistics" })
@Description("Write Rate from the FileOutputStream, FileChannelImpl, RandomAccessFile")
@StackTrace(false)
public final class FileWriteIOStatisticsEvent extends AbstractJDKEvent {

@Label("Write Rate (Bytes per Sec)")
public long writeRate;

@Label("Total Accumulated Write Bytes")
public long accWrite;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, 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
Expand Down Expand Up @@ -66,137 +66,167 @@ public void force(boolean metaData) throws IOException {

@JIInstrumentationMethod
public int read(ByteBuffer dst) throws IOException {
EventConfiguration eventConfiguration = EventConfigurations.FILE_READ;
if (!eventConfiguration.isEnabled()) {
macarte marked this conversation as resolved.
Show resolved Hide resolved
EventConfiguration fileReadEventConfiguration = EventConfigurations.FILE_READ;
EventConfiguration fileReadIOStatisticsEventConfiguration = EventConfigurations.FILE_READ_IO_STATISTICS;
if (!fileReadEventConfiguration.isEnabled() && !fileReadIOStatisticsEventConfiguration.isEnabled()) {
return read(dst);
}
macarte marked this conversation as resolved.
Show resolved Hide resolved
int bytesRead = 0;
long start = 0;
long duration = 0;
try {
start = EventConfiguration.timestamp();
bytesRead = read(dst);
} finally {
long duration = EventConfiguration.timestamp() - start;
if (eventConfiguration.shouldCommit(duration)) {
duration = EventConfiguration.timestamp() - start;
if (fileReadEventConfiguration.shouldCommit(duration)) {
if (bytesRead < 0) {
FileReadEvent.commit(start, duration, path, 0L, true);
} else {
FileReadEvent.commit(start, duration, path, bytesRead, false);
}
}
}
if(fileReadIOStatisticsEventConfiguration.isEnabled()){
FileIOStatistics.addTotalReadBytesForPeriod(((bytesRead < 0) ? 0 : bytesRead), duration);
}
return bytesRead;
}

@JIInstrumentationMethod
public int read(ByteBuffer dst, long position) throws IOException {
EventConfiguration eventConfiguration = EventConfigurations.FILE_READ;
if (!eventConfiguration.isEnabled()) {
EventConfiguration fileReadEventConfiguration = EventConfigurations.FILE_READ;
EventConfiguration fileReadIOStatisticsEventConfiguration = EventConfigurations.FILE_READ_IO_STATISTICS;
if (!fileReadEventConfiguration.isEnabled() && !fileReadIOStatisticsEventConfiguration.isEnabled()) {
return read(dst, position);
}
int bytesRead = 0;
long start = 0;
long duration = 0;
try {
start = EventConfiguration.timestamp();
bytesRead = read(dst, position);
} finally {
long duration = EventConfiguration.timestamp() - start;
if (eventConfiguration.shouldCommit(duration)) {
duration = EventConfiguration.timestamp() - start;
if (fileReadEventConfiguration.shouldCommit(duration)) {
if (bytesRead < 0) {
FileReadEvent.commit(start, duration, path, 0L, true);
} else {
FileReadEvent.commit(start, duration, path, bytesRead, false);
}
}
}
if(fileReadIOStatisticsEventConfiguration.isEnabled()){
FileIOStatistics.addTotalReadBytesForPeriod(((bytesRead < 0) ? 0 : bytesRead), duration);
}
return bytesRead;
}

@JIInstrumentationMethod
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
EventConfiguration eventConfiguration = EventConfigurations.FILE_READ;
if (!eventConfiguration.isEnabled()) {
EventConfiguration fileReadEventConfiguration = EventConfigurations.FILE_READ;
EventConfiguration fileReadIOStatisticsEventConfiguration = EventConfigurations.FILE_READ_IO_STATISTICS;
if (!fileReadEventConfiguration.isEnabled() && !fileReadIOStatisticsEventConfiguration.isEnabled()) {
return read(dsts, offset, length);
}
long bytesRead = 0;
long start = 0;
long duration = 0;
try {
start = EventConfiguration.timestamp();
bytesRead = read(dsts, offset, length);
} finally {
long duration = EventConfiguration.timestamp() - start;
if (eventConfiguration.shouldCommit(duration)) {
duration = EventConfiguration.timestamp() - start;
if (fileReadEventConfiguration.shouldCommit(duration)) {
if (bytesRead < 0) {
FileReadEvent.commit(start, duration, path, 0L, true);
} else {
FileReadEvent.commit(start, duration, path, bytesRead, false);
}
}
}
if(fileReadIOStatisticsEventConfiguration.isEnabled()){
FileIOStatistics.addTotalReadBytesForPeriod(((bytesRead < 0) ? 0 : bytesRead), duration);
}
return bytesRead;
}

@JIInstrumentationMethod
public int write(ByteBuffer src) throws IOException {
EventConfiguration eventConfiguration = EventConfigurations.FILE_WRITE;
if (!eventConfiguration.isEnabled()) {
EventConfiguration fileWriteEventConfiguration = EventConfigurations.FILE_WRITE;
EventConfiguration fileWriteIOStatisticsEventConfiguration = EventConfigurations.FILE_WRITE_IO_STATISTICS;
if (!fileWriteEventConfiguration.isEnabled() && !fileWriteIOStatisticsEventConfiguration.isEnabled()) {
return write(src);
}
}
int bytesWritten = 0;
long start = 0;
long duration = 0;
try {
start = EventConfiguration.timestamp();
bytesWritten = write(src);
} finally {
long duration = EventConfiguration.timestamp() - start;
if (eventConfiguration.shouldCommit(duration)) {
duration = EventConfiguration.timestamp() - start;
if (fileWriteEventConfiguration.shouldCommit(duration)) {
long bytes = bytesWritten > 0 ? bytesWritten : 0;
FileWriteEvent.commit(start, duration, path, bytes);
}
}
if(fileWriteIOStatisticsEventConfiguration.isEnabled()){
FileIOStatistics.addTotalWriteBytesForPeriod(((bytesWritten > 0) ? bytesWritten : 0), duration);
}
return bytesWritten;
}

@JIInstrumentationMethod
public int write(ByteBuffer src, long position) throws IOException {
EventConfiguration eventConfiguration = EventConfigurations.FILE_WRITE;
if (!eventConfiguration.isEnabled()) {
EventConfiguration fileWriteEventConfiguration = EventConfigurations.FILE_WRITE;
EventConfiguration fileWriteIOStatisticsEventConfiguration = EventConfigurations.FILE_WRITE_IO_STATISTICS;
if (!fileWriteEventConfiguration.isEnabled() && !fileWriteIOStatisticsEventConfiguration.isEnabled()) {
return write(src, position);
}

int bytesWritten = 0;
long start = 0;
long duration = 0;
try {
start = EventConfiguration.timestamp();
bytesWritten = write(src, position);
} finally {
long duration = EventConfiguration.timestamp() - start;
if (eventConfiguration.shouldCommit(duration)) {
duration = EventConfiguration.timestamp() - start;
if (fileWriteEventConfiguration.shouldCommit(duration)) {
long bytes = bytesWritten > 0 ? bytesWritten : 0;
FileWriteEvent.commit(start, duration, path, bytes);
}
}
if(fileWriteIOStatisticsEventConfiguration.isEnabled()){
FileIOStatistics.addTotalWriteBytesForPeriod(((bytesWritten > 0) ? bytesWritten : 0), duration);
}

return bytesWritten;
}

@JIInstrumentationMethod
public long write(ByteBuffer[] srcs, int offset, int length) throws IOException {
EventConfiguration eventConfiguration = EventConfigurations.FILE_WRITE;
if (!eventConfiguration.isEnabled()) {
EventConfiguration fileWriteEventConfiguration = EventConfigurations.FILE_WRITE;
EventConfiguration fileWriteIOStatisticsEventConfiguration = EventConfigurations.FILE_WRITE_IO_STATISTICS;
if (!fileWriteEventConfiguration.isEnabled() && !fileWriteIOStatisticsEventConfiguration.isEnabled()) {
return write(srcs, offset, length);
}
long bytesWritten = 0;
long start = 0;
long duration = 0;
try {
start = EventConfiguration.timestamp();
bytesWritten = write(srcs, offset, length);
} finally {
long duration = EventConfiguration.timestamp() - start;
if (eventConfiguration.shouldCommit(duration)) {
duration = EventConfiguration.timestamp() - start;
if (fileWriteEventConfiguration.shouldCommit(duration)) {
long bytes = bytesWritten > 0 ? bytesWritten : 0;
FileWriteEvent.commit(start, duration, path, bytes);
}
}
if(fileWriteIOStatisticsEventConfiguration.isEnabled()){
FileIOStatistics.addTotalWriteBytesForPeriod(((bytesWritten > 0) ? bytesWritten : 0), duration);
}
return bytesWritten;
}
}
Loading