[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-6623":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":24,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":16,"starSnapshotCount":16,"syncStatus":34,"lastSyncTime":35,"discoverSource":36},6623,"coz","plasma-umass\u002Fcoz","plasma-umass","Coz: Causal Profiling","",null,"C",4508,170,65,43,0,3,18,1,28.7,"Other",false,"master",true,[26,27,28,29,30],"causal-inference","optimization","performance-analysis","performance-engineering","profiler","2026-06-12 02:01:27","# Coz: Finding Code that Counts with Causal Profiling\n\nby [Charlie Curtsinger](https:\u002F\u002Fcurtsinger.cs.grinnell.edu\u002F) and [Emery Berger](https:\u002F\u002Femeryberger.com)\n\n[![Rust Crate downloads](https:\u002F\u002Fimg.shields.io\u002Fcrates\u002Fd\u002Fcoz?logo=rust&link=https%3A%2F%2Fcrates.io%2Fcrates%2Fcoz)](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fcoz)\n\nCoz is a profiler for native code (C\u002FC++\u002FRust) that unlocks\noptimization opportunities missed by traditional profilers. Coz\nemploys a novel technique called *causal profiling* that measures\noptimization potential. It predicts what the impact of optimizing code\nwill have on overall throughput or latency.\n\nProfiles generated by Coz show the \"bang for buck\" of optimizing a\nline of code in an application. In the below profile, almost every\neffort to optimize the performance of this line of code directly leads\nto an increase in overall performance, making it an excellent\ncandidate for optimization efforts.\n\n![Example Coz profile](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fcoz\u002Fblob\u002Fmaster\u002Fexample-coz-output.png)\n\nCoz's measurement matches developers' assumptions about profilers: that optimizing highly-ranked code will have the greatest impact on performance. Causal profiling measures optimization potential for serial, parallel, and asynchronous programs without instrumentation of special handling for library calls and concurrency primitives. Instead, a causal profiler uses performance experiments to predict the effect of optimizations. This allows the profiler to establish causality: \"optimizing function X will have effect Y,\" exactly the measurement developers had assumed they were getting all along.\n\nFull details of Coz are available in our paper, [Coz: Finding Code\nthat Counts with Causal Profiling\n(pdf)](http:\u002F\u002Farxiv.org\u002Fpdf\u002F1608.03676v1.pdf), SOSP 2015, October 2015\n(recipient of a Best Paper Award).\n\n[![Coz presentation at SOSP](http:\u002F\u002Fimg.youtube.com\u002Fvi\u002FjE0V-p1odPg\u002F0.jpg)](http:\u002F\u002Fwww.youtube.com\u002Fwatch?v=jE0V-p1odPg&t=0m28s \"Coz presentation at SOSP\")\n\n## Installation\n\n### Pre-built Packages (Recommended)\n\nDownload the latest release for your platform from the [GitHub Releases page](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fcoz\u002Freleases).\n\n**Debian\u002FUbuntu (`.deb`):**\n```shell\n# Download the .deb for your architecture (amd64 or arm64)\nsudo dpkg -i coz_VERSION_amd64.deb\n```\n\n**Fedora\u002FRHEL\u002FCentOS (`.rpm`):**\n```shell\n# Download the .rpm for your architecture (x86_64 or aarch64)\nsudo rpm -i coz-VERSION-1.x86_64.rpm\n```\n\n**Generic Linux (tarball):**\n```shell\ntar xzf coz-VERSION-linux-x86_64.tar.gz\ncd coz-VERSION-linux-x86_64\nsudo .\u002Finstall.sh        # Installs to \u002Fusr\u002Flocal by default\nsudo ldconfig\n```\n\n### Requirements\n\nCoz works on Linux systems (running version 2.6.32 or later, with support\nfor the `perf_event_open` system call) and macOS (using Apple's kperf framework).\nBoth platforms require a Python 3.x interpreter.\n\n**macOS Note**: The macOS port uses Apple's private kperf framework for sampling.\nThis requires either running with elevated privileges or adjusting System Integrity\nProtection settings. The kperf API is undocumented and may change in future macOS versions.\n\n## Libraries\u002FWrappers\n\nBy default, Coz works for C, C++, and Rust programs. It has been ported or\nhas wrappers for several other languages, listed below:\n\n| Language      | Link |\n| ----------- | -----------  \n| Java   | JCoz: https:\u002F\u002Fgithub.com\u002FDecave\u002FJCoz|\n| Go     | Cozgo: https:\u002F\u002Fgithub.com\u002Furjitbhatia\u002Fcozgo|\n| Swift  | Swift Coz: https:\u002F\u002Fgithub.com\u002Ffuncmike\u002Fswift-coz |\n\n## Building Coz From Source\n\n### Install build prerequisites\n\nOn Debian\u002FUbuntu:\n\n```shell\nsudo apt-get install -y build-essential cmake pkg-config\n```\n\nlibelfin is fetched automatically during the build, so no additional dependencies are required.\n\n### Configure and build\n\nUse the standard out-of-source workflow (shown with `build\u002F`, but any directory works):\n\n```shell\ncmake -S . -B build          # Configure (defaults to Release with debug info)\ncmake --build build -j       # Build libcoz and the CLI\nsudo cmake --install build   # Install to \u002Fusr\u002Flocal (or CMAKE_INSTALL_PREFIX)\nsudo ldconfig                # Update shared library cache\n```\n\nBefore running Coz on Linux, relax `perf_event_paranoid` so sampling works:\n\n```shell\nsudo sh -c 'echo 1 >\u002Fproc\u002Fsys\u002Fkernel\u002Fperf_event_paranoid'\n```\n\n### Building the Benchmarks\n\nThe benchmark suite is off by default because it pulls in extra dependencies. Enable it when configuring:\n\n```shell\ncmake -S . -B build-bench -DBUILD_BENCHMARKS=ON\ncmake --build build-bench -j\n```\n\nWhen `BUILD_BENCHMARKS` is set, CMake automatically switches the build type to `RelWithDebInfo` (or keeps `Debug`) so DWARF line tables are available. Benchmark binaries live under `build-bench\u002Fbenchmarks\u002F\u003Cname>\u002F`.\n\nA number of the benchmarks are from the Phoenix benchmark suite, and several require data files. These are available for download via links in the README from [the Phoenix repository](https:\u002F\u002Fgithub.com\u002Fkozyraki\u002Fphoenix).\n\n### Viewer\n\nAfter profiling, run `coz plot` to automatically open your results in the browser. To view a specific profile, use `coz plot -i \u002Fpath\u002Fto\u002Fprofile.coz`.\n\nYou may need to adjust the \"Minimum Points\" slider to see results if the profile has limited data.\n\n#### AI-Powered Optimization Suggestions\n\nThe viewer includes an AI assistant that analyzes causal profiling results and suggests concrete optimizations. Click the magic wand icon on any plot to get context-aware suggestions based on the profiling data and source code.\n\nSupported LLM providers:\n- **Anthropic** (Claude) — set `ANTHROPIC_API_KEY`\n- **OpenAI** (GPT-4o, o3, etc.) — set `OPENAI_API_KEY`\n- **Amazon Bedrock** — set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`\n- **Ollama** — local models, no API key required\n\nThe viewer dynamically fetches available models from each provider and caches them locally. Provider settings, API keys, and model selections persist across sessions via cookies.\n\n## Using Coz\nUsing Coz requires a small amount of setup, but you can jump ahead to the section on the included [sample applications](#sample-applications) in this repository if you want to try Coz right away.\n\nTo run your program with Coz, you will need to build it with debug information (`-g`). Coz now supports modern DWARF versions (including DWARF 5), so you can use your compiler's default debug format. You do not need to include debug symbols in the main executable: coz uses the same procedure as `gdb` to locate debug information for stripped binaries.\n\nOnce you have your program built with debug information, you can run it with Coz using the command `coz run {coz options} --- {program name and arguments}`. But, to produce a useful profile you need to decide which part(s) of the application you want to speed up by specifying one or more progress points.\n\n### Profiling Modes\nCoz departs from conventional profiling by making it possible to view the effect of optimizations on both throughput and latency. To profile throughput, you must specify a progress point. To profile latency, you must specify a pair of progress points.\n\n#### Throughput Profiling: Specifying Progress Points\nTo profile throughput you must indicate a line in the code that corresponds to the end of a unit of work. For example, a progress point could be the point at which a transaction concludes, when a web page finishes rendering, or when a query completes. Coz then measures the rate of visits to each progress point to determine any potential optimization's effect on throughput.\n\nTo place a progress point, include `coz.h` (under the `include` directory in this repository) and add the `COZ_PROGRESS` macro to at least one line you would like to execute more frequently. Don't forget to link your program with libdl: use the `-ldl` option.\n\nBy default, Coz uses the source file and line number as the name for your progress points. If you use `COZ_PROGRESS_NAMED(\"name for progress point\")` instead, you can provide an informative name for your progress points. This also allows you to mark multiple source locations that correspond to the same progress point.\n\n#### Latency Profiling: Specifying Progress Points\nTo profile latency, you must place two progress points that correspond to the start and end of an event of interest, such as when a transaction begins and completes. Simply  mark the beginning of a transaction with the `COZ_BEGIN(\"transaction name\")` macro, and the end with the `COZ_END(\"transaction name\")` macro. Unlike regular progress points, you always need to specify a name for your latency progress points. Don't forget to link your program with libdl: use the `-ldl` option.\n\nWhen coz tests a hypothetical optimization it will report the effect of that optimization on the average latency between these two points. Coz can track this information without any knowledge of individual transactions thanks to [Little's Law](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FLittle%27s_law).\n\n### AI-Suggested Progress Points (`coz suggest-points`)\nIf you're new to Coz or working in an unfamiliar codebase, the hardest part is deciding *where* to place progress points. The `coz suggest-points` subcommand uses an LLM agent to read your source, identify what counts as a unit of work, and propose concrete `COZ_PROGRESS_NAMED` \u002F `COZ_BEGIN` \u002F `COZ_END` placements. Each proposal is shown with a rationale and a unified diff; nothing is written until you confirm.\n\n```shell\nexport ANTHROPIC_API_KEY=...\n\ncoz suggest-points src\u002F                         # explore src\u002F, then prompt to apply\ncoz suggest-points --dry-run src\u002F               # print diffs only, no prompt\ncoz suggest-points --apply src\u002F                 # skip the prompt, apply everything\ncoz suggest-points --kind latency src\u002F          # only propose COZ_BEGIN\u002FCOZ_END pairs\ncoz suggest-points --hint \"HTTP server\" src\u002F    # give the agent a domain hint\n```\n\nThe agent has read-only tools (`list_files`, `read_file`, `grep`) scoped to the paths you pass, and emits one proposal per call. When you accept a proposal, the macro is inserted at the chosen line (matching surrounding indentation), `#include \"coz.h\"` is added if missing, and the original file is backed up to `*.coz.bak`. Latency points are only applied in matched `BEGIN`\u002F`END` pairs. Files that already contain Coz macros are left alone.\n\n#### Choosing an LLM provider\n\n`coz suggest-points` supports the same providers as the viewer's optimization assistant. Pick one with `--provider`; the agentic tool-use loop is used on all of them, so results are comparable across providers (quality depends on how well the chosen model follows tool-use instructions).\n\n| Provider | Flag | Credentials | Default model |\n| --- | --- | --- | --- |\n| Anthropic (Claude) | `--provider anthropic` *(default)* | `ANTHROPIC_API_KEY` (or `--api-key`) | `claude-opus-4-7` |\n| OpenAI (GPT-4o, o3, …) | `--provider openai` | `OPENAI_API_KEY` (or `--api-key`) | `gpt-4o` |\n| Amazon Bedrock | `--provider bedrock` | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` (optional `AWS_SESSION_TOKEN`); region via `AWS_REGION` \u002F `AWS_DEFAULT_REGION` or `--region`. Any credential source that boto3's default chain picks up (IAM role, `~\u002F.aws\u002Fcredentials`, SSO) also works. Requires `pip install boto3`. | `anthropic.claude-opus-4-20250514-v1:0` |\n| Ollama (local) | `--provider ollama` | No key. Endpoint via `OLLAMA_HOST` or `--ollama-host` (defaults to `http:\u002F\u002Flocalhost:11434`). Use a tool-capable model (e.g. `llama3.1`, `qwen2.5`). | `llama3.1` |\n\nExamples:\n\n```shell\n# Anthropic (default)\nexport ANTHROPIC_API_KEY=...\ncoz suggest-points src\u002F\n\n# OpenAI\nexport OPENAI_API_KEY=...\ncoz suggest-points --provider openai --model gpt-4o src\u002F\n\n# Amazon Bedrock — uses the boto3 credential chain\nexport AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... AWS_REGION=us-west-2\ncoz suggest-points --provider bedrock \\\n                   --model anthropic.claude-opus-4-20250514-v1:0 src\u002F\n\n# Ollama on a local server (no API key)\ncoz suggest-points --provider ollama --model llama3.1 src\u002F\n```\n\nYou can also pass `--api-key \u003Ckey>` inline for Anthropic or OpenAI instead of exporting an env var, and `--model \u003Cid>` to select a specific model on any provider. See `coz suggest-points --help` for the full option list (`--include`, `--exclude`, `--max-points`, `--region`, `--ollama-host`, etc.).\n\n### Specifying Progress Points on the Command Line\nCoz has command line options to specify progress points when profiling the application instead of modifying its source. This feature is currently disabled because it did not work particularly well. Adding support for better command line-specified progress points is planned in the near future.\n\n## Processing Results\nRun `coz plot` to view your profile in the browser. Use `coz plot --text` for terminal output, or `coz plot --text --verbose` for detailed data points.\n\n## Sample Applications\nThe `benchmarks\u002F` directory includes several small programs with progress points already wired up. Once you configure with `-DBUILD_BENCHMARKS=ON` (see above), you can run them straight from the build tree:\n\n```shell\n.\u002Fbuild-bench\u002Fbenchmarks\u002Ftoy\u002Ftoy\ncoz run --- .\u002Fbuild-bench\u002Fbenchmarks\u002Ftoy\u002Ftoy\n```\n\nThese programs may need several runs before Coz accumulates enough samples to emit a useful profile. Run `coz plot` to view the results.\n\n## CMake\nWhen you install coz it installs a cmake config file. To add coz to a cmake project simply use the command `find_package(coz-profiler)`. This will import a target for the library and includes called `coz::coz` and a target for the coz binary `coz::profiler`. For guidance on how to use these targets refer to the CMake documentation.\n\n## Limitations\nCoz currently does not support interpreted or JIT-compiled languages such as Python, Ruby, or JavaScript. Interpreted languages will likely not be supported at any point, but support for JIT-compiled languages that produce debug information could be added in the future.\n\n## License\nAll source code is licensed under the BSD 2-clause license unless otherwise indicated. See LICENSE.md for details.\n\nSample applications (in the `benchmarks` directory) include several [Phoenix](https:\u002F\u002Fgithub.com\u002Fkozyraki\u002Fphoenix) programs and [pbzip2](http:\u002F\u002Fcompression.ca\u002Fpbzip2\u002F), which are licensed separately and included with this release for convenience.\n","Coz 是一个针对原生代码（C\u002FC++\u002FRust）的性能分析工具，它通过因果分析技术识别出传统分析器可能忽略的优化机会。核心功能包括测量优化潜力并预测优化某段代码对整体吞吐量或延迟的影响，从而帮助开发者找到最具优化价值的代码部分。该工具适用于需要深入性能调优的场景，无论是串行、并行还是异步程序，都能有效工作，无需对库调用或并发原语进行特殊处理。Coz 通过执行性能实验来建立因果关系，即“优化函数X会产生效果Y”，这与开发者对性能分析器的期望一致。",2,"2026-06-11 03:07:57","top_language"]