<commit_before>package RSP;

use strict;
use warnings;

use Cwd;
use base 'Mojo';
our $VERSION = '1.2';
use Application::Config 'rsp.conf';

use RSP::Transaction::Mojo;

sub handler {
  my ($self, $tx) = @_;

  eval {
    my $rsptx = RSP::Transaction::Mojo->new
                                      ->request( $tx->req )
                                      ->response( $tx->res );

    $rsptx->process_transaction;
    $rsptx = undef;
  };
  if ($@) {
    $tx->res->code( 500 );
    $tx->res->headers->content_type('text/plain');
    $tx->res->body($@);
  }
  return $tx;
}

sub root {
  my $self = shift;
  my $root = $self->config->{_}->{root};
  if (!$root) {
    $root = getcwd();
  }
  return $root;
}

1;
<commit_msg>memory sampling to test for leaks - there are a lot<commit_after>package RSP;

use strict;
use warnings;

use Cwd;
use base 'Mojo';
use Number::Bytes::Human 'format_bytes';
use Darwin::Process::Memory;
use Scalar::Util qw( weaken );
our $VERSION = '1.2';
use Application::Config 'rsp.conf';

use RSP::Transaction::Mojo;

sub sample_memory {
  return (
      #format_bytes( 
	  Darwin::Process::Memory::resident(),
      #),
      #format_bytes(
	  Darwin::Process::Memory::virtual()
      #),
      );
}

sub handler {
  my ($self, $tx) = @_;

  my ($rstart, $vstart) = sample_memory();
  print STDERR sprintf("$$ start: resident: %s, virtual: %s\n", $rstart, $vstart);
  my $rsptx = RSP::Transaction::Mojo->new
                                    ->request( $tx->req )
				    ->response( $tx->res );

  eval {
    $rsptx->process_transaction;    
  };
  if ($@) {
    $tx->res->code( 500 );
    $tx->res->headers->content_type('text/plain');
    $tx->res->body($@);
  }

  $rsptx->request( undef );
  $rsptx->response( undef );
  $rsptx = undef;

  my ($rend, $vend) = sample_memory();
  print STDERR sprintf("$$ end: resident: %s, virtual: %s, resident diff: %s\n", $rend, $vend, format_bytes( $rend - $rstart ));

  return $tx;
}

sub root {
  my $self = shift;
  my $root = $self->config->{_}->{root};
  if (!$root) {
    $root = getcwd();
  }
  return $root;
}

1;

{'fraction_non_alphanumeric': 0.1950405340963281, 'fraction_numerical': 0.005722460658082976, 'mean_word_length': 2.6742556917688267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3563777', 'n_tokens_mistral': 799, 'n_tokens_neox': 775, 'n_words': 177}