mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +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
|
@ -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