How abhilash1401/leakwatch works
Purpose and entry point
LeakWatch is a CLI-oriented Java diagnostic tool that compiles and launches a user-selected Java source program, monitors its external process memory and GC signals, applies a heuristic for possible leaks, optionally terminates the target, and prints a final report. The application entry point and workflow coordinator are Main.java; presentation begins with Header.java.
1. Program selection boundary
FileSelector.java provides the user-facing source-file selection step, using Swing file selection for .java targets. Its output is the selected source path/name consumed by the execution pipeline. This separates LeakWatch’s own JVM from the application being diagnosed.
2. Target compilation and process lifecycle
JavaRunner.java owns target compilation and execution through Java process APIs/ProcessBuilder. It creates the monitored target Java process and supplies its process identity/lifecycle state to monitoring. This is the critical isolation boundary: LeakWatch observes and can stop a separate OS process rather than introspecting its own heap.
3. Cross-platform memory acquisition
MemoryMonitor.java periodically samples the target process’s memory usage. It relies on platform commands—PowerShell on Windows and ps on Linux/macOS—rather than JVM heap APIs, so measurements represent externally observable process memory. MemorySample.java is the time-series record passed downstream; MemoryUtils.java formats byte quantities for console output.
4. GC signal observation
GCMonitor.java observes garbage-collection activity from the running target, likely via process output/GC logging configured at launch. GC observations are used as evidence that memory should have had an opportunity to recover; they are not object-level or heap-dump analysis.
5. Heuristic leak analysis
LeakAnalyzer.java consumes collected MemorySample history plus GC observations to evaluate the defining pattern: significant growth, continuous upward trend, GC activity, and no meaningful recovery. It produces AnalysisResult.java, the decision boundary between raw monitoring data and the final classification of normal behavior versus a potential leak.
6. Control decision and termination
Main.java coordinates sampling, GC observation, and repeated analysis while the target remains active. When the analyzer identifies a suspicious pattern, the orchestration path instructs the process owner in JavaRunner.java to stop the target; otherwise monitoring ends when the program completes. This makes detection actionable but intentionally heuristic-driven.
7. Final reporting
Report.java renders the terminal summary from AnalysisResult.java, collected samples, GC-event count, and process outcome. Reported values include initial/final/peak memory, trend, recovery behavior, leak status, and whether LeakWatch terminated the application.
Runtime and operational dependencies
The tool requires JDK 11+ for compiling/running both LeakWatch and selected sources. It uses Java/Swing locally, OS process execution via ProcessBuilder, PowerShell on Windows, and ps on Linux/macOS. No server, database, persistent storage, or cloud service is indicated.
Main entry points: Main.java Main · Report.java Report · JavaRunner.java JavaRunner · GCMonitor.java GCMonitor
Components 13
Selection & presentation
- Main · CLI entry point coordinating the diagnostic lifecycle.
Main.java - Header
Header.java - FileSelector · Swing selection boundary for .java targets.
FileSelector.java - Report · Summarizes memory, trend, recovery, status, and outcome.
Report.java - MemoryUtils
MemoryUtils.java
Target process lifecycle
- JavaRunner · Compiles, launches, and can stop the separate target JVM.
JavaRunner.java - Selected Java program · User-selected source running as an isolated OS process.
External monitoring
- MemoryMonitor · Periodically reads target memory through OS commands.
MemoryMonitor.java - PowerShell / ps · Windows PowerShell or Linux/macOS ps provides external memory data.
- MemorySample
MemorySample.java - GCMonitor · Observes target GC activity via output or GC logging.
GCMonitor.java
Heuristic analysis
- LeakAnalyzer · Evaluates growth, trend, GC activity, and recovery.
LeakAnalyzer.java - AnalysisResult
AnalysisResult.java
Connections 21
- Main → Header: starts presentation
- Main → FileSelector: requests source
- FileSelector → JavaRunner: selected source path
- JavaRunner → Selected Java program: compiles and launches
- Main → MemoryMonitor: coordinates sampling
- MemoryMonitor → PowerShell / ps: queries memory
- PowerShell / ps → Selected Java program: reads process metrics
- MemoryMonitor → MemorySample: records samples
- Main → GCMonitor: coordinates observation
- Selected Java program → GCMonitor: GC output or logs
- MemorySample → LeakAnalyzer: memory history
- GCMonitor → LeakAnalyzer: GC observations
- LeakAnalyzer → AnalysisResult: classification
- AnalysisResult → Main: suspicion decision
- Main → JavaRunner: stop on suspected leak
- JavaRunner → Selected Java program: terminates when instructed
- Main → Report: final outcome and data
- AnalysisResult → Report: leak classification
- MemorySample → Report: memory summary
- GCMonitor → Report: GC event count
- MemoryUtils → Report: formats byte values