An Emacs plugin that analyzes OCaml compiler output to highlight memory allocation points in source code.
- Allocation Highlighting: Highlights memory allocation points in OCaml source code
- Virtual Text: Shows allocation details (block count, tag) as overlay text
- Smart File Selection: Use minibuffer completion to select .cmx.dump files
- Customizable: Configurable highlighting faces and options
- Clone or download this repository
- Add the directory to your Emacs
load-path
- Require the package in your init file:
(add-to-list 'load-path "/path/to/alloc-scan.el")
(require 'alloc-scan)
If using use-package
:
(use-package alloc-scan
:load-path "/path/to/alloc-scan.el"
:commands (alloc-scan alloc-scan-file alloc-scan-clear)
:bind (("C-c a s" . alloc-scan)
("C-c a f" . alloc-scan-file)
("C-c a c" . alloc-scan-clear)))
M-x alloc-scan
- Scan current buffer for allocations- Uses minibuffer completion to select a .cmx.dump file
- Highlights allocation points in the current buffer
M-x alloc-scan-file
- Scan a specific file for allocations- Prompts for a source file to scan
- Uses minibuffer completion to select a .cmx.dump file
- Opens the source file and highlights allocations
M-x alloc-scan-clear
- Clear all allocation highlights in the current buffer
- Compile your OCaml project with allocation tracking enabled
- Use
M-x alloc-scan
in an OCaml source buffer - Select the appropriate
.cmx.dump
file from the minibuffer prompt - Allocation points will be highlighted with virtual text showing details
alloc-scan-highlight-style
- Style of highlighting (default:'box
)alloc-scan-highlight-color
- Color for highlighting (default:"#cccccc"
)alloc-scan-show-virtual-text
- Whether to show allocation details as virtual text (default:t
)alloc-scan-virtual-text-face
- Face used for virtual text (default:font-lock-comment-face
)
The plugin supports several highlighting styles:
- =’box= - Border outline around allocation (default)
- =’underline= - Underline the allocation text
- =’background= - Light background color
- =’bold= - Bold text with colored foreground
- =’custom= - Use custom face definition
;; Subtle grey outline (recommended)
(setq alloc-scan-highlight-style 'box
alloc-scan-highlight-color "#999999")
;; Very light grey outline
(setq alloc-scan-highlight-style 'box
alloc-scan-highlight-color "#cccccc")
;; Red outline for high visibility
(setq alloc-scan-highlight-style 'box
alloc-scan-highlight-color "#ff6b6b")
;; Subtle grey underline
(setq alloc-scan-highlight-style 'underline
alloc-scan-highlight-color "#aaaaaa")
;; Blue underline
(setq alloc-scan-highlight-style 'underline
alloc-scan-highlight-color "#4dabf7")
;; Light yellow background
(setq alloc-scan-highlight-style 'background
alloc-scan-highlight-color "#fffacd")
;; Very light grey background
(setq alloc-scan-highlight-style 'background
alloc-scan-highlight-color "#f8f9fa")
;; Light pink background
(setq alloc-scan-highlight-style 'background
alloc-scan-highlight-color "#ffe0e6")
;; Bold dark grey text
(setq alloc-scan-highlight-style 'bold
alloc-scan-highlight-color "#666666")
;; Bold blue text
(setq alloc-scan-highlight-style 'bold
alloc-scan-highlight-color "#1971c2")
;; Use the built-in custom face (can be customized via M-x customize-face)
(setq alloc-scan-highlight-style 'custom)
;; Or define your own custom face
(defface my-alloc-highlight
'((t (:box (:line-width 2 :color "#ff9500" :style nil)
:background "#fff3cd")))
"Custom face for allocation highlighting.")
(setq alloc-scan-highlight-style 'custom)
(setq alloc-scan-highlight-face 'my-alloc-highlight)
For an interactive way to customize the plugin:
M-x customize-group RET alloc-scan RET
(use-package alloc-scan
:load-path "/path/to/alloc-scan.el"
:custom
(alloc-scan-highlight-style 'box)
(alloc-scan-highlight-color "#999999")
(alloc-scan-show-virtual-text t)
(alloc-scan-virtual-text-face 'font-lock-doc-face)
:bind
(("C-c a s" . alloc-scan)
("C-c a f" . alloc-scan-file)
("C-c a c" . alloc-scan-clear)))
After changing settings, clear existing highlights and rescan:
M-x alloc-scan-clear RET
M-x alloc-scan RET
- File Discovery: The plugin automatically searches for .cmx.dump files in your project’s
_build
directory - File Selection: Uses minibuffer completion to select from available dump files
- Parsing: Parses allocation information from the dump file using regex patterns
- Highlighting: Creates overlays in the source buffer to highlight allocation points
- Virtual Text: Shows allocation details (block count and tag) as overlay text
The plugin includes comprehensive tests located in the test/
directory. See test/README.org
for detailed testing instructions.
- Emacs 25.1 or later
- OCaml project with compiler dump files (
.cmx.dump
)
To generate the necessary .cmx.dump files for your OCaml project:
# Build with allocation tracking
dune build --profile dev
# Or use ocamlopt directly with dump flags
ocamlopt -dump-cmm your_file.ml
The plugin will look for .cmx.dump
files in your project’s _build
directory structure.
- Add jump to cmm dump file