-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8365066: RecordingStream and RemoteRecordingStream do not terminate when the associated Recording is stopped or closed externally #26710
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
Open
chiroito
wants to merge
1
commit into
openjdk:master
Choose a base branch
from
chiroito:recording-stream
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+555
−51
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -41,7 +41,7 @@ | |||||
import jdk.jfr.internal.LogLevel; | ||||||
import jdk.jfr.internal.LogTag; | ||||||
import jdk.jfr.internal.Logger; | ||||||
import jdk.jfr.internal.PlatformRecording; | ||||||
import jdk.jfr.internal.management.EventSource; | ||||||
import jdk.jfr.internal.util.Utils; | ||||||
import jdk.jfr.internal.management.StreamBarrier; | ||||||
|
||||||
|
@@ -55,7 +55,6 @@ public final class EventDirectoryStream extends AbstractEventStream { | |||||
private static final Comparator<? super RecordedEvent> EVENT_COMPARATOR = JdkJfrConsumer.instance().eventComparator(); | ||||||
|
||||||
private final RepositoryFiles repositoryFiles; | ||||||
private final PlatformRecording recording; | ||||||
private final StreamBarrier barrier = new StreamBarrier(); | ||||||
private final AtomicLong streamId = new AtomicLong(); | ||||||
private ChunkParser currentParser; | ||||||
|
@@ -66,11 +65,10 @@ public final class EventDirectoryStream extends AbstractEventStream { | |||||
|
||||||
public EventDirectoryStream( | ||||||
Path p, | ||||||
PlatformRecording recording, | ||||||
EventSource eventSource, | ||||||
List<Configuration> configurations, | ||||||
boolean allowSubDirectories) throws IOException { | ||||||
super(configurations); | ||||||
this.recording = recording; | ||||||
super(configurations, eventSource); | ||||||
this.repositoryFiles = new RepositoryFiles(p, allowSubDirectories); | ||||||
this.streamId.incrementAndGet(); | ||||||
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Stream " + streamId + " started."); | ||||||
|
@@ -131,7 +129,7 @@ protected void processRecursionSafe() throws IOException { | |||||
Dispatcher lastDisp = null; | ||||||
Dispatcher disp = dispatcher(); | ||||||
Path path; | ||||||
boolean validStartTime = isRecordingStream() || disp.startTime != null; | ||||||
boolean validStartTime = eventSource.requiresStartTime() || disp.startTime != null; | ||||||
if (validStartTime) { | ||||||
path = repositoryFiles.firstPath(disp.startNanos, true); | ||||||
} else { | ||||||
|
@@ -169,6 +167,19 @@ protected void processRecursionSafe() throws IOException { | |||||
"ns (epoch), parser at " + lastFlush + "ns (epoch)."); | ||||||
return; | ||||||
} | ||||||
|
||||||
if(!barrier.used()) { | ||||||
RecordingState state = eventSource.getState(); | ||||||
if (state == RecordingState.CLOSED) { | ||||||
return; | ||||||
} else if (state == RecordingState.STOPPED) { | ||||||
long stopTime = eventSource.getStopTime(); | ||||||
if (lastFlush > stopTime) { | ||||||
logStreamEnd("stopped at " + stopTime + "ns (epoch), parser at " + lastFlush + "ns (epoch)."); | ||||||
return; | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
long endNanos = currentParser.getStartNanos() + currentParser.getChunkDuration(); | ||||||
long endMillis = Instant.ofEpochSecond(0, endNanos).toEpochMilli(); | ||||||
|
@@ -181,9 +192,13 @@ protected void processRecursionSafe() throws IOException { | |||||
return; | ||||||
} | ||||||
|
||||||
if (isRecordingStream()) { | ||||||
if (recording.getState() == RecordingState.STOPPED && !barrier.used()) { | ||||||
logStreamEnd("recording stopped externally."); | ||||||
if(!barrier.used()) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
RecordingState state = eventSource.getState(); | ||||||
if (state == RecordingState.CLOSED){ | ||||||
logStreamEnd("Event source is closed externally"); | ||||||
return; | ||||||
}else if(state == RecordingState.STOPPED) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
logStreamEnd("Event source is stopped externally"); | ||||||
return; | ||||||
} | ||||||
} | ||||||
|
@@ -226,10 +241,6 @@ private void logStreamEnd(String text) { | |||||
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, msg); | ||||||
} | ||||||
|
||||||
protected boolean isRecordingStream() { | ||||||
return recording != null; | ||||||
} | ||||||
|
||||||
private void processOrdered(Dispatcher c) throws IOException { | ||||||
if (sortedCache == null) { | ||||||
sortedCache = new RecordedEvent[100_000]; | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2025, 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.internal.consumer; | ||
|
||
import jdk.jfr.internal.management.EventSource; | ||
|
||
public class FileEventSource implements EventSource { | ||
} | ||
60 changes: 60 additions & 0 deletions
60
src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||||
/* | ||||||||
* Copyright (c) 2025, 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.internal.consumer; | ||||||||
|
||||||||
import jdk.jfr.RecordingState; | ||||||||
|
||||||||
import jdk.jfr.internal.PlatformRecording; | ||||||||
import jdk.jfr.internal.management.EventSource; | ||||||||
|
||||||||
public class LocalRecordingEventSource implements EventSource { | ||||||||
|
||||||||
private final PlatformRecording recording; | ||||||||
|
||||||||
public LocalRecordingEventSource(PlatformRecording recording) { | ||||||||
this.recording = recording; | ||||||||
} | ||||||||
|
||||||||
@Override | ||||||||
public boolean requiresStartTime() { | ||||||||
return true; | ||||||||
} | ||||||||
|
||||||||
@Override | ||||||||
public long getStopTime() { | ||||||||
return recording.getStopTime().toEpochMilli(); | ||||||||
} | ||||||||
|
||||||||
@Override | ||||||||
public boolean stop() { | ||||||||
return recording.stop("stopped by RecordingStream"); | ||||||||
} | ||||||||
|
||||||||
@Override | ||||||||
public RecordingState getState() { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
return recording.getState(); | ||||||||
} | ||||||||
} |
47 changes: 47 additions & 0 deletions
47
src/jdk.jfr/share/classes/jdk/jfr/internal/management/EventSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2025, 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.internal.management; | ||
|
||
import jdk.jfr.RecordingState; | ||
|
||
public interface EventSource { | ||
|
||
default long getStopTime() { | ||
return Long.MAX_VALUE; | ||
} | ||
|
||
default boolean stop() { | ||
return true; | ||
} | ||
|
||
default boolean requiresStartTime(){ | ||
return false; | ||
} | ||
|
||
default RecordingState getState() { | ||
return RecordingState.RUNNING; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.