mwrap.git  about / heads / tags
LD_PRELOAD malloc wrapper + line stats for Ruby
$ git log --pretty=format:'%h %s (%cs)%d' v1.0.0 --
f28676e mwrap 1.0.0 (2018-07-02)
	(tag: v1.0.0)
61ee1c4 documentation updates (2018-07-02)
a47e497 release GVL for most Ruby operations (2018-07-02)
53dfbf1 bin/mwrap: do not add redundant paths to LD_PRELOAD (2018-07-02)
387d17c favor inline helpers instead of magic numbers (2018-07-02)
50c83d9 require Userspace RCU to track non-GVL allocations (2018-07-02)
c0a29c0 initial (2018-07-02)

$ git cat-file blob v1.0.0:README
= mwrap - LD_PRELOAD malloc wrapper + line stats for Ruby

mwrap is designed to answer the question:

   Which lines of Ruby are hitting malloc the most?

mwrap wraps all malloc, calloc, and realloc calls to trace the Ruby
source location of such calls and bytes allocated at each callsite.
This functionality may be expanded in the future.

It does not track allocation lifetimes, or frees, however.  It works
best for allocations under GVL, but tries to track numeric caller
addresses for allocations made without GVL so you can get an idea of how
much memory usage certain extensions and native libraries use.

It requires the concurrent lock-free hash table from the
Userspace RCU project: https://liburcu.org/

It does not require recompiling or rebuilding Ruby, but only supports
Ruby trunk (2.6.0dev+) on a few platforms:

* GNU/Linux
* FreeBSD (tested 11.1)

It may work on NetBSD, OpenBSD and DragonFly BSD.

== Install

	# FreeBSD: pkg install liburcu

	# Debian-based systems: apt-get liburcu-dev

	# Install mwrap via RubyGems.org
	gem install mwrap

== Usage

mwrap works as an LD_PRELOAD and supplies a mwrap RubyGem executable to
improve ease-of-use.  You can set dump_fd: in the MWRAP environment
variable to dump the results to a certain file descriptor at exit:

	# Dump results to stderr at exit:
	MWRAP=dump_fd:2 mwrap RUBY_COMMAND

You may also set dump_path to append to a log file:

	MWRAP=dump_path:/path/to/log mwrap RUBY_COMMAND

You may also `require 'mwrap'' in your Ruby code and use
Mwrap.dump, Mwrap.clear, Mwrap.reset, Mwrap.each, etc.

However, mwrap MUST be loaded via LD_PRELOAD to have any
effect in tracking malloc use.

The output of the mwrap dump is a text file with 3 columns:

	total_bytes	call_count	location

Where location is a Ruby source location (if made under GVL)
or an address retrieved by backtrace_symbols(3)

== Known problems

* 32-bit machines are prone to overflow (WONTFIX)

== Mail archives and list:

	https://80x24.org/mwrap-public/
	nntp://80x24.org/inbox.comp.lang.ruby.mwrap

No subscription will ever be required to post, but HTML mail
will be rejected:

		mwrap-public@80x24.org

== Hacking

	git clone https://80x24.org/mwrap.git

Send all patches and pull requests (use "git request-pull" to format) to
the mailing list.  We do not use centralized or proprietary messaging
systems.

== License

GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>

# heads (aka `branches'):
$ git for-each-ref --sort=-creatordate refs/heads \
	--format='%(HEAD) %(refname:short) %(subject) (%(creatordate:short))'
* master       README: fixup references to the Perl version (2024-01-08)
  heavy        mwrap_rack: Rack app to track live allocations (2018-07-16)

# tags:
$ git for-each-ref --sort=-creatordate refs/tags \
	--format='%(refname:short) %(subject) (%(creatordate:short))'
v3.0.0-pre1  mwrap 3.0.0-pre1 (2023-01-09) tar.gz
v2.3.0       mwrap 2.3.0 (2022-09-03) tar.gz
v2.2.0       mwrap 2.2.0 (2022-08-22) tar.gz
v2.1.0       mwrap 2.1.0 - heap_page_body struct tracking (2018-08-11) tar.gz
v2.0.0       mwrap 2.0.0 (2018-07-20) tar.gz
v1.0.0       mwrap 1.0.0 - initial release (2018-07-02) tar.gz

# associated public inboxes:
# (number on the left is used for dev purposes)
            https://80x24.org/mwrap-public

git clone https://80x24.org/mwrap.git