mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8310978: JFR events SocketReadEvent/SocketWriteEvent for Socket adaptor ops
Reviewed-by: dfuchs, alanb
This commit is contained in:
parent
988e1dfe6e
commit
1183b221c2
8 changed files with 204 additions and 30 deletions
|
@ -110,6 +110,23 @@ public class SocketReadEvent extends Event {
|
|||
* timestamp and the given start time. If the duration is meets
|
||||
* or exceeds the configured value (determined by calling the generated method
|
||||
* {@link #shouldCommit(long)}), an event will be emitted by calling
|
||||
* {@link #emit(long, long, long, SocketAddress, long)}
|
||||
*
|
||||
* @param start the start time
|
||||
* @param nbytes how many bytes were transferred
|
||||
* @param remote the address of the remote socket
|
||||
* @param timeout maximum time to wait
|
||||
*/
|
||||
public static void offer(long start, long nbytes, SocketAddress remote, long timeout) {
|
||||
long duration = timestamp() - start;
|
||||
if (shouldCommit(duration)) {
|
||||
emit(start, duration, nbytes, remote, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to perform a common task of getting event data ready and
|
||||
* then emitting the event by calling
|
||||
* {@link #commit(long, long, String, String, int, long, long, boolean)}.
|
||||
*
|
||||
* @param start the start time
|
||||
|
|
|
@ -105,6 +105,22 @@ public class SocketWriteEvent extends Event {
|
|||
* timestamp and the given start time. If the duration is meets
|
||||
* or exceeds the configured value (determined by calling the generated method
|
||||
* {@link #shouldCommit(long)}), an event will be emitted by calling
|
||||
* {@link #emit(long, long, long, SocketAddress)}.
|
||||
*
|
||||
* @param start the start time
|
||||
* @param bytesWritten how many bytes were sent
|
||||
* @param remote the address of the remote socket being written to
|
||||
*/
|
||||
public static void offer(long start, long bytesWritten, SocketAddress remote) {
|
||||
long duration = timestamp() - start;
|
||||
if (shouldCommit(duration)) {
|
||||
emit(start, duration, bytesWritten, remote);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to perform a common task of getting event data ready and
|
||||
* then emitting the event by calling
|
||||
* {@link #commit(long, long, String, String, int, long)}.
|
||||
*
|
||||
* @param start the start time
|
||||
|
|
|
@ -494,10 +494,7 @@ class SocketChannelImpl
|
|||
}
|
||||
long start = SocketReadEvent.timestamp();
|
||||
int nbytes = implRead(buf);
|
||||
long duration = SocketReadEvent.timestamp() - start;
|
||||
if (SocketReadEvent.shouldCommit(duration)) {
|
||||
SocketReadEvent.emit(start, duration, nbytes, remoteAddress(), 0);
|
||||
}
|
||||
SocketReadEvent.offer(start, nbytes, remoteAddress(), 0);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
@ -511,10 +508,7 @@ class SocketChannelImpl
|
|||
}
|
||||
long start = SocketReadEvent.timestamp();
|
||||
long nbytes = implRead(dsts, offset, length);
|
||||
long duration = SocketReadEvent.timestamp() - start;
|
||||
if (SocketReadEvent.shouldCommit(duration)) {
|
||||
SocketReadEvent.emit(start, duration, nbytes, remoteAddress(), 0);
|
||||
}
|
||||
SocketReadEvent.offer(start, nbytes, remoteAddress(), 0);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
@ -625,10 +619,7 @@ class SocketChannelImpl
|
|||
}
|
||||
long start = SocketWriteEvent.timestamp();
|
||||
int nbytes = implWrite(buf);
|
||||
long duration = SocketWriteEvent.timestamp() - start;
|
||||
if (SocketWriteEvent.shouldCommit(duration)) {
|
||||
SocketWriteEvent.emit(start, duration, nbytes, remoteAddress());
|
||||
}
|
||||
SocketWriteEvent.offer(start, nbytes, remoteAddress());
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
@ -641,10 +632,7 @@ class SocketChannelImpl
|
|||
}
|
||||
long start = SocketWriteEvent.timestamp();
|
||||
long nbytes = implWrite(srcs, offset, length);
|
||||
long duration = SocketWriteEvent.timestamp() - start;
|
||||
if (SocketWriteEvent.shouldCommit(duration)) {
|
||||
SocketWriteEvent.emit(start, duration, nbytes, remoteAddress());
|
||||
}
|
||||
SocketWriteEvent.offer(start, nbytes, remoteAddress());
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 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
|
||||
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package sun.nio.ch;
|
||||
|
||||
import jdk.internal.event.SocketReadEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.function.IntSupplier;
|
||||
|
@ -60,9 +62,7 @@ class SocketInputStream extends InputStream {
|
|||
return (n > 0) ? (a[0] & 0xff) : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int timeout = timeoutSupplier.getAsInt();
|
||||
private int implRead(byte[] b, int off, int len, int timeout) throws IOException {
|
||||
if (timeout > 0) {
|
||||
long nanos = MILLISECONDS.toNanos(timeout);
|
||||
return sc.blockingRead(b, off, len, nanos);
|
||||
|
@ -71,6 +71,18 @@ class SocketInputStream extends InputStream {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int timeout = timeoutSupplier.getAsInt();
|
||||
if (!SocketReadEvent.enabled()) {
|
||||
return implRead(b, off, len, timeout);
|
||||
}
|
||||
long start = SocketReadEvent.timestamp();
|
||||
int n = implRead(b, off, len, timeout);
|
||||
SocketReadEvent.offer(start, n, sc.remoteAddress(), timeout);
|
||||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return sc.available();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 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
|
||||
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package sun.nio.ch;
|
||||
|
||||
import jdk.internal.event.SocketWriteEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
|
@ -55,7 +57,13 @@ class SocketOutputStream extends OutputStream {
|
|||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
if (!SocketWriteEvent.enabled()) {
|
||||
sc.blockingWriteFully(b, off, len);
|
||||
return;
|
||||
}
|
||||
long start = SocketWriteEvent.timestamp();
|
||||
sc.blockingWriteFully(b, off, len);
|
||||
SocketWriteEvent.offer(start, len, sc.remoteAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue