$ show plasma-umass/coz
Coz is a causal profiler for native code (C/C++, Rust, Go, Swift, Java) that uses virtual speedup experiments to identify which lines of code, if optimized, would most improve program throughput or latency. It operates by injecting a shared library (libcoz) via LD_PRELOAD or DYLD_INSERT_LIBRARIES, interposing synchronization primitives to track blocking and apply controlled delays on non-selected threads. The profiler outputs a JSON Lines profile that can be visualized with a built-in web viewer (D3.js scatter plots with loess smoothing) or analyzed via CLI. It includes an AI-assisted feature for suggesting progress point placement and optimization advice. The architecture is a hybrid: a core runtime library in C++ with language bindings for Rust, Go, Swift, and Java (JVMTI agent), plus a Python CLI that orchestrates profiling, visualization, and LLM integration. The project is a research artifact from UMass Amherst, published at SOSP 2015, and remains actively developed with modern features like streaming AI support.
The LLM identified 3 files worth highlighting for reuse:
A lock-free, fixed-capacity, open-addressing hash map with linear probing, designed for thread-safe key-value storage in a shared library context. Uses C++11 atomics (compare_exchange_weak, memory_order) for lock-free insertion and lookup. Demonstrates a high-craftsmanship implementation of a concurrent data structure that avoids locks entirely, making it suitable for performance-critical profiling code. The map is templated, generic, and has no dependencies on the rest of the codebase beyond atomic operations, making it directly reusable in any C++ project needing a small, fast, lock-free associative array.
A clean Go package that provides the Coz profiling API (Progress, Begin, End, Scope, Counter) using cgo to call into the libcoz runtime via dlsym. Caches resolved function pointers in a sync.Map to avoid repeated dlsym calls. Gracefully degrades to no-ops when libcoz is not loaded. The design is a model for wrapping a native library in Go with minimal dependencies and thread-safe caching. The pattern of using a shim C file (coz_shim.c) to resolve symbols and then exposing them through a Go API is reusable for any system that needs optional runtime instrumentation.
A TypeScript module that parses Coz profile data (JSON Lines or legacy tab-separated) and renders interactive scatter plots using D3.js v3. Computes speedup values via linear regression (R²), draws loess-smoothed trendlines using the science.js library, and provides tooltips for each data point. Implements a streaming AI optimization endpoint with progress bar and abort support. The module is self-contained (depends only on D3 and science.js) and could be adapted for other profiling tools that output similar experiment data. Its use of D3 for interactive, data-driven documents and its clean separation of parsing, calculation, and rendering make it a reusable visualization component.