112 lines
4.7 KiB
Diff
Executable File
112 lines
4.7 KiB
Diff
Executable File
From fcf556744f9597ddd58c8103bf49bc992401feca Mon Sep 17 00:00:00 2001
|
|
From: hubodao <hubodao@huawei.com>
|
|
Date: Sat, 11 Sep 2021 09:47:21 +0800
|
|
Subject: [PATCH 4/8] create jfr dump file with pid or timestamp if specified
|
|
|
|
Summary: <JFR> : create jfr dump file with pid or timestamp if specified
|
|
LLT: NA
|
|
Patch Type: huawei
|
|
Bug url: NA
|
|
---
|
|
src/hotspot/share/jfr/dcmd/jfrDcmds.cpp | 16 ++++++++++++++--
|
|
src/hotspot/share/utilities/ostream.cpp | 2 +-
|
|
src/hotspot/share/utilities/ostream.hpp | 2 +-
|
|
.../jdk/jfr/jcmd/TestJcmdDumpWithFileName.java | 16 ++++++++++++++++
|
|
4 files changed, 32 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp b/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp
|
|
index 4aa5c56f3..b1c5df029 100644
|
|
--- a/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp
|
|
+++ b/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp
|
|
@@ -230,7 +230,13 @@ void JfrDumpFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {
|
|
|
|
jstring filepath = NULL;
|
|
if (_filename.is_set() && _filename.value() != NULL) {
|
|
- filepath = JfrJavaSupport::new_string(_filename.value(), CHECK);
|
|
+ const char* extended_path = make_log_name(_filename.value(), NULL);
|
|
+ if (extended_path != NULL) {
|
|
+ filepath = JfrJavaSupport::new_string(extended_path, CHECK);
|
|
+ FREE_C_HEAP_ARRAY(char, extended_path);
|
|
+ } else {
|
|
+ filepath = JfrJavaSupport::new_string(_filename.value(), CHECK);
|
|
+ }
|
|
}
|
|
|
|
jobject maxage = NULL;
|
|
@@ -398,7 +404,13 @@ void JfrStartFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {
|
|
|
|
jstring filename = NULL;
|
|
if (_filename.is_set() && _filename.value() != NULL) {
|
|
- filename = JfrJavaSupport::new_string(_filename.value(), CHECK);
|
|
+ const char *dumpPath = make_log_name(_filename.value(), NULL);
|
|
+ if (dumpPath != NULL) {
|
|
+ filename = JfrJavaSupport::new_string(dumpPath, CHECK);
|
|
+ FREE_C_HEAP_ARRAY(char, dumpPath);
|
|
+ } else {
|
|
+ filename = JfrJavaSupport::new_string(_filename.value(), CHECK);
|
|
+ }
|
|
}
|
|
|
|
jobject maxage = NULL;
|
|
diff --git a/src/hotspot/share/utilities/ostream.cpp b/src/hotspot/share/utilities/ostream.cpp
|
|
index eb8ee4de1..0aabe8e8f 100644
|
|
--- a/src/hotspot/share/utilities/ostream.cpp
|
|
+++ b/src/hotspot/share/utilities/ostream.cpp
|
|
@@ -528,7 +528,7 @@ static const char* make_log_name_internal(const char* log_name, const char* forc
|
|
// -XX:DumpLoadedClassList=<file_name>
|
|
// in log_name, %p => pid1234 and
|
|
// %t => YYYY-MM-DD_HH-MM-SS
|
|
-static const char* make_log_name(const char* log_name, const char* force_directory) {
|
|
+const char* make_log_name(const char* log_name, const char* force_directory) {
|
|
char timestr[32];
|
|
get_datetime_string(timestr, sizeof(timestr));
|
|
return make_log_name_internal(log_name, force_directory, os::current_process_id(),
|
|
diff --git a/src/hotspot/share/utilities/ostream.hpp b/src/hotspot/share/utilities/ostream.hpp
|
|
index fe38c2f3e..e2a8a621c 100644
|
|
--- a/src/hotspot/share/utilities/ostream.hpp
|
|
+++ b/src/hotspot/share/utilities/ostream.hpp
|
|
@@ -309,5 +309,5 @@ class networkStream : public bufferedStream {
|
|
};
|
|
|
|
#endif
|
|
-
|
|
+const char* make_log_name(const char* log_name, const char* force_directory);
|
|
#endif // SHARE_VM_UTILITIES_OSTREAM_HPP
|
|
diff --git a/test/jdk/jdk/jfr/jcmd/TestJcmdDumpWithFileName.java b/test/jdk/jdk/jfr/jcmd/TestJcmdDumpWithFileName.java
|
|
index 691e53174..cead3a0e7 100644
|
|
--- a/test/jdk/jdk/jfr/jcmd/TestJcmdDumpWithFileName.java
|
|
+++ b/test/jdk/jdk/jfr/jcmd/TestJcmdDumpWithFileName.java
|
|
@@ -47,6 +47,7 @@ public class TestJcmdDumpWithFileName {
|
|
testDumpAll();
|
|
testDumpNamed();
|
|
testDumpNamedWithFilename();
|
|
+ testDumpNamedWithFilenameExpansion();
|
|
}
|
|
|
|
private static void testDumpAll() throws Exception {
|
|
@@ -96,6 +97,21 @@ public class TestJcmdDumpWithFileName {
|
|
cleanup();
|
|
}
|
|
|
|
+ private static void testDumpNamedWithFilenameExpansion() throws Exception {
|
|
+ long pid = ProcessHandle.current().pid();
|
|
+ Path dumpPath = Path.of("dumpPath-%p-%t.jfr").toAbsolutePath();
|
|
+ try (Recording r = new Recording()) {
|
|
+ r.setName("testDumpNamedWithFilenameExpansion");
|
|
+ r.setDestination(dumpPath);
|
|
+ r.start();
|
|
+ JcmdHelper.jcmd("JFR.dump", "name=testDumpNamedWithFilenameExpansion", "filename=" + dumpPath.toString());
|
|
+ Stream<Path> stream = Files.find(Path.of("."), 1, (s, a) -> s.toString()
|
|
+ .matches("^.*dumpPath-pid" + pid + ".\\d{4}.\\d{2}.\\d{2}.\\d{2}.\\d{2}.\\d{2}" + ".jfr") && (a.size() > 0L));
|
|
+ Asserts.assertTrue(stream.findAny().isPresent());
|
|
+ }
|
|
+ cleanup();
|
|
+ }
|
|
+
|
|
private static boolean namedFile(Path dumpFile) throws IOException {
|
|
return Files.exists(dumpFile) && (Files.size(dumpFile) > 0);
|
|
}
|
|
--
|
|
2.22.0
|
|
|