2727import org .apache .cassandra .io .util .File ;
2828import org .apache .cassandra .io .util .FileUtils ;
2929import org .apache .cassandra .profiler .AsyncProfilerMBean ;
30- import org .apache .cassandra .tools .NodeProbe ;
3130import org .apache .cassandra .service .AsyncProfilerService .AsyncProfilerEvent ;
3231import org .apache .cassandra .service .AsyncProfilerService .AsyncProfilerFormat ;
32+ import org .apache .cassandra .tools .NodeProbe ;
3333import org .apache .cassandra .utils .FBUtilities ;
3434import picocli .CommandLine .Command ;
3535import picocli .CommandLine .Option ;
@@ -64,7 +64,7 @@ public void execute(NodeProbe probe)
6464 cmd .run ();
6565 }
6666
67- public static void doWithProfiler (NodeProbe probe , Consumer <AsyncProfilerMBean > consumer , boolean requiresEnabledProfiler )
67+ private static void doWithProfiler (NodeProbe probe , Consumer <AsyncProfilerMBean > consumer , boolean requiresEnabledProfiler )
6868 {
6969 AsyncProfilerMBean profiler = probe .getAsyncProfilerProxy ();
7070
@@ -77,6 +77,19 @@ public static void doWithProfiler(NodeProbe probe, Consumer<AsyncProfilerMBean>
7777 consumer .accept (profiler );
7878 }
7979
80+ private static String getOutputFileName (AsyncProfilerFormat outputFormat )
81+ {
82+ String filename = DateTimeFormatter .ofPattern ("yyyy-MM-dd-HH-mm-ss" )
83+ .withZone (ZoneId .systemDefault ()).format (FBUtilities .now ());
84+
85+ if (outputFormat == AsyncProfilerFormat .jfr )
86+ filename += ".jfr" ;
87+ else
88+ filename += ".html" ;
89+
90+ return filename ;
91+ }
92+
8093 public static void doWithProfiler (NodeProbe probe , Consumer <AsyncProfilerMBean > consumer )
8194 {
8295 doWithProfiler (probe , consumer , true );
@@ -92,15 +105,14 @@ public static class AsyncProfileStartCommand extends AbstractCommand
92105
93106 @ Option (names = { "-o" , "--output" }, description = "File name to save profiling results into, defaults to a " +
94107 "file of name 'yyyy-MM-dd-HH-mm-ss.html'" )
95- public String filename = DateTimeFormatter .ofPattern ("yyyy-MM-dd-HH-mm-ss" )
96- .withZone (ZoneId .systemDefault ()).format (FBUtilities .now ()) + ".html" ;
108+ public String filename ;
97109
98110 @ Option (names = { "-d" , "--duration" }, description = "Duration of profiling, defaults to '60s'. Accepts string values " +
99111 "in the form of '5m', '30s' and similar." )
100112 public String duration = "60s" ;
101113
102114 @ Option (names = { "-f" , "--format" },
103- description = "Output format, one of 'flat', 'traces', 'collapsed', 'flamegraph', 'tree', 'jfr', 'otlp', defaults to 'flamegraph'" )
115+ description = "Output format, one of 'flat', 'traces', 'collapsed', 'flamegraph', 'tree', 'jfr', defaults to 'flamegraph'" )
104116 public AsyncProfilerFormat outputFormat = AsyncProfilerFormat .flamegraph ;
105117
106118 @ Override
@@ -109,6 +121,9 @@ public void execute(NodeProbe probe)
109121 // make sure it is valid
110122 parseDuration (duration );
111123
124+ if (filename == null )
125+ filename = AsyncProfileCommandGroup .getOutputFileName (outputFormat );
126+
112127 doWithProfiler (probe , profiler -> {
113128 if (!profiler .start (event .stream ().map (Enum ::name ).collect (joining ("," )),
114129 outputFormat .name (),
0 commit comments