import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SimplifiedLogAnalyzer {
// Define patterns to match in log files
private static final Pattern WEBAPP_INIT_PATTERN = Pattern.compile("WebApplicationContext: initialization completed in (\\d+) ms");
private static final Pattern METHOD_EXECUTION_PATTERN = Pattern.compile("Time taken for\\*\\|\\*(.*?)\\*\\|\\*is\\*\\|\\*(\\d+)\\*\\|\\*ms");
// Data structure to store timing information
static class TimingInfo {
String operation;
long timeInMs;
TimingInfo(String operation, long timeInMs) {
this.operation = operation;
this.timeInMs = timeInMs;
}
}
// Data structure to store statistics
static class Statistics {
long min = Long.MAX_VALUE;
long max = Long.MIN_VALUE;
long sum = 0;
int count = 0;
void addValue(long value) {
min = Math.min(min, value);
max = Math.max(max, value);
sum += value;
count++;
}
double getAverage() {
return count > 0 ? (double) sum / count : 0;
}
@Override
public String toString() {
return String.format("Count: %d, Min: %d ms, Max: %d ms, Avg: %.2f ms, Total: %d ms",
count, min, max, getAverage(), sum);
}
}
public static void main(String[] args) {
// BEFORE UPGRADE: Paste your log content here
String beforeUpgradeLogContent =
"INFO 2024-12-29 15:55:19,347 [[STANDBY] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)'] " +
"(org-springframework.boot.web.servlet.context.ServletWebServerApplicationContext) - Root WebApplicationContext: initialization completed in 15299 ms\n" +
"INFO 2024-12-29 15:55:21,560 [[STANDBY] ExecuteThread: '27' for queue: 'weblogic.kernel.Default (self-tuning)'] " +
"(org-springframework-boot.web.servlet.context.ServletWebServerApplicationContext) - Root WebApplicationContext: initialization completed in 15968 ms\n" +
"INFO 2024-12-29 16:01:08,067 [LoggerThread-0] (TimeTracker) - 2024-12-29 16:01:08,064 Thread[[ACTIVE] ExecuteThread: " +
"'11' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads] [com.cibc-go.myclient.dao.impl." +
"ReferenceDataDaoImpl.getRefTableValues(ReferenceDataDaoImpl.java:96)] *| *Time taken for*|*ReferenceDataDaoImpl." +
"getRefTableValues*|*is*| *567*|*ms.\n" +
"INFO 2024-12-29 16:01:10,679 [LoggerThread-0] (TimeTracker) - 2024-12-29 16:01:10,678 Thread[[ACTIVE] ExecuteThread: " +
"'11' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads] [com.cibc-go.myclient.dao.impl." +
"ReferenceDataDaoImpl.getEntitySubTypes(ReferenceDataDaoImpl.java:324)] *| *Time taken for*| *ReferenceDataDaoImpl." +
"getEntitySubTypes*|*is*|*4206*| *ms.";
// AFTER UPGRADE: Paste your log content here
String afterUpgradeLogContent =
"INFO 2025-01-29 15:55:19,347 [[STANDBY] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)'] " +
"(org-springframework.boot.web.servlet.context.ServletWebServerApplicationContext) - Root WebApplicationContext: initialization completed in 11299 ms\n" +
"INFO 2025-01-29 15:55:21,560 [[STANDBY] ExecuteThread: '27' for queue: 'weblogic.kernel.Default (self-tuning)'] " +
"(org-springframework-boot.web.servlet.context.ServletWebServerApplicationContext) - Root WebApplicationContext: initialization completed in 11968 ms\n" +
"INFO 2025-01-29 16:01:08,067 [LoggerThread-0] (TimeTracker) - 2025-01-29 16:01:08,064 Thread[[ACTIVE] ExecuteThread: " +
"'11' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads] [com.cibc-go.myclient.dao.impl." +
"ReferenceDataDaoImpl.getRefTableValues(ReferenceDataDaoImpl.java:96)] *| *Time taken for*|*ReferenceDataDaoImpl." +
"getRefTableValues*|*is*| *367*|*ms.\n" +
"INFO 2025-01-29 16:01:10,679 [LoggerThread-0] (TimeTracker) - 2025-01-29 16:01:10,678 Thread[[ACTIVE] ExecuteThread: " +
"'11' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads] [com.cibc-go.myclient.dao.impl." +
"ReferenceDataDaoImpl.getEntitySubTypes(ReferenceDataDaoImpl.java:324)] *| *Time taken for*| *ReferenceDataDaoImpl." +
"getEntitySubTypes*|*is*|*2606*| *ms.";
// Replace the sample data above with your actual log content
// You can paste 2000 lines if needed - just add them to the strings
// Process the logs
Map<String, Statistics> beforeStats = processLogContent(beforeUpgradeLogContent);
Map<String, Statistics> afterStats = processLogContent(afterUpgradeLogContent);
// Print comparison
printComparison(beforeStats, afterStats);
}
private static Map<String, Statistics> processLogContent(String logContent) {
List<TimingInfo> timings = new ArrayList<>();
// Split the content into lines
String[] lines = logContent.split("\n");
System.out.println("Processing " + lines.length + " log lines");
for (String line : lines) {
// Try to match WebApp initialization pattern
Matcher webappMatcher = WEBAPP_INIT_PATTERN.matcher(line);
if (webappMatcher.find()) {
long time = Long.parseLong(webappMatcher.group(1));
timings.add(new TimingInfo("WebApplicationContext Initialization", time));
continue;
}
// Try to match method execution pattern
Matcher methodMatcher = METHOD_EXECUTION_PATTERN.matcher(line);
if (methodMatcher.find()) {
String methodName = methodMatcher.group(1);
long time = Long.parseLong(methodMatcher.group(2));
timings.add(new TimingInfo(methodName, time));
}
}
System.out.println("Found " + timings.size() + " timing entries");
// Calculate statistics
return calculateStatistics(timings);
}
private static Map<String, Statistics> calculateStatistics(List<TimingInfo> timings) {
Map<String, Statistics> statsByOperation = new HashMap<>();
for (TimingInfo timing : timings) {
Statistics stats = statsByOperation.computeIfAbsent(timing.operation, k -> new Statistics());
stats.addValue(timing.timeInMs);
}
return statsByOperation;
}
private static void printComparison(Map<String, Statistics> beforeStats, Map<String, Statistics> afterStats) {
System.out.println("\n===================== PERFORMANCE COMPARISON =====================");
System.out.println("Operation | Before Upgrade | After Upgrade | Improvement (%)");
System.out.println("----------------------------------------------------------------");
// Combine all keys
java.util.Set<String> allOperations = new java.util.HashSet<>();
allOperations.addAll(beforeStats.keySet());
allOperations.addAll(afterStats.keySet());
for (String operation : allOperations) {
Statistics before = beforeStats.getOrDefault(operation, new Statistics());
Statistics after = afterStats.getOrDefault(operation, new Statistics());
// Skip if no data for comparison
if (before.count == 0 || after.count == 0) {
System.out.println(operation + " - Incomplete data, skipping comparison");
continue;
}
double beforeAvg = before.getAverage();
double afterAvg = after.getAverage();
double improvementPct = beforeAvg > 0 ? ((beforeAvg - afterAvg) / beforeAvg) * 100 : 0;
System.out.printf("%-40s | %-15s | %-15s | %s%n",
operation,
String.format("%.2f ms", beforeAvg),
String.format("%.2f ms", afterAvg),
String.format("%+.2f%%", improvementPct));
}
System.out.println("================================================================");
}
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (6)