| Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm |
| Statements | Executed 61 statements in 4.30s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 64µs | 3.92s | Hailo::Storage::SQLite::save |
| 1 | 1 | 1 | 63µs | 6.23ms | Hailo::Storage::SQLite::_set_pragmas |
| 1 | 1 | 1 | 59µs | 385ms | Hailo::Storage::SQLite::__ANON__[:65] |
| 1 | 1 | 1 | 47µs | 145µs | Hailo::Storage::SQLite::BEGIN@9 |
| 3 | 3 | 1 | 44µs | 56µs | Hailo::Storage::SQLite::_backup_memory_to_disk |
| 1 | 1 | 1 | 42µs | 861µs | Hailo::Storage::SQLite::__ANON__[:88] |
| 1 | 1 | 1 | 36µs | 175µs | Hailo::Storage::SQLite::__ANON__[:42] |
| 13 | 8 | 2 | 22µs | 22µs | Hailo::Storage::SQLite::brain (xsub) |
| 1 | 1 | 1 | 21µs | 21µs | Hailo::Storage::SQLite::BEGIN@2 |
| 1 | 1 | 1 | 14µs | 14µs | Hailo::Storage::SQLite::CORE:ftis (opcode) |
| 1 | 1 | 1 | 13µs | 98µs | Hailo::Storage::SQLite::BEGIN@9.5 |
| 1 | 1 | 1 | 12µs | 683µs | Hailo::Storage::SQLite::BEGIN@10 |
| 1 | 1 | 1 | 12µs | 1.26ms | Hailo::Storage::SQLite::BEGIN@12 |
| 1 | 1 | 1 | 11µs | 348µs | Hailo::Storage::SQLite::BEGIN@11 |
| 1 | 1 | 1 | 9µs | 31µs | Hailo::Storage::SQLite::__ANON__[:24] |
| 5 | 2 | 1 | 8µs | 8µs | Hailo::Storage::SQLite::arguments (xsub) |
| 1 | 1 | 1 | 5µs | 5µs | Hailo::Storage::SQLite::BEGIN@5 |
| 2 | 2 | 1 | 4µs | 4µs | Hailo::Storage::SQLite::order (xsub) |
| 1 | 1 | 1 | 4µs | 4µs | Hailo::Storage::SQLite::tokenizer_class (xsub) |
| 1 | 1 | 1 | 3µs | 3µs | Hailo::Storage::SQLite::_build_dbd |
| 1 | 1 | 1 | 3µs | 3µs | Hailo::Storage::SQLite::CORE:match (opcode) |
| 0 | 0 | 0 | 0s | 0s | Hailo::Storage::SQLite::__ANON__[:72] |
| 0 | 0 | 0 | 0s | 0s | Hailo::Storage::SQLite::__ANON__[:79] |
| 0 | 0 | 0 | 0s | 0s | Hailo::Storage::SQLite::ready |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Hailo::Storage::SQLite; | ||||
| 2 | # spent 21µs within Hailo::Storage::SQLite::BEGIN@2 which was called:
# once (21µs+0s) by Hailo::_new_class at line 4 | ||||
| 3 | 1 | 12µs | $Hailo::Storage::SQLite::AUTHORITY = 'cpan:AVAR'; | ||
| 4 | 1 | 23µs | 1 | 21µs | } # spent 21µs making 1 call to Hailo::Storage::SQLite::BEGIN@2 |
| 5 | # spent 5µs within Hailo::Storage::SQLite::BEGIN@5 which was called:
# once (5µs+0s) by Hailo::_new_class at line 7 | ||||
| 6 | 1 | 5µs | $Hailo::Storage::SQLite::VERSION = '0.57'; | ||
| 7 | 1 | 19µs | 1 | 5µs | } # spent 5µs making 1 call to Hailo::Storage::SQLite::BEGIN@5 |
| 8 | |||||
| 9 | 4 | 77µs | 3 | 329µs | use 5.010; # spent 145µs making 1 call to Hailo::Storage::SQLite::BEGIN@9
# spent 98µs making 1 call to Hailo::Storage::SQLite::BEGIN@9.5
# spent 85µs making 1 call to feature::import |
| 10 | 2 | 31µs | 2 | 1.35ms | # spent 683µs (12+671) within Hailo::Storage::SQLite::BEGIN@10 which was called:
# once (12µs+671µs) by Hailo::_new_class at line 10 # spent 683µs making 1 call to Hailo::Storage::SQLite::BEGIN@10
# spent 671µs making 1 call to Any::Moose::import |
| 11 | 2 | 32µs | 2 | 685µs | # spent 348µs (11+337) within Hailo::Storage::SQLite::BEGIN@11 which was called:
# once (11µs+337µs) by Hailo::_new_class at line 11 # spent 348µs making 1 call to Hailo::Storage::SQLite::BEGIN@11
# spent 337µs making 1 call to Any::Moose::import |
| 12 | 2 | 674µs | 2 | 2.51ms | # spent 1.26ms (12µs+1.25) within Hailo::Storage::SQLite::BEGIN@12 which was called:
# once (12µs+1.25ms) by Hailo::_new_class at line 12 # spent 1.26ms making 1 call to Hailo::Storage::SQLite::BEGIN@12
# spent 1.25ms making 1 call to namespace::clean::import |
| 13 | |||||
| 14 | 1 | 4µs | 1 | 21.2ms | extends 'Hailo::Storage'; # spent 21.2ms making 1 call to Mouse::extends |
| 15 | 1 | 5µs | 1 | 22.8ms | with qw(Hailo::Role::Arguments Hailo::Role::Storage); # spent 22.8ms making 1 call to Mouse::with |
| 16 | |||||
| 17 | 1 | 5µs | # spent 3µs within Hailo::Storage::SQLite::_build_dbd which was called:
# once (3µs+0s) by Hailo::Storage::dbd at line 60 of Hailo/Storage.pm | ||
| 18 | |||||
| 19 | # spent 31µs (9+21) within Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:24] which was called:
# once (9µs+21µs) by Hailo::Storage::SQLite::_build_dbd_options at line 416 of Mouse/Meta/Class.pm | ||||
| 20 | return { | ||||
| 21 | 1 | 10µs | 1 | 21µs | %{ super() }, # spent 21µs making 1 call to Mouse::super |
| 22 | sqlite_unicode => 1, | ||||
| 23 | }; | ||||
| 24 | 1 | 8µs | 1 | 85µs | }; # spent 85µs making 1 call to Mouse::override |
| 25 | |||||
| 26 | # spent 175µs (36+139) within Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:42] which was called:
# once (36µs+139µs) by Mouse::Meta::Class::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Meta/Class.pm:379] at line 379 of Mouse/Meta/Class.pm | ||||
| 27 | 9 | 39µs | my $orig = shift; | ||
| 28 | my $self = shift; | ||||
| 29 | |||||
| 30 | my $return; | ||||
| 31 | 1 | 19µs | if ($self->_backup_memory_to_disk) { # spent 19µs making 1 call to Hailo::Storage::SQLite::_backup_memory_to_disk | ||
| 32 | 1 | 1µs | my $file = $self->brain; # spent 1µs making 1 call to Hailo::Storage::SQLite::brain | ||
| 33 | 1 | 2µs | $self->brain(':memory:'); # spent 2µs making 1 call to Hailo::Storage::SQLite::brain | ||
| 34 | 1 | 115µs | $return = $self->$orig(@_); # spent 115µs making 1 call to Hailo::Storage::_build_dbi_options | ||
| 35 | 1 | 2µs | $self->brain($file); # spent 2µs making 1 call to Hailo::Storage::SQLite::brain | ||
| 36 | } | ||||
| 37 | else { | ||||
| 38 | $return = $self->$orig(@_); | ||||
| 39 | } | ||||
| 40 | |||||
| 41 | return $return; | ||||
| 42 | 1 | 11µs | 1 | 132µs | }; # spent 132µs making 1 call to Mouse::around |
| 43 | |||||
| 44 | # Are we running in a mixed mode where we run in memory but | ||||
| 45 | # restore/backup to disk? | ||||
| 46 | # spent 56µs (44+13) within Hailo::Storage::SQLite::_backup_memory_to_disk which was called 3 times, avg 19µs/call:
# once (14µs+4µs) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:65] at line 60
# once (15µs+4µs) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:42] at line 31
# once (14µs+4µs) by Hailo::Storage::SQLite::save at line 127 | ||||
| 47 | 6 | 61µs | my ($self) = @_; | ||
| 48 | |||||
| 49 | 9 | 13µs | return (defined $self->brain # spent 8µs making 6 calls to Hailo::Storage::SQLite::brain, avg 1µs/call
# spent 5µs making 3 calls to Hailo::Storage::SQLite::arguments, avg 2µs/call | ||
| 50 | and $self->brain ne ':memory:' | ||||
| 51 | and $self->arguments->{in_memory}); | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | # spent 385ms (59µs+385) within Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:65] which was called:
# once (59µs+385ms) by Hailo::Storage::SQLite::_engage at line 330 of Mouse/Meta/Class.pm | ||||
| 55 | 4 | 379ms | my ($self) = @_; | ||
| 56 | |||||
| 57 | # Set any user-defined pragmas | ||||
| 58 | 1 | 6.23ms | $self->_set_pragmas; # spent 6.23ms making 1 call to Hailo::Storage::SQLite::_set_pragmas | ||
| 59 | |||||
| 60 | 4 | 379ms | if ($self->_backup_memory_to_disk) { # spent 379ms making 1 call to DBI::db::sqlite_backup_from_file
# spent 19µs making 1 call to Hailo::Storage::SQLite::_backup_memory_to_disk
# spent 2µs making 1 call to Hailo::Storage::dbh
# spent 1µs making 1 call to Hailo::Storage::SQLite::brain | ||
| 61 | $self->dbh->sqlite_backup_from_file($self->brain); | ||||
| 62 | } | ||||
| 63 | |||||
| 64 | return; | ||||
| 65 | 1 | 7µs | 1 | 109µs | }; # spent 109µs making 1 call to Mouse::before |
| 66 | |||||
| 67 | before start_training => sub { | ||||
| 68 | my $dbh = shift->dbh; | ||||
| 69 | $dbh->do('PRAGMA synchronous=OFF;'); | ||||
| 70 | $dbh->do('PRAGMA journal_mode=OFF;'); | ||||
| 71 | return; | ||||
| 72 | 1 | 6µs | 1 | 89µs | }; # spent 89µs making 1 call to Mouse::before |
| 73 | |||||
| 74 | after stop_training => sub { | ||||
| 75 | my $dbh = shift->dbh; | ||||
| 76 | $dbh->do('PRAGMA journal_mode=DELETE;'); | ||||
| 77 | $dbh->do('PRAGMA synchronous=ON;'); | ||||
| 78 | return; | ||||
| 79 | 1 | 7µs | 1 | 94µs | }; # spent 94µs making 1 call to Mouse::after |
| 80 | |||||
| 81 | # spent 861µs (42+819) within Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:88] which was called:
# once (42µs+819µs) by Hailo::Storage::SQLite::initialized at line 416 of Mouse/Meta/Class.pm | ||||
| 82 | 5 | 63µs | my ($self) = @_; | ||
| 83 | |||||
| 84 | 1 | 4µs | my $brain = $self->brain; # spent 4µs making 1 call to Hailo::Storage::SQLite::brain | ||
| 85 | return unless defined $brain; | ||||
| 86 | return if $brain eq ':memory:'; | ||||
| 87 | 2 | 815µs | return -e $brain && super(); # spent 801µs making 1 call to Mouse::super
# spent 14µs making 1 call to Hailo::Storage::SQLite::CORE:ftis | ||
| 88 | 1 | 6µs | 1 | 68µs | }; # spent 68µs making 1 call to Mouse::override |
| 89 | |||||
| 90 | sub ready { | ||||
| 91 | my ($self) = @_; | ||||
| 92 | my $brain = $self->brain; | ||||
| 93 | return unless defined $self->brain; | ||||
| 94 | return 1 if $self->brain eq ':memory:'; | ||||
| 95 | return 1; | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | # spent 6.23ms (63µs+6.17) within Hailo::Storage::SQLite::_set_pragmas which was called:
# once (63µs+6.17ms) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:65] at line 58 | ||||
| 99 | 9 | 77µs | my ($self) = @_; | ||
| 100 | |||||
| 101 | my %pragmas; | ||||
| 102 | |||||
| 103 | # speedy defaults when DB is not kept in memory | ||||
| 104 | if (!$self->{in_memory}) { | ||||
| 105 | $pragmas{synchronous} = 'OFF'; | ||||
| 106 | $pragmas{journal_mode} = 'OFF'; | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | 2 | 3µs | while (my ($k, $v) = each %{ $self->arguments }) { # spent 3µs making 2 calls to Hailo::Storage::SQLite::arguments, avg 2µs/call | ||
| 110 | 1 | 3µs | if (my ($pragma) = $k =~ /^pragma_(.*)/) { # spent 3µs making 1 call to Hailo::Storage::SQLite::CORE:match | ||
| 111 | $pragmas{$pragma} = $v; | ||||
| 112 | } | ||||
| 113 | } | ||||
| 114 | |||||
| 115 | 1 | 39µs | 9 | 12.3ms | while (my ($k, $v) = each %pragmas) { # spent 5.79ms making 2 calls to Hailo::Storage::dbh, avg 2.90ms/call
# spent 5.76ms making 1 call to Hailo::Storage::_build_dbh
# spent 370µs making 2 calls to DBI::db::do, avg 185µs/call
# spent 357µs making 2 calls to DBD::SQLite::db::do, avg 178µs/call
# spent 3µs making 1 call to Mouse::Meta::TypeConstraint::_compiled_type_constraint
# spent 2µs making 1 call to Mouse::Meta::Attribute::builder |
| 116 | $self->dbh->do(qq[PRAGMA $k="$v";]) | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | return; | ||||
| 120 | } | ||||
| 121 | |||||
| 122 | # spent 3.92s (64µs+3.92) within Hailo::Storage::SQLite::save which was called:
# once (64µs+3.92s) by Hailo::save at line 212 of Hailo.pm | ||||
| 123 | 5 | 3.92s | my ($self, $filename) = @_; | ||
| 124 | 1 | 2µs | my $file = $filename // $self->brain; # spent 2µs making 1 call to Hailo::Storage::SQLite::brain | ||
| 125 | |||||
| 126 | 1 | 2µs | return unless $self->_engaged; # spent 2µs making 1 call to Hailo::Storage::_engaged | ||
| 127 | 3 | 3.92s | if ($self->_backup_memory_to_disk) { # spent 3.92s making 1 call to DBI::db::sqlite_backup_to_file
# spent 19µs making 1 call to Hailo::Storage::SQLite::_backup_memory_to_disk
# spent 2µs making 1 call to Hailo::Storage::dbh | ||
| 128 | $self->dbh->sqlite_backup_to_file($file); | ||||
| 129 | } | ||||
| 130 | return; | ||||
| 131 | }; | ||||
| 132 | |||||
| 133 | 1 | 23µs | 2 | 132µs | __PACKAGE__->meta->make_immutable; # spent 117µs making 1 call to Mouse::Meta::Class::make_immutable
# spent 15µs making 1 call to Hailo::Storage::SQLite::meta |
| 134 | |||||
| 135 | =encoding utf8 | ||||
| 136 | |||||
| 137 | =head1 NAME | ||||
| 138 | |||||
| 139 | Hailo::Storage::SQLite - A storage backend for L<Hailo|Hailo> using L<DBD::SQLite> | ||||
| 140 | |||||
| 141 | =head1 SYNOPSIS | ||||
| 142 | |||||
| 143 | As a module: | ||||
| 144 | |||||
| 145 | my $hailo = Hailo->new( | ||||
| 146 | storage_class => 'SQLite', | ||||
| 147 | ); | ||||
| 148 | $hailo->train("hailo.trn"); | ||||
| 149 | |||||
| 150 | From the command line: | ||||
| 151 | |||||
| 152 | hailo --train hailo.trn --storage SQLite | ||||
| 153 | |||||
| 154 | See L<Hailo's documentation|Hailo> for other non-MySQL specific options. | ||||
| 155 | |||||
| 156 | =head1 DESCRIPTION | ||||
| 157 | |||||
| 158 | This backend maintains information in an SQLite database. It is the default | ||||
| 159 | storage backend. | ||||
| 160 | |||||
| 161 | =head1 ATTRIBUTES | ||||
| 162 | |||||
| 163 | =head2 C<storage_args> | ||||
| 164 | |||||
| 165 | This is a hash reference which can have the following keys: | ||||
| 166 | |||||
| 167 | =head3 C<pragma_*> | ||||
| 168 | |||||
| 169 | Any option starting with B<'pragma_'> will be considered to be an L<SQLite | ||||
| 170 | pragma|http://www.sqlite.org/pragma.html> which will be set after we connect | ||||
| 171 | to the database. An example of this would be | ||||
| 172 | |||||
| 173 | storage_args => { | ||||
| 174 | pragma_cache_size => 10000, | ||||
| 175 | pragma_synchronous => 'OFF', | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | Setting B<'pragma_cache_size'> in particular can be beneficial. It's the | ||||
| 179 | size of the page cache used by SQLite. See L<SQLite's | ||||
| 180 | documentation|http://www.sqlite.org/pragma.html#pragma_cache_size> for | ||||
| 181 | more information. | ||||
| 182 | |||||
| 183 | Increasing it might speed up Hailo, especially when disk IO is slow on | ||||
| 184 | your machine. Obviously, you shouldn't bother with this option if | ||||
| 185 | L<B<'in_memory'>|/in_memory> is enabled. | ||||
| 186 | |||||
| 187 | Setting B<'pragma_synchronous'> to B<'OFF'> or B<'pragma_journal_mode'> | ||||
| 188 | to B<'OFF'> will speed up operations at the expense of safety. Since Hailo | ||||
| 189 | is most likely not running as a mission-critical component this trade-off | ||||
| 190 | should be acceptable in most cases. If the database becomes corrupt | ||||
| 191 | it's easy to rebuild it by retraining from the input it was trained on | ||||
| 192 | to begin with. For performance reasons, these two are set to B<'OFF'> | ||||
| 193 | by default unless L<B<'in_memory'>|/in_memory> is enabled. | ||||
| 194 | |||||
| 195 | =head3 C<in_memory> | ||||
| 196 | |||||
| 197 | When set to a true value, Hailo behaves much like MegaHAL. The entire | ||||
| 198 | database will be kept in memory, and only written out to disk when the | ||||
| 199 | L<C<save>|Hailo/save> method is called and/or when the Hailo object gets | ||||
| 200 | destroyed (unless you disabled | ||||
| 201 | L<C<save_on_exit>|Hailo/save_on_exit>). This is disabled by default. | ||||
| 202 | |||||
| 203 | =head1 AUTHOR | ||||
| 204 | |||||
| 205 | E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> | ||||
| 206 | |||||
| 207 | Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com | ||||
| 208 | |||||
| 209 | =head1 LICENSE AND COPYRIGHT | ||||
| 210 | |||||
| 211 | Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason and | ||||
| 212 | Hinrik E<Ouml>rn SigurE<eth>sson | ||||
| 213 | |||||
| 214 | This program is free software, you can redistribute it and/or modify | ||||
| 215 | it under the same terms as Perl itself. | ||||
| 216 | |||||
| 217 | 1 | 12µs | 1 | 3.84ms | =cut # spent 3.84ms making 1 call to B::Hooks::EndOfScope::__ANON__[B/Hooks/EndOfScope.pm:26] |
# spent 14µs within Hailo::Storage::SQLite::CORE:ftis which was called:
# once (14µs+0s) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:88] at line 87 | |||||
# spent 3µs within Hailo::Storage::SQLite::CORE:match which was called:
# once (3µs+0s) by Hailo::Storage::SQLite::_set_pragmas at line 110 | |||||
sub Hailo::Storage::SQLite::arguments; # xsub | |||||
# spent 22µs within Hailo::Storage::SQLite::brain which was called 13 times, avg 2µs/call:
# 6 times (8µs+0s) by Hailo::Storage::SQLite::_backup_memory_to_disk at line 49, avg 1µs/call
# once (4µs+0s) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:88] at line 84
# once (2µs+0s) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:42] at line 33
# once (2µs+0s) by Hailo::Storage::SQLite::save at line 124
# once (2µs+0s) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:42] at line 35
# once (1µs+0s) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:65] at line 60
# once (1µs+0s) by Hailo::Storage::SQLite::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm:42] at line 32
# once (1µs+0s) by Hailo::Storage::_build_dbi_options at line 62 of Hailo/Storage.pm | |||||
# spent 4µs within Hailo::Storage::SQLite::order which was called 2 times, avg 2µs/call:
# once (3µs+0s) by Hailo::Storage::_engage_initialized_check_and_set_order at line 147 of Hailo/Storage.pm
# once (2µs+0s) by Hailo::Storage::_build_sth at line 90 of Hailo/Storage.pm | |||||
# spent 4µs within Hailo::Storage::SQLite::tokenizer_class which was called:
# once (4µs+0s) by Hailo::Storage::_engage_initialized_check_and_set_tokenizer at line 177 of Hailo/Storage.pm |