• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A global allocator for Wasm that traces allocations and deallocations for debugging purposes.

wasm-tracing-allocator

A global allocator for Wasm that traces allocations and deallocations for debugging purposes.

Crates.io version Download docs.rs docs

Built with 🦀🕸 by The Rust and WebAssembly Working Group

About

wasm-tracing-allocator enables you to better debug and analyze memory leaks and invalid frees in an environment where we don't have access to the conventional tools like Valgrind. The tracing hooks are safely implemented in JS, outside the Wasm module and its linear memory, to ensure that the tracing code doesn't perturb results.

Table of Contents

Enabling the Tracing Allocator

First, add wasm-tracing-allocator to your Cargo.toml's dependency list:

[dependencies]
wasm-tracing-allocator = "0.1.0"

Next, configure wasm_tracing_allocator::WasmTracingAllocator as the global allocator:

// src/lib.rs

use std::alloc::System;
use wasm_tracing_allocator::WasmTracingAllocator;

#[global_allocator]
static GLOBAL_ALLOCATOR: WasmTracingAllocator<System> = WasmTracingAllocator(System);

Finally, make the JS implementations of the tracing hooks are available for your Wasm module to import:

  • On the Web, add this script before your Wasm module is instantiated:

    <script src="https://unpkg.com/[email protected]/js/hooks.js"></script>
  • On Node.js, require the hooks before your Wasm module is instantiated:

    require("wasm-tracing-allocator");

Analyzing and Debugging

Use your developer tools console to invoke methods of the global WasmTracingAllocator object to get analyses about allocations and deallocations.

The output is typically rendered with console.table:

Example output

WasmTracingAllocator.dumpLiveAllocations

Dump a table of live allocations to the console.

WasmTracingAllocator.dumpLiveAllocations({
  keyLabel: String,
  valueLabel: String,
  getKey: Object => any,
  getValue: Object => Number,
});
  • keyLabel: Optional. The string label used to describe the keys column in the table.

  • valueLabel: Optional. The string label used to describe the values column in the table.

  • getKey: Optional. Function from an allocation entry object to anything. The table will group and aggregate entries by their keys. Defaults to the stack at the time of the allocation.

  • getValue: Optional. Function from an allocation entry object to a number. The values for all entries with the same key are summed. Defaults to the byte size of each allocation; a potential alternative would be to ignore the argument and return 1 to count the number of allocations instead.

WasmTracingAllocator.dumpInvalidFrees

Dump a table of invalid frees (double frees, frees of things that were never allocated, etc...) to the console.

WasmTracingAllocator.dumpInvalidFrees({
  keyLabel: String,
  valueLabel: String,
  getKey: Object => any,
  getValue: Object => Number,
});
  • keyLabel: Optional. The string label used to describe the keys column in the table.

  • valueLabel: Optional. The string label used to describe the values column in the table.

  • getKey: Optional. Function from an invalid free entry object to anything. The table will group and aggregate entries by their keys. Defaults to the stack at the time of the deallocation.

  • getValue: Optional. Function from an invalid free entry object to a number. The values for all entries with the same key are summed. Defaults to counting the number of invalid frees.

More Repositories

1

wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
Rust
7,655
star
2

wasm-pack

📦✨ your favorite rust -> wasm workflow tool!
Rust
6,173
star
3

gloo

A modular toolkit for building fast, reliable Web applications and libraries with Rust and WASM
Rust
1,773
star
4

book

The Rust and WebAssembly Book
Handlebars
1,734
star
5

team

A point of coordination for all things Rust and WebAssembly
1,436
star
6

twiggy

Twiggy🌱 is a code size profiler
Rust
1,254
star
7

wee_alloc

The Wasm-Enabled, Elfin Allocator
Rust
666
star
8

awesome-rust-and-webassembly

Awesome Rust and WebAssembly projects, libraries, tools, and resources
627
star
9

wasm-pack-template

a template for starting a rust-wasm project to be used with wasm-pack
Rust
618
star
10

rust-webpack-template

Kickstart your Rust, WebAssembly, and Webpack project!
JavaScript
562
star
11

create-wasm-app

npm init template for consuming rustwasm pkgs
JavaScript
492
star
12

walrus

Walrus is a WebAssembly transformation library 🌊🐘
Rust
377
star
13

console_error_panic_hook

A panic hook for wasm32-unknown-unknown that logs panics with console.error
Rust
317
star
14

wasm_game_of_life

A Rust and WebAssembly tutorial implementing the Game of Life
Rust
276
star
15

wasm-snip

`wasm-snip` replaces a WebAssembly function's body with an `unreachable`
Rust
218
star
16

rust-parcel-template

Kickstart your Rust, WebAssembly, and Parcel project!
Rust
156
star
17

deprecated_rust_wasm_template

Deprecated in favor of rustwasm/wasm-pack-template or rustwasm/rust-webpack-template
Shell
102
star
18

rustwasm.github.io

Rust and WebAssembly website! 🦀 + 🕸
HTML
68
star
19

weedle

A WebIDL Parser
WebIDL
43
star
20

rfcs

The Rust and WebAssembly RFCs
Shell
39
star
21

wasm-webidl-bindings

Read, write, and manipulate the Wasm WebIDL bindings custom section
Rust
38
star
22

binary-install

Rust
10
star
23

wasm-weight-tracker

Tracking Rust and WebAssembly sizes over time
Rust
10
star
24

hello-wasm-bindgen

a presentation introducing wasm-bindgen
JavaScript
8
star
25

sfhtml5-rust-and-wasm

JavaScript
4
star
26

.github

Default issue templates, CONTRIBUTING.md, etc...
2
star
27

wasm-weight-tracker-data

WIP
1
star