Mmuzaf commented on code in PR #3508:
URL: https://github.com/apache/cassandra/pull/3508#discussion_r1761190203
##########
src/java/org/apache/cassandra/tools/nodetool/GcStats.java:
##########
@@ -19,19 +19,32 @@
import org.apache.cassandra.tools.NodeProbe;
import org.apache.cassandra.tools.NodeTool.NodeToolCmd;
+import org.apache.cassandra.tools.nodetool.stats.GcStatsHolder;
+import org.apache.cassandra.tools.nodetool.stats.GcStatsPrinter;
+import org.apache.cassandra.tools.nodetool.stats.StatsHolder;
+import org.apache.cassandra.tools.nodetool.stats.StatsPrinter;
import io.airlift.airline.Command;
+import io.airlift.airline.Option;
@Command(name = "gcstats", description = "Print GC Statistics")
public class GcStats extends NodeToolCmd
{
+ @Option(title = "format",
+ name = {"-F", "--format"},
+ description = "Output format (json, yaml)")
+ private String outputFormat = "";
+
@Override
public void execute(NodeProbe probe)
{
- double[] stats = probe.getAndResetGCStats();
- double mean = stats[2] / stats[5];
- double stdev = Math.sqrt((stats[3] / stats[5]) - (mean * mean));
- probe.output().out.printf("%20s%20s%20s%20s%20s%20s%25s%n", "Interval
(ms)", "Max GC Elapsed (ms)", "Total GC Elapsed (ms)", "Stdev GC Elapsed (ms)",
"GC Reclaimed (MB)", "Collections", "Direct Memory Bytes");
-
probe.output().out.printf("%20.0f%20.0f%20.0f%20.0f%20.0f%20.0f%25d%n",
stats[0], stats[1], stats[2], stdev, stats[4], stats[5], (long)stats[6]);
+ if (!outputFormat.isEmpty() && !"json".equals(outputFormat) &&
!"yaml".equals(outputFormat))
+ {
+ throw new IllegalArgumentException("arguments for -F are json,
yaml only.");
+ }
+
+ StatsHolder data = new GcStatsHolder(probe);
+ StatsPrinter printer = GcStatsPrinter.from(outputFormat);
+ printer.print(data, probe.output().out);
Review Comment:
```suggestion
GcStatsHolder data = new GcStatsHolder(probe);
StatsPrinter<GcStatsHolder> printer =
GcStatsPrinter.from(outputFormat);
printer.print(data, probe.output().out);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]