From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id AD0FE1F8C8 for ; Sun, 3 Oct 2021 08:33:43 +0000 (UTC) From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH] psgi: show live bytes, fix bold in sort column Date: Sun, 3 Oct 2021 08:33:43 +0000 Message-Id: <20211003083343.14623-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- lib/Devel/Mwrap/PSGI.pm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/Devel/Mwrap/PSGI.pm b/lib/Devel/Mwrap/PSGI.pm index b6e660c..c94d136 100644 --- a/lib/Devel/Mwrap/PSGI.pm +++ b/lib/Devel/Mwrap/PSGI.pm @@ -39,13 +39,14 @@ sub uri_unescape { $str; } -my @COLS = qw(total allocations frees mean_life max_life location); -my $HDR = '' . join('', @COLS) . ''; -my @FIELDS = qw(total allocations frees mean_life max_life location); +my @FIELDS = qw(total allocations frees live mean_life max_life location); +my $HDR = '' . join('', @FIELDS) . ''; sub accumulate_i { # callback for Devel::Mwrap::each my ($all, $src_loc) = @_; - push @$all, [ $src_loc->total, $src_loc->allocations, $src_loc->frees, + my $alloc = $src_loc->allocations; + my $frees = $src_loc->frees; + push @$all, [ $src_loc->total, $alloc, $frees, $alloc - $frees, $src_loc->mean_lifespan, $src_loc->max_lifespan, $src_loc->name ]; } @@ -73,13 +74,14 @@ sub each_gt { my @f = @FIELDS; my $sc = 0; for (my $i = 0; $i <= $#FIELDS; $i++) { - next if $FIELDS[$i] ne $sort; - $sc = $i; - last; + if ($FIELDS[$i] eq $sort) { + $sc = $i; + last; + } } $f[$sc] = "$f[$sc]"; @f = (join('', map {; - if (/\A/) { + if (substr($_, 0, 1) eq '<') { $_; } else { qq($_); @@ -89,16 +91,17 @@ sub each_gt { Devel::Mwrap::each($min, \&accumulate_i, \@all); @all = sort { $b->[$sc] <=> $a->[$sc] } @all; my $age = Devel::Mwrap::current_age(); + my $live = $age - Devel::Mwrap::total_bytes_freed(); print $fh <$t

$t

-

Current age: $age

+

Current age: $age (live: $live)

EOM while (my $cols = shift @all) { # cols: [ total, allocations, frees, mean_lifespan, # max_lifespan, name ] my $loc_name = pop @$cols; - $cols->[3] = sprintf('%0.3f', $cols->[3]); # mean_life + $cols->[4] = sprintf('%0.3f', $cols->[4]); # mean_life my $href = "$sn/at/".uri_escape($loc_name); print $fh '
@f
', join('', @$cols), qq(name); open my $fh, '+>', undef or die "open: $!"; my $age = Devel::Mwrap::current_age(); + my $live = $age - Devel::Mwrap::total_bytes_freed(); print $fh <$t

live allocations at $t

-

Current age: $age

\n +

Current age: $age (live: $live)

\n
EOM $src_loc->each(0, \&each_at_i, $fh); @@ -151,7 +155,7 @@ sub call { # PSGI entry point my $ret; if ($path_info =~ m!\A/each/([0-9]+)\z!) { my $min = $1 + 0; - my ($sort) = ($env->{QUERY_STRING} =~ /\bsort=([a-z+])\b/); + my ($sort) = ($env->{QUERY_STRING} =~ /\bsort=([a-z]+)\b/); $ret = each_gt($env, $min, $sort); } elsif ($path_info =~ m!\A/at/(.*)\z!) { my $src_loc = Devel::Mwrap::get(uri_unescape($1));
sizegeneration