Skip to content

Conversation

@jbachorik
Copy link
Collaborator

Summary

Implements complete session state export/import functionality for jfr-shell, enabling users to:

  • Save analysis progress and resume later
  • Share analysis sessions with team members
  • Create reusable analysis templates
  • Document incident investigations

Changes

New Features

  • Session Export: Save complete session state to JSON file

    • Export variables (scalars, maps, lazy queries)
    • Export recording information and metadata
    • Export session settings
    • Optional: include cached query results (--include-results)
    • Row limiting to control file size (--max-rows)
  • Session Import: Restore previously exported sessions

    • Recreate all variables and queries
    • Path remapping for cross-machine sharing (--remap-path)
    • Custom alias assignment (--alias)
    • Pre-populate cached results if included in export

Implementation

  • SessionSnapshot.java - Immutable data model for session state (~200 lines)
  • SessionExporter.java - Export service with JSON serialization (~400 lines)
  • SessionImporter.java - Import service with JSON parsing (~500 lines)
  • SessionExportImportTest.java - Integration tests (2 tests, all passing)

Commands

# Export
export [--include-results] [--max-rows N] [--format json] <path>

# Import  
import [--alias NAME] [--remap-path PATH] <session-file>

Integration

  • Added export/import commands to CommandDispatcher
  • Updated tab completion (CommandCompleter, OptionCompleter)
  • Comprehensive help documentation (help export, help import)

Documentation

  • Updated README.md with feature overview and examples (~100 lines)
  • Updated jfr-shell-tutorial.md with detailed use cases (~140 lines)
  • Updated jfr_shell_usage.md with command reference
  • Updated CLAUDE.md with feature description

Test plan

  • Unit tests for SessionSnapshot serialization
  • Integration tests for export/import roundtrip
  • Manual testing with various variable types
  • All existing tests passing
  • Code formatting applied (spotless)

Testing checklist

Tested scenarios:

  • Export session with scalar, map, and lazy variables
  • Import session and verify variables restored
  • Export with --include-results option
  • Import with --alias option
  • Import with --remap-path for different file location
  • Export/import with session settings preserved
  • Handle missing recording file on import
  • Tab completion for export/import commands

Example usage

# Save analysis
jfr> open recording.jfr --alias analysis
jfr> set threshold = 1000
jfr> set bigReads = events/jdk.FileRead[bytes>${threshold}]
jfr> export my-analysis.json

# Resume later
jfr> import my-analysis.json
jfr> vars  # All variables restored
jfr> show ${bigReads}

Future enhancements (Phase 2)

  • Markdown export format
  • HTML export format with interactive tables
  • Command history capture and replay
  • Bookmarks and annotations
  • Improved JSON parsing with proper library

Notes

  • Phase 1 implements JSON format only (Markdown/HTML in Phase 2)
  • Simplified JSON parsing sufficient for current needs
  • Format version 1.0 with backward compatibility support

🤖 Generated with Claude Code

Implements complete session state export/import functionality allowing users to save and share analysis sessions including variables, queries, and settings.

- Add SessionSnapshot data model for serializable state
- Add SessionExporter service with JSON export support
- Add SessionImporter service with path remapping
- Add export/import commands to CommandDispatcher
- Add comprehensive help documentation
- Add tab completion for new commands
- Add integration tests for roundtrip export/import
- Update all documentation (README, tutorial, usage guide)

Export options: --include-results, --max-rows, --format json
Import options: --alias, --remap-path

Use cases: save progress, share with team, create templates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jbachorik jbachorik added the AI AI-generated code or contributions label Jan 9, 2026
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

Combined JUnit Test Report

  • Total: 14
  • Passed: 13
  • Failures: 0
  • Errors: 0
  • Skipped: 1

HTML Test Reports

Run artifacts: https://github.com/btraceio/jafar/actions/runs/20868508431

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI AI-generated code or contributions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants