Ben Greenman
Ben Greenman

Reputation: 2002

Memory consumption in Racket

Is there a simple way to measure a Racket program's memory use? I'm trying to run many programs in parallel and I want to make sure each gets enough RAM.

Upvotes: 3

Views: 953

Answers (1)

Leif Andersen
Leif Andersen

Reputation: 22342

There are a few ways to track the memory used by Racket programs from within Racket itself.

  1. current-memory-use Tracks the amount of memory that is reachable.

  2. dump-memory-stats prints a report of your current error port. What it prints out will depend on your installation.

  3. vector-set-performance-stats! takes a mutable vector, and fills it with a bunch of runtime stats for your program, including memory usage. And even memory usage that you can't get from current-memory-usage.

There's also a few options that don't use Racket to track memory. For example, the top command can show you how much memory your racket process uses. If you use this technique, be careful to ensure you are tracking the memory of all of the subprocesses that the racket process may have spawned. Also, this technique will vary greatly based on the OS you are using.

Upvotes: 5

Related Questions