<commit_before>#!/usr/bin/perl
#
# mySociety/Logfile.pm:
# Logfile reading/searching stuff.
#
# Copyright (c) 2005 UK Citizens Online Democracy. All rights reserved.
# Email: <EMAIL>; WWW: http://www.mysociety.org/
#
# $Id: Logfile.pm,v 1.7 2006-09-19 09:29:13 francis Exp $
#

package mySociety::Logfile::Error;

use Error;

@mySociety::Logfile::Error::ISA = qw(Error::Simple);

package mySociety::Logfile;

use Error qw(:try);
use File::stat;
use IO::File;
use POSIX ();
use Sys::Mmap;
use Time::HiRes;

=head1 NAME

mySociety::Logfile

=head1 DESCRIPTION

Object representing the contents of a logfile; that is, a file which contains
a list of diagnostic messages in chronological order.

package mySociety::Logfile;

=head1 FUNCTIONS

=over 4

=cut

# maplen SIZE
# Return the length of a mapping which should be used to cover a file of SIZE
# bytes.
sub maplen ($) {
    my ($size) = @_;
    use integer;
    my $pagesize = POSIX::sysconf(&POSIX::_SC_PAGESIZE);
    my $maplen = (($size + $pagesize - 1) / $pagesize) * $pagesize;

    # from Sys::Mmap(3pm), help for mmap: "The LENGTH argument can be zero in
    # which case a stat is done on FILEHANDLE and the size of the underlying
    # file is used instead." Which for some reason causes an "invalid argument"
    # error from mmap in our case. Return pagesize instead for zero length files.
    return $maplen == 0 ? $pagesize : $maplen;
}

# _update
# Update the mapping for the logfile, if it has changed on disk.
sub _update ($) {
    my ($self) = @_;
    my $st = stat($self->{fh})
        or throw mySociety::Logfile::Error("$self->{file}: $!");<commit_msg>Previous code gave a bus error, admit instead that I don't know how to fix this<commit_after>#!/usr/bin/perl
#
# mySociety/Logfile.pm:
# Logfile reading/searching stuff.
#
# Copyright (c) 2005 UK Citizens Online Democracy. All rights reserved.
# Email: <EMAIL>; WWW: http://www.mysociety.org/
#
# $Id: Logfile.pm,v 1.8 2006-09-20 11:57:24 francis Exp $
#

package mySociety::Logfile::Error;

use Error;

@mySociety::Logfile::Error::ISA = qw(Error::Simple);

package mySociety::Logfile;

use Error qw(:try);
use File::stat;
use IO::File;
use POSIX ();
use Sys::Mmap;
use Time::HiRes;

=head1 NAME

mySociety::Logfile

=head1 DESCRIPTION

Object representing the contents of a logfile; that is, a file which contains
a list of diagnostic messages in chronological order.

package mySociety::Logfile;

=head1 FUNCTIONS

=over 4

=cut

# maplen SIZE
# Return the length of a mapping which should be used to cover a file of SIZE
# bytes.
sub maplen ($) {
    my ($size) = @_;
    use integer;
    my $pagesize = POSIX::sysconf(&POSIX::_SC_PAGESIZE);
    my $maplen = (($size + $pagesize - 1) / $pagesize) * $pagesize;

    # from Sys::Mmap(3pm), help for mmap: "The LENGTH argument can be zero in
    # which case a stat is done on FILEHANDLE and the size of the underlying
    # file is used instead." Which for some reason causes an "invalid argument"
    # error from mmap in our case. 
    throw mySociety::Logfile::Error("Zero length log file not supported") if $maplen == 0;
    return $maplen == 0 ? $pagesize : $maplen;
}

# _update
# Update the mapping for the logfile, if it has changed on disk.
sub _update ($) {
    my ($self) = @_;
    my $st = stat($self->{fh})
        or throw mySociety::Logfile::Error("$self->{file}: $!");
{'fraction_non_alphanumeric': 0.12712116701399226, 'fraction_numerical': 0.01637392080976481, 'mean_word_length': 3.912280701754386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1638147', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1135, 'n_words': 406}