Git Product home page Git Product logo

peak_alloc's Introduction

Peak Alloc

Peak Alloc is a dead simple and willingly low overhead allocator for rust which allows you to track (and consult) the amount of memory that is being allocated to your process as well as the maximum amount of memory that has been allocatd to your process over the course of its life.

Note 1:

When I mean that peak alloc is low overhead, I mean that all it ever maintains, is a pair of two atomic usize. So the overhead is low...but there is and overhead because of the atomic number manipulations.

Note 2:

The peak allocator is really just a shim around the system allocator. The bulk of its work is delegated to the system allocator and all PeakAlloc does is to maintain the atomic counters.

Usage

In your Cargo.toml, you should add the following line to your dependencies section.

[dependencies]
peak_alloc = "0.2.0"

Then in your main code, you will simply use it as shown below:

use peak_alloc::PeakAlloc;

#[global_allocator]
static PEAK_ALLOC: PeakAlloc = PeakAlloc;

fn main() {
	// Do your funky stuff...

	let current_mem = PEAK_ALLOC.current_usage_as_mb();
	println!("This program currently uses {} MB of RAM.", current_mem);
	let peak_mem = PEAK_ALLOC.peak_usage_as_gb();
	println!("The max amount that was used {}", peak_mem);
}

peak_alloc's People

Contributors

xgillard avatar luxalpa avatar silas2308 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.