Skip to content

Commit

Permalink
Add config option for thread dumping
Browse files Browse the repository at this point in the history
Adds option to the log settings for controlling if application should print
the thread dump on shutdown.
Since it creates a lot of possibly unwanted clutter it is disabled by default.
  • Loading branch information
Bouncheck committed Oct 21, 2024
1 parent b518ec2 commit 5d1911d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions tools/stress/src/org/apache/cassandra/stress/Stress.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ public final class Stress

public static void main(String[] arguments) throws Exception
{
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("Shutdown thread dump:");
System.out.println(threadDump(true, true));
}));
registerSignalHandler();

if (FBUtilities.isWindows)
WindowsTimer.startTimerPeriod(1);
Expand Down Expand Up @@ -100,6 +95,14 @@ private static int run(String[] arguments)
return 1;
}

if (settings.log.printThreadDumpOnShutdown) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("Shutdown thread dump:");
System.out.println(threadDump(true, true));
}));
registerSignalHandler();
}

MultiResultLogger logout = settings.log.getOutput();

if (! settings.log.noSettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public static enum Level
public final File hdrFile;
public final int intervalMillis;
public final Level level;
public final boolean printThreadDumpOnShutdown;

public SettingsLog(Options options)
{

noSummary = options.noSummmary.setByUser();
noSettings = options.noSettings.setByUser();
printStatementsOnError = options.printStatementsOnError.setByUser();
printThreadDumpOnShutdown = options.printThreadDumpOnShutdown.setByUser();

if (options.outputFile.setByUser())
file = new File(options.outputFile.value());
Expand Down Expand Up @@ -93,11 +95,12 @@ public static final class Options extends GroupedOptions
final OptionSimple hdrOutputFile = new OptionSimple("hdrfile=", ".*", null, "Log to a file", false);
final OptionSimple interval = new OptionSimple("interval=", "[0-9]+(ms|s|)", "1s", "Log progress every <value> seconds or milliseconds", false);
final OptionSimple level = new OptionSimple("level=", "(minimal|normal|verbose)", "normal", "Logging level (minimal, normal or verbose)", false);
final OptionSimple printThreadDumpOnShutdown = new OptionSimple("print-thread-dump-on-shutdown", "", null, "Print local thread dump to the standard output on shutdown (normal, SIGTERM, SIGINT, SIGABRT).", false);

@Override
public List<? extends Option> options()
{
return Arrays.asList(level, noSummmary, outputFile, hdrOutputFile, interval, noSettings, printStatementsOnError);
return Arrays.asList(level, noSummmary, outputFile, hdrOutputFile, interval, noSettings, printStatementsOnError, printThreadDumpOnShutdown);
}
}

Expand Down

0 comments on commit 5d1911d

Please sign in to comment.