first commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// This is an example script for Crash Assistant.
|
||||
// It detects if the crash was triggered manually by the user (F3 + C).
|
||||
|
||||
// You can use the 'Analysis' object to add warnings.
|
||||
// If you want your custom warning to be localized, you can use the "config/crash_assistant/crash_assistant_localization_overrides" folder.
|
||||
// Your custom keys with the prefix 'custom.' will NOT be automatically cleared as unused.
|
||||
// Example: Analysis.addWarning(log, LanguageProvider.get("custom.manual_crash"));
|
||||
|
||||
// Full documentation and more examples: https://github.com/KostromDan/Crash-Assistant/blob/pages/guides/Scripting%20Support/Getting%20Started.md
|
||||
|
||||
// Request specific log types for analysis.
|
||||
var requested_logs = LogsList.getLogs(CRASH_REPORT);
|
||||
// You can request multiple log types: var requested_logs = LogsList.getLogs(LOG, CRASH_REPORT, HS_ERR, STDERR_STREAM)
|
||||
// Warning: if you want to analyze WIN_EVENT log type, due to them coming with a delay, they are not available on the first launch of the script.
|
||||
// In such a case, you must allow your script to run on second-time analysis calls (when the log is added later): Analysis.markRunAlways()
|
||||
|
||||
for (log : requested_logs) {
|
||||
var log_text = log.getReader().getAllLinesString();
|
||||
// If you want to get lines as a List<String>, not a single String, you can use: log.getReader().getAllLinesList()
|
||||
// If you want to get not the entire log, but the last 100 lines as a List<String>, you can use: log.getReader().getLastNLines(100); or the first lines: log.getReader().getFirstNLines(10)
|
||||
|
||||
// You can use standard Java regex classes (Pattern, Matcher) if you need to extract specific data (like a version number) from the log.
|
||||
// However, if you just need a simple true/false check, you can use the 'RegexChecker' utility for convenience.
|
||||
// It can check multiple patterns at once.
|
||||
// RegexChecker.logContainsOneOfPatterns returns true if ANY of the patterns match.
|
||||
// You can give this function any number of patterns.
|
||||
var pattern1 = "Description: Manually triggered debug crash";
|
||||
var pattern2 = "Caused by: java\\.lang\\.Throwable: Manually triggered debug crash";
|
||||
|
||||
if (RegexChecker.logContainsOneOfPatterns(log, pattern1, pattern2)) {
|
||||
// If you don't want to use localization, you can just pass a raw string (supports HTML tags and formatting):
|
||||
// Analysis.addWarning(log, "Manual crash detected!");
|
||||
|
||||
// Using internal localization key shipped with mod:
|
||||
var warn = Analysis.addWarning(log, LanguageProvider.get("custom.manual_crash"));
|
||||
// Now the String received from LanguageProvider.get("custom.manual_crash") will be displayed to the user as a warning.
|
||||
// If you don't need the additional options below, you can call Analysis.addWarning(...) without assigning it to a variable.
|
||||
|
||||
// You can add a 'don't show again' checkbox, so the user can prevent this warning from showing in the future.
|
||||
// Needs a unique key, by which it'll recognize this 'don't show again' choice from others.
|
||||
warn.withDontShowAgain("manual_crash_warning");
|
||||
|
||||
// If you want to ensure the user will read the warning, you can set a delay in seconds for the OK button, so the user can't immediately close it.
|
||||
// We set it to 0 because we don't want one and it's just an example.
|
||||
warn.withOkDelay(0);
|
||||
|
||||
// You can set the priority for this warning. Warnings with higher priority are shown first.
|
||||
warn.withPriority(10001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// This is an example script for Crash Assistant.
|
||||
// It designed to demonstrate abilities of startup scripts and by default warn about over allocation of ram (more than system can provide).
|
||||
// With startup scripts you can do including but not limited:
|
||||
// - Analyse ram alloction.
|
||||
// - Analyse jvm / minecraft args.
|
||||
// - Analyse modlist for incompatible / removed neccery mods.
|
||||
// Full documentation and more examples: https://github.com/KostromDan/Crash-Assistant/blob/pages/guides/Scripting%20Support/Getting%20Started.md
|
||||
|
||||
|
||||
// --- Configuration Area ---
|
||||
var MIN_CRITICAL_GB = 4.0;
|
||||
var MIN_RECOMMENDED_GB = 8.0;
|
||||
var MAX_RECOMMENDED_GB = 12.0;
|
||||
// --------------------------
|
||||
|
||||
// Most options are commented out. Please uncomment them to enable them.
|
||||
|
||||
var xmxBytes = MemoryUtils.getJvmMaxHeapBytes();
|
||||
var xmxGB = MemoryUtils.bytesToGigabytes(xmxBytes);
|
||||
var formattedXmx = MemoryUtils.formatMemorySize(xmxBytes);
|
||||
|
||||
// 1. Critical Minimum Check
|
||||
//if (xmxGB < MIN_CRITICAL_GB) {
|
||||
// var msg = LanguageProvider.get("custom.critical_min");
|
||||
// msg = msg.replace("$XMX$", formattedXmx);
|
||||
// msg = msg.replace("$MIN_RECOMMENDED$", MIN_RECOMMENDED_GB.toString());
|
||||
// var warn = Startup.addBootWarning(msg);
|
||||
// warn.withMemoryAllocationGuide();
|
||||
//}
|
||||
|
||||
// 2. Minimum Recommended Check
|
||||
//else if (xmxGB < MIN_RECOMMENDED_GB) {
|
||||
// var msg = LanguageProvider.get("custom.min_recommended");
|
||||
// msg = msg.replace("$XMX$", formattedXmx);
|
||||
// msg = msg.replace("$MIN_RECOMMENDED$", MIN_RECOMMENDED_GB.toString());
|
||||
// var lowMemWarn = Startup.addBootWarning(msg);
|
||||
// lowMemWarn.withDontShowAgain("low_memory_check");
|
||||
// lowMemWarn.withMemoryAllocationGuide();
|
||||
//}
|
||||
|
||||
// 3. Excessive Allocation Check
|
||||
// Warning starts exactly when Xmx exceeds MAX_RECOMMENDED_GB.
|
||||
//if (xmxGB > MAX_RECOMMENDED_GB) {
|
||||
// var msg = LanguageProvider.get("custom.excessive_allocation");
|
||||
// msg = msg.replace("$XMX$", formattedXmx);
|
||||
// msg = msg.replace("$MIN_RECOMMENDED$", MIN_RECOMMENDED_GB.toString());
|
||||
// msg = msg.replace("$MAX_RECOMMENDED$", MAX_RECOMMENDED_GB.toString());
|
||||
// var excessiveMemWarn = Startup.addBootWarning(msg);
|
||||
// excessiveMemWarn.withDontShowAgain("excessive_memory_check");
|
||||
// excessiveMemWarn.withMemoryAllocationGuide();
|
||||
//}
|
||||
|
||||
// 4. Over-Allocation vs Total Capacity Check (Hardware Limit)
|
||||
var totalSystemCapacity = MemoryUtils.getSystemTotalMemoryBytes() + MemoryUtils.getSystemTotalSwapBytes();
|
||||
var exceedsTotalSystemCapacity = xmxBytes > totalSystemCapacity;
|
||||
if (exceedsTotalSystemCapacity) {
|
||||
var msg = LanguageProvider.get("custom.over_allocation");
|
||||
msg = msg.replace("$XMX$", formattedXmx);
|
||||
msg = msg.replace("$TOTAL_CAPACITY$", MemoryUtils.formatMemorySize(totalSystemCapacity));
|
||||
var warn = Startup.addBootWarning(msg);
|
||||
warn.withMemoryAllocationGuide();
|
||||
}
|
||||
|
||||
// 5. High System Load Check (Current Capacity)
|
||||
var systemAvailable = MemoryUtils.getSystemFreeMemoryBytes() + MemoryUtils.getSystemFreeSwapBytes();
|
||||
var jvmAllocated = MemoryUtils.getJvmAllocatedMemoryBytes();
|
||||
var stillNeeded = xmxBytes - jvmAllocated;
|
||||
|
||||
if (!exceedsTotalSystemCapacity && xmxBytes > 0 && stillNeeded > 0 && systemAvailable < stillNeeded) {
|
||||
var msg = LanguageProvider.get("custom.high_system_load");
|
||||
msg = msg.replace("$XMX$", formattedXmx);
|
||||
msg = msg.replace("$AVAILABLE$", MemoryUtils.formatMemorySize(systemAvailable));
|
||||
var highLoadWarn = Startup.addBootWarning(msg);
|
||||
highLoadWarn.withDontShowAgain("high_system_load_check");
|
||||
highLoadWarn.withMemoryAllocationGuide();
|
||||
}
|
||||
|
||||
// 6. Windows Swap/Pagefile Check
|
||||
//if (PlatformHelp.isWindows() && MemoryUtils.getSystemTotalSwapBytes() == 0) {
|
||||
// var msg = LanguageProvider.get("custom.windows_no_swap");
|
||||
// msg = msg.replace("$XMX$", formattedXmx);
|
||||
// var noSwapWarn = Startup.addBootWarning(msg);
|
||||
// noSwapWarn.withDontShowAgain("windows_no_swap_check");
|
||||
// noSwapWarn.withMemoryAllocationGuide();
|
||||
//}
|
||||
|
||||
// 7. Large Heap / ZGC Advice
|
||||
//var jvmArgs = ArgUtils.getSafeJvmArgs();
|
||||
//var launchArgs = ArgUtils.getSafeLaunchArgs();
|
||||
//if (xmxGB > 12.0 && !jvmArgs.contains("-XX:+UseZGC")) {
|
||||
// var msg = LanguageProvider.get("custom.large_heap_zgc");
|
||||
// msg = msg.replace("$XMX$", formattedXmx);
|
||||
// var zgcWarn = Startup.addBootWarning(msg);
|
||||
// zgcWarn.withDontShowAgain("zgc_recommendation_check");
|
||||
// zgcWarn.withJvmArgsGuide();
|
||||
//}
|
||||
Reference in New Issue
Block a user