{"id":13995287,"url":"https://github.com/rustwasm/wasm-tracing-allocator","last_synced_at":"2025-05-07T15:08:14.792Z","repository":{"id":52414507,"uuid":"185870864","full_name":"rustwasm/wasm-tracing-allocator","owner":"rustwasm","description":"A global allocator for Wasm that traces allocations and deallocations for debugging purposes.","archived":false,"fork":false,"pushed_at":"2021-04-29T21:09:43.000Z","size":63,"stargazers_count":106,"open_issues_count":3,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T15:08:11.462Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.rs/wasm-tracing-allocator","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rustwasm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-09T20:59:04.000Z","updated_at":"2025-04-30T14:39:08.000Z","dependencies_parsed_at":"2022-08-31T01:22:35.660Z","dependency_job_id":null,"html_url":"https://github.com/rustwasm/wasm-tracing-allocator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwasm-tracing-allocator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwasm-tracing-allocator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwasm-tracing-allocator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwasm-tracing-allocator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rustwasm","download_url":"https://codeload.github.com/rustwasm/wasm-tracing-allocator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252902614,"owners_count":21822261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-09T14:03:20.174Z","updated_at":"2025-05-07T15:08:14.763Z","avatar_url":"https://github.com/rustwasm.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n  \u003ch1\u003e\u003ccode\u003ewasm-tracing-allocator\u003c/code\u003e\u003c/h1\u003e\n\n  \u003cstrong\u003eA global allocator for Wasm that traces allocations and deallocations for debugging purposes.\u003c/strong\u003e\n\n  \u003cp\u003e\n    \u003ca href=\"https://crates.io/crates/wasm-tracing-allocator\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/wasm-tracing-allocator.svg?style=flat-square\" alt=\"Crates.io version\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/wasm-tracing-allocator\"\u003e\u003cimg src=\"https://img.shields.io/crates/d/wasm-tracing-allocator.svg?style=flat-square\" alt=\"Download\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://docs.rs/wasm-tracing-allocator\"\u003e\u003cimg src=\"https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square\" alt=\"docs.rs docs\" /\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\n  \u003ch3\u003e\n    \u003ca href=\"https://docs.rs/wasm-tracing-allocator\"\u003eAPI Docs\u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/rustwasm/wasm-tracing-allocator/blob/master/CONTRIBUTING.md\"\u003eContributing\u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://discordapp.com/channels/442252698964721669/443151097398296587\"\u003eChat\u003c/a\u003e\n  \u003c/h3\u003e\n\n  \u003csub\u003eBuilt with 🦀🕸 by \u003ca href=\"https://rustwasm.github.io/\"\u003eThe Rust and WebAssembly Working Group\u003c/a\u003e\u003c/sub\u003e\n\u003c/div\u003e\n\n\n### About\n\n`wasm-tracing-allocator` enables you to better debug and analyze memory leaks\nand invalid frees in an environment where we don't have access to the\nconventional tools like Valgrind. The tracing hooks are safely implemented in\nJS, outside the Wasm module and its linear memory, to ensure that the tracing\ncode doesn't perturb results.\n\n### Table of Contents\n\n* [Enabling the Tracing Allocator](#enabling-the-tracing-allocator)\n* [Analyzing and Debugging](#analyzing-and-debugging)\n\n### Enabling the Tracing Allocator\n\nFirst, add `wasm-tracing-allocator` to your `Cargo.toml`'s dependency list:\n\n```toml\n[dependencies]\nwasm-tracing-allocator = \"0.1.0\"\n```\n\nNext, configure `wasm_tracing_allocator::WasmTracingAllocator` as the global\nallocator:\n\n```rust\n// src/lib.rs\n\nuse std::alloc::System;\nuse wasm_tracing_allocator::WasmTracingAllocator;\n\n#[global_allocator]\nstatic GLOBAL_ALLOCATOR: WasmTracingAllocator\u003cSystem\u003e = WasmTracingAllocator(System);\n```\n\nFinally, make the JS implementations of the tracing hooks are available for your\nWasm module to import:\n\n* On the Web, add this script *before* your Wasm module is instantiated:\n\n  ```html\n  \u003cscript src=\"https://unpkg.com/wasm-tracing-allocator@0.1.0/js/hooks.js\"\u003e\u003c/script\u003e\n  ```\n\n* On Node.js, require the hooks *before* your Wasm module is instantiated:\n\n  ```js\n  require(\"wasm-tracing-allocator\");\n  ```\n\n### Analyzing and Debugging\n\nUse your developer tools console to invoke methods of the global\n`WasmTracingAllocator` object to get analyses about allocations and\ndeallocations.\n\nThe output is typically rendered with `console.table`:\n\n[![Example output](https://raw.githubusercontent.com/rustwasm/wasm-tracing-allocator/master/live-allocations-dump.png)](https://raw.githubusercontent.com/rustwasm/wasm-tracing-allocator/master/live-allocations-dump.png)\n\n#### `WasmTracingAllocator.dumpLiveAllocations`\n\nDump a table of live allocations to the console.\n\n```js\nWasmTracingAllocator.dumpLiveAllocations({\n  keyLabel: String,\n  valueLabel: String,\n  getKey: Object =\u003e any,\n  getValue: Object =\u003e Number,\n});\n```\n\n* `keyLabel`: Optional. The string label used to describe the keys column in the\n  table.\n\n* `valueLabel`: Optional. The string label used to describe the values column in\n  the table.\n\n* `getKey`: Optional. Function from an allocation entry object to anything. The\n  table will group and aggregate entries by their keys. Defaults to the stack at\n  the time of the allocation.\n\n* `getValue`: Optional. Function from an allocation entry object to a\n  number. The values for all entries with the same key are summed. Defaults to\n  the byte size of each allocation; a potential alternative would be to ignore\n  the argument and return `1` to count the number of allocations instead.\n\n#### `WasmTracingAllocator.dumpInvalidFrees`\n\nDump a table of invalid frees (double frees, frees of things that were never\nallocated, etc...) to the console.\n\n```js\nWasmTracingAllocator.dumpInvalidFrees({\n  keyLabel: String,\n  valueLabel: String,\n  getKey: Object =\u003e any,\n  getValue: Object =\u003e Number,\n});\n```\n\n* `keyLabel`: Optional. The string label used to describe the keys column in the\n  table.\n\n* `valueLabel`: Optional. The string label used to describe the values column in\n  the table.\n\n* `getKey`: Optional. Function from an invalid free entry object to anything. The\n  table will group and aggregate entries by their keys. Defaults to the stack at\n  the time of the deallocation.\n\n* `getValue`: Optional. Function from an invalid free entry object to a\n  number. The values for all entries with the same key are summed. Defaults to\n  counting the number of invalid frees.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustwasm%2Fwasm-tracing-allocator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustwasm%2Fwasm-tracing-allocator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustwasm%2Fwasm-tracing-allocator/lists"}