From: Eric Wong <e@80x24.org>
To: ruby-talk@ruby-lang.org, mwrap-public@80x24.org
Subject: [ANN] mwrap - LD_PRELOAD malloc wrapper + line stats for Ruby
Date: Mon, 2 Jul 2018 12:00:50 +0000 [thread overview]
Message-ID: <20180702120050.GA24029@dcvr> (raw)
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_path: in the MWRAP environment
variable to append the results to a log file:
MWRAP=dump_path:/path/to/log mwrap RUBY_COMMAND
# And to display the locations with the most allocations:
sort -k1,1rn </path/to/log | $PAGER
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). It is
recommended to use the sort(1) command on either of the
first two columns to find the hottest malloc locations.
== 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>
--
https://80x24.org/mwrap/README.html
https://80x24.org/mwrap/Mwrap.html
next reply other threads:[~2018-07-02 12:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-02 12:00 Eric Wong [this message]
2018-07-03 0:11 ` [ANN] mwrap - LD_PRELOAD malloc wrapper + line stats for Ruby Sam Saffron
2018-07-03 7:48 ` Eric Wong
2018-07-16 21:48 ` Eric Wong
2018-07-03 9:11 ` Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://80x24.org/mwrap/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180702120050.GA24029@dcvr \
--to=e@80x24.org \
--cc=mwrap-public@80x24.org \
--cc=ruby-talk@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).