How chewiebug/gcviewer works
Project Type & Purpose
• It ships as an executable JAR (and a Mac .app via Maven Assembly) and is built with Maven.
• Its core function is: read GC logs → parse events → build an in-memory model → render charts & tables → optionally export metrics.
File Structure
• pom.xml – Maven build / packaging / assembly config.
• cicd/ – Build scripts (Docker, CI credentials, Travis/GitHub Actions).
• src/main/java: package com.tagtraum.perf.gcviewer divided into:
• imp/ – parsers (“DataReader” implementations per JVM type).
• exp/ – exporters (“DataWriter” implementations).
• ctrl/ – controllers & factories (GCModelLoader, GUI controllers, actions).
• model/ – domain classes (GCEvent, GCModel, GcResource…).
• view/ – Swing UI (frames, panels, renderers, menu/toolbars).
• math/, util/, log/ – helpers for calculations, IO, logging.
• src/main/assembly – packaging instructions (e.g. Mac dist).
• src/test – unit tests exercising each layer.
• dependometer/ – static dependency analysis config.
• doc/ – design/usage docs.
Key Insights from README
• Two execution modes: GUI (java -jar gcviewer.jar double-click) and CLI (java -jar gcviewer.jar gc.log summary.csv [chart.png] [-t FORMAT]).
• Supported GC formats listed in README correspond to DataReader implementations.
• MVC pattern: clear separation between model (domain), view (Swing), controller (actions, loaders).
• Export formats mapped to DataWriter implementations (CSV, PLAIN, SIMPLE, SUMMARY, CSV_TS).
Main Components & Their Relationships
a. Entry Points
• GUI Launcher (GCViewer.main)
• CLI Parser (GCViewerArgsParser → dispatches to summary export or GUI)
b. Argument Parser (GCViewerArgsParser)
• Recognizes CLI flags, file lists, export format → passes control to loader or exporter.
c. DataReader Layer (imp/)
• DataReaderFactory chooses the correct DataReader subtype (Sun, IBM, HPUX, JRockit, Unified JVM Logging…).
• DataReaderFacade orchestrates reading and parsing lines into events.
d. Model Loader (ctrl/impl/GCModelLoaderImpl)
• Consumes parsed events → builds a GCModel (model/GCModel) containing timelines, metrics.
e. Controller Layer (ctrl/impl/GCViewerGuiController, GCViewerGuiBuilder)
• Initializes UI, registers listeners, binds model to view.
• Implements user actions (OpenFile, Export, Zoom, Watch, etc.).
f. View Layer (view/)
• Swing components: main window (GCViewerGui), chart panels (ChartPanelView), data tables, dialogs.
• Renderers produce the visual chart elements.
• Model-view binding via listeners and property-change events (view/model packages).
g. Exporters (exp/impl/)
• DataWriterFactory picks CSVDataWriter, PlainDataWriter, PNGDataWriter, SummaryDataWriter, etc.
• Exports model metrics to CSV, PNG, text.
h. Utilities
• Math/statistics helpers (math/), logging (log/), configuration (util), localization.
i. Packaging
• Maven Assembly builds JAR & Mac .app.
• CI/CD directory showcases build scripts but is orthogonal to runtime architecture.
Architectural Patterns & Design Principles
• MVC (Model-View-Controller):
• Model = model/GCModel + events
• View = view/ Swing components
• Controller = ctrl/ actions & GUI builders
• Factory Pattern for DataReaders and DataWriters.
• Facade for parsing (DataReaderFacade).
• Plugin-style extensibility: each new GC log format or export format is a new impl class, registered via factory.
• Separation of Concerns: parsing, modeling, UI, exporting are decoupled.
Final Advice
• Be very detailed: include all 4 layers (parsing, modeling, control, view) plus export.
• factory-based extension points (DataReaderFactory, DataWriterFactory).