diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/mwrap-decode-csv | 56 | ||||
-rw-r--r-- | script/mwrap-perl | 154 | ||||
-rw-r--r-- | script/mwrap-rproxy | 115 |
3 files changed, 0 insertions, 325 deletions
diff --git a/script/mwrap-decode-csv b/script/mwrap-decode-csv deleted file mode 100644 index ad73b8c..0000000 --- a/script/mwrap-decode-csv +++ /dev/null @@ -1,56 +0,0 @@ -#!perl -w -# Copyright (C) mwrap hackers <mwrap-perl@80x24.org> -# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> -use v5.12; -use Devel::Mwrap::Rproxy; -use IO::Handle; -Devel::Mwrap::Rproxy::decode_csv(*STDIN{IO}, *STDOUT{IO}); -__END__ -=head1 NAME - -mwrap-decode-csv - decode non-Perl addresses from mwrap CSV dumps - -=head1 SYNOPSIS - - MWRAP=dump_csv:$FILENAME,bt:2 mwrap-perl COMMAND... - - mwrap-decode-csv <$FILENAME - -=head1 DESCRIPTION - -mwrap-decode-csv is a convenient wrapper for L<addr2line(1)> -for decoding C backtraces from CSV files. - -It reads the CSV via standard input, and emits to standard output. - -It expects CSV files emitted by a L<mwrap-perl(1p)> via -C<MWRAP=dump_csv:$FILENAME> or retrieved directly via C<curl --unix-socket>. - -It is not needed for CSVs retrieved via L<mwrap-rproxy(1p)>, -since mwrap-rproxy already performs the same function as mwrap-decode-csv. - -To get useful C backtraces of Perl programs, C<MWRAP=bt:$DEPTH> -directive must be used (carefully). See L<mwrap-perl(1p)>. - -addr2line from GNU binutils 2.39+ (August 2022) is recommended to -support C<SYMBOL+OFFSET> addresses. - -=head1 CONTACT - -Feedback welcome via plain-text mail to L<mailto:mwrap-perl@80x24.org> - -Mail archives are hosted at L<https://80x24.org/mwrap-perl/> - -=head1 COPYRIGHT - -Copyright all contributors L<mailto:mwrap-perl@80x24.org> - -License: GPL-3.0+ L<https://www.gnu.org/licenses/gpl-3.0.txt> - -Source code is at L<https://80x24.org/mwrap-perl.git/> - -=head1 SEE ALSO - -L<mwrap-perl(1p)>, L<mwrap-rproxy(1)> - -=cut diff --git a/script/mwrap-perl b/script/mwrap-perl deleted file mode 100644 index 632deaf..0000000 --- a/script/mwrap-perl +++ /dev/null @@ -1,154 +0,0 @@ -#!perl -w -# Copyright (C) mwrap hackers <mwrap-perl@80x24.org> -# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> -use v5.12; -use Devel::Mwrap; -my ($so) = grep(m!/Mwrap\.so\z!, @DynaLoader::dl_shared_objects) - or die 'Mwrap.so not loaded'; -if (!@ARGV || ($ARGV[0] // '') =~ /\A(?:-h|--help)\z/) { - require Pod::Usage; Pod::Usage::pod2usage(@ARGV ? 0 : 1); -} -my @cur = split(/[: \t]+/, $ENV{LD_PRELOAD} // ''); -if (!grep(/\A\Q$so\E\z/, @cur)) { # drop old redundant versions - my @keep = grep(!m!/Mwrap\.so$!, @cur); - $ENV{LD_PRELOAD} = join(':', $so, @keep); -} -exec @ARGV; -__END__ -=head1 NAME - -mwrap-perl - run any command under mwrap - -=head1 SYNOPSIS - - # to trace a long-running program and access it via $DIR/$PID.sock: - MWRAP=socket_dir:$DIR mwrap-perl COMMAND - - # to trace a short-lived command and dump its output to a CSV: - MWRAP=dump_csv$FILENAME mwrap-perl COMMAND - -=head1 DESCRIPTION - -mwrap-perl is a command-line to automatically add Mwrap.so as an -LD_PRELOAD for any command. It will resolve malloc-family calls -to a Perl file and line number, and it can also provide a backtrace -of native (C/C++) functions for non-Perl programs. - -=head1 ENVIRONMENT - -C<MWRAP> is the only environment variable read. It contains multiple -options delimited by C<,> with names and values delimited by C<:> - -=over 4 - -=item socket_dir:$DIR - -This launches an embedded HTTP server in each process and binds it -to C<$DIR/$PID.sock>. C<curl --unix-socket $DIR/$PID.sock http://0/$PID/> -or L<mwrap-rproxy(1p)> may be used to access various endpoints in -the HTTP server. - -=item bt:$DEPTH - -The backtrace depth for L<backtrace(3)> in addition to the Perl -file and line number where C<$DEPTH> is a non-negative number. - -The maximum allowed value is 32, though values of 5 or less are -typically useful. Increasing this to even 2 or 3 can significantly -increase the amount of memory mwrap (and liburcu) itself uses. - -This is only useful in conjunction with C<socket_dir> - -This may be changed via POST request (see below). - -Default: 0 - -=item dump_csv:$FILENAME - -Dump CSV to the given filename. - -This output matches the HTTP server output and includes column headers, -but is subject to change in future releases. - -C<dump_csv> without the C<:> may also be used in conjunction with -C<dump_fd>, such as C<MWRAP=dump_fd:2,dump_csv>. - -C<$FILENAME> may contain C<%p> where C<%p> is a placeholder for -the PID being dumped. No other use of C<%> is accepted, and -multiple C<%> means all C<%> (including C<%p>) are handled as-is. - -=item dump_path:$FILENAME - -Gives a simpler, legacy output compatible with the old Ruby version: - - total_bytes call_count location - -Expands C<%p> to the PID in C<$FILENAME> as described for C<dump_csv> - -=item dump_fd:$DESCRIPTOR - -As with dump_path, but dumps the output to a given file descriptor. - -=back - -=head1 HTTP POST API - -In addition to the various GET endpoints linked via C<http://0/$PID/>, -there are some POST endpoints which are typically accessed via -C<curl --unix-socket $DIR/$PID.sock> - -=over 4 - -=item POST http://0/$PID/reset - -C<curl --unix-socket $DIR/$PID.sock -XPOST http://0/$PID/reset> - -Reset all internal counters. This is not done atomically and does -not release any memory. - -=item POST http://0/$PID/trim - -C<curl --unix-socket $DIR/$PID.sock -XPOST http://0/$PID/trim> - -Runs L<malloc_trim(3)> with a 0 pad value to release unused memory -back to the kernel. In our malloc implementation, this is done -lazily to avoid contention and does not happen unless sleeping threads. - -=item POST http://0/$PID/ctl - -Set various internal knobs. Currently, C<X-Mwrap-BT> is the -only knob supported: - -C<curl --unix-socket $DIR/$PID.sock -XPOST -HX-Mwrap-BT:1 http://0/$PID/ctl> - -Using the C<X-Mwrap-BT> header allows changing the aforementioned -C<bt:> value to a specified depth level. As with C<bt:>, only make small -adjustments as the memory cost can increase exponentially with each step. - -It is typically a good idea to reset (C<http://0/$PID/reset>) after changing -the depth on a running process. - -Headers other than C<X-Mwrap-BT> may be accepted in the future to -tweak other settings. - -=back - -=head1 CONTACT - -Feedback welcome via plain-text mail to L<mailto:mwrap-perl@80x24.org> - -Mail archives are hosted at L<https://80x24.org/mwrap-perl/> - -=head1 COPYRIGHT - -Copyright all contributors L<mailto:mwrap-perl@80x24.org> - -License: GPL-3.0+ L<https://www.gnu.org/licenses/gpl-3.0.txt> - -Source code is at L<https://80x24.org/mwrap-perl.git/> - -=head1 SEE ALSO - -L<mwrap-rproxy(1)>, L<Devel::Mwrap(3pm)> - -=cut diff --git a/script/mwrap-rproxy b/script/mwrap-rproxy deleted file mode 100644 index 57fdde7..0000000 --- a/script/mwrap-rproxy +++ /dev/null @@ -1,115 +0,0 @@ -#!perl -w -# Copyright (C) mwrap hackers <mwrap-perl@80x24.org> -# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> -# thin wrapper for Devel::Mwrap::Rproxy (see __END__ below for manpage) -use v5.12; # strict -eval { require Plack::Runner } or die "Plack not installed: $@\n"; -use Getopt::Long qw(:config no_ignore_case no_auto_abbrev pass_through); -my $usage = "$0 --socket-dir=/path/to/socket-dir [PLACKUP_OPTIONS]\n"; -my %opt = (deflate => 1); -GetOptions(\%opt, 'socket-dir=s', 'deflate!', 'help|h') or do { - require Pod::Usage; Pod::Usage::pod2usage(1); -}; -if ($opt{help}) { require Pod::Usage; Pod::Usage::pod2usage(0) } -my $socket_dir = delete $opt{'socket-dir'}; -$socket_dir //= ($ENV{MWRAP} // '') =~ m!\bsocket_dir:([^,]+)! ? $1 : undef; -$socket_dir // die $usage; -require Devel::Mwrap::Rproxy; -my $rproxy = Devel::Mwrap::Rproxy->new($socket_dir); -my $app = sub { $rproxy->call(@_) }; -my $runner = Plack::Runner->new; -$runner->parse_options(@ARGV); -if (($ENV{LISTEN_PID} // 0) == $$) { - my $fds = $ENV{LISTEN_FDS} // ''; - die "only one LISTEN_FDS=1 supported (got `$fds')\n" if $fds ne '1'; - if (open(my $s, '<&=', 3)) { - my $prev_was_blocking = $s->blocking(1); - warn <<"" unless $prev_was_blocking; -Inherited socket (fd=3) is non-blocking, making it blocking. - - bless $s, 'IO::Socket::INET'; - $runner->set_options(listen_sock => $s); - } -} -if ($opt{deflate} && eval { require Plack::Middleware::Deflater } and !$@) { - $app = Plack::Middleware::Deflater->wrap($app); -} - -# ensure mwrap_dtor() runs if running under mwrap-perl, ourselves -sub sigexit { exit 0 } -$SIG{$_} = \&sigexit for (qw(INT TERM)); - -$runner->run($app); -__END__ -=head1 NAME - -mwrap-rproxy - reverse proxy for embedded per-process mwrap httpd - -=head1 SYNOPSIS - - # start the long-running COMMAND you wish to trace: - MWRAP=socket_dir:$DIR mwrap-perl COMMAND - - # in a different terminal, point mwrap-proxy to the mwrap-perl socket_dir - mwrap-rproxy --socket-dir=$DIR -l 127.0.0.1:8080 - - # open http://127.0.0.1:8080/ in your favorite web browser: - w3m http://127.0.0.1:8080/ - -=head1 DESCRIPTION - -B<mwrap-rproxy> is a PSGI reverse proxy to provide access -via TCP to the native, Unix-socket-only httpd embedded inside -mwrap core. It provides a listing of process IDs of each process -traced via mwrap. - -B<mwrap-rproxy> does not have a hard dependency on mwrap-perl itself, -it exists to provide a convenient interface to programs being -traced by mwrap-perl. - -=head1 OPTIONS - -=over 4 - -=item --socket-dir=DIR - -If unset, it will attempt to parse C<socket_dir:> from the C<MWRAP> -environment (see L<mwrap-perl(1p)>). - -=item --no-deflate - -L<Plack::Middleware::Deflater(3pm)> is loaded by default if available. -Using C<--no-deflate> will save CPU cycles at the expense of bandwidth. - -=back - -Additionally, all options in L<plackup(1p)> are supported. Notably, -C<-l>/C<--listen> and C<--path=/prefix> may be useful. - -=head1 ENVIRONMENT - -mwrap-rproxy supports systemd (and compatible) socket activation via -C<LISTEN_PID> and C<LISTEN_FDS> variables. See L<systemd.socket(5)> -and L<sd_listen_fds(3)>. - -C<PLACK_ENV> is also supported as described by L<plackup(1p)> - -=head1 CONTACT - -Feedback welcome via plain-text mail to L<mailto:mwrap-perl@80x24.org> - -Mail archives are hosted at L<https://80x24.org/mwrap-perl/> - -=head1 COPYRIGHT - -Copyright all contributors L<mailto:mwrap-perl@80x24.org> - -License: GPL-3.0+ L<https://www.gnu.org/licenses/gpl-3.0.txt> - -Source code is at L<https://80x24.org/mwrap-perl.git/> - -=head1 SEE ALSO - -L<mwrap-perl(1p)> - -=cut |