← Index
NYTProf Performance Profile   « block view • line view • sub view »
For reply.pl
  Run on Thu Oct 21 22:40:13 2010
Reported on Thu Oct 21 22:44:43 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Hailo/Storage/SQLite.pm
StatementsExecuted 61 statements in 4.30s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11164µs3.92sHailo::Storage::SQLite::::saveHailo::Storage::SQLite::save
11163µs6.23msHailo::Storage::SQLite::::_set_pragmasHailo::Storage::SQLite::_set_pragmas
11159µs385msHailo::Storage::SQLite::::__ANON__[:65]Hailo::Storage::SQLite::__ANON__[:65]
11147µs145µsHailo::Storage::SQLite::::BEGIN@9Hailo::Storage::SQLite::BEGIN@9
33144µs56µsHailo::Storage::SQLite::::_backup_memory_to_diskHailo::Storage::SQLite::_backup_memory_to_disk
11142µs861µsHailo::Storage::SQLite::::__ANON__[:88]Hailo::Storage::SQLite::__ANON__[:88]
11136µs175µsHailo::Storage::SQLite::::__ANON__[:42]Hailo::Storage::SQLite::__ANON__[:42]
138222µs22µsHailo::Storage::SQLite::::brainHailo::Storage::SQLite::brain (xsub)
11121µs21µsHailo::Storage::SQLite::::BEGIN@2Hailo::Storage::SQLite::BEGIN@2
11114µs14µsHailo::Storage::SQLite::::CORE:ftisHailo::Storage::SQLite::CORE:ftis (opcode)
11113µs98µsHailo::Storage::SQLite::::BEGIN@9.5Hailo::Storage::SQLite::BEGIN@9.5
11112µs683µsHailo::Storage::SQLite::::BEGIN@10Hailo::Storage::SQLite::BEGIN@10
11112µs1.26msHailo::Storage::SQLite::::BEGIN@12Hailo::Storage::SQLite::BEGIN@12
11111µs348µsHailo::Storage::SQLite::::BEGIN@11Hailo::Storage::SQLite::BEGIN@11
1119µs31µsHailo::Storage::SQLite::::__ANON__[:24]Hailo::Storage::SQLite::__ANON__[:24]
5218µs8µsHailo::Storage::SQLite::::argumentsHailo::Storage::SQLite::arguments (xsub)
1115µs5µsHailo::Storage::SQLite::::BEGIN@5Hailo::Storage::SQLite::BEGIN@5
2214µs4µsHailo::Storage::SQLite::::orderHailo::Storage::SQLite::order (xsub)
1114µs4µsHailo::Storage::SQLite::::tokenizer_classHailo::Storage::SQLite::tokenizer_class (xsub)
1113µs3µsHailo::Storage::SQLite::::_build_dbdHailo::Storage::SQLite::_build_dbd
1113µs3µsHailo::Storage::SQLite::::CORE:matchHailo::Storage::SQLite::CORE:match (opcode)
0000s0sHailo::Storage::SQLite::::__ANON__[:72]Hailo::Storage::SQLite::__ANON__[:72]
0000s0sHailo::Storage::SQLite::::__ANON__[:79]Hailo::Storage::SQLite::__ANON__[:79]
0000s0sHailo::Storage::SQLite::::readyHailo::Storage::SQLite::ready
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package 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
BEGIN {
3112µs $Hailo::Storage::SQLite::AUTHORITY = 'cpan:AVAR';
4123µs121µ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
BEGIN {
615µs $Hailo::Storage::SQLite::VERSION = '0.57';
7119µs15µs}
# spent 5µs making 1 call to Hailo::Storage::SQLite::BEGIN@5
8
9477µs3329µs
# spent 145µs (47+98) within Hailo::Storage::SQLite::BEGIN@9 which was called: # once (47µs+98µs) by Hailo::_new_class at line 9 # spent 98µs (13+85) within Hailo::Storage::SQLite::BEGIN@9.5 which was called: # once (13µs+85µs) by Hailo::Storage::SQLite::BEGIN@9 at line 9
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
10231µs21.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
use Any::Moose;
# spent 683µs making 1 call to Hailo::Storage::SQLite::BEGIN@10 # spent 671µs making 1 call to Any::Moose::import
11232µs2685µ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
use Any::Moose 'X::StrictConstructor';
# spent 348µs making 1 call to Hailo::Storage::SQLite::BEGIN@11 # spent 337µs making 1 call to Any::Moose::import
122674µs22.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
use namespace::clean -except => 'meta';
# spent 1.26ms making 1 call to Hailo::Storage::SQLite::BEGIN@12 # spent 1.25ms making 1 call to namespace::clean::import
13
1414µs121.2msextends 'Hailo::Storage';
# spent 21.2ms making 1 call to Mouse::extends
1515µs122.8mswith qw(Hailo::Role::Arguments Hailo::Role::Storage);
# spent 22.8ms making 1 call to Mouse::with
16
1715µ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
sub _build_dbd { return 'SQLite' };
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
override _build_dbd_options => sub {
20 return {
21110µs121µs %{ super() },
# spent 21µs making 1 call to Mouse::super
22 sqlite_unicode => 1,
23 };
2418µs185µ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
around _build_dbi_options => sub {
2711µs my $orig = shift;
2811µs my $self = shift;
29
3011µs my $return;
3116µs119µs if ($self->_backup_memory_to_disk) {
# spent 19µs making 1 call to Hailo::Storage::SQLite::_backup_memory_to_disk
3216µs11µs my $file = $self->brain;
# spent 1µs making 1 call to Hailo::Storage::SQLite::brain
3317µs12µs $self->brain(':memory:');
# spent 2µs making 1 call to Hailo::Storage::SQLite::brain
3415µs1115µs $return = $self->$orig(@_);
# spent 115µs making 1 call to Hailo::Storage::_build_dbi_options
3517µs12µs $self->brain($file);
# spent 2µs making 1 call to Hailo::Storage::SQLite::brain
36 }
37 else {
38 $return = $self->$orig(@_);
39 }
40
4115µs return $return;
42111µs1132µ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
sub _backup_memory_to_disk {
4734µs my ($self) = @_;
48
49357µs913µ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
before _engage => sub {
5512µs my ($self) = @_;
56
57 # Set any user-defined pragmas
5814µs16.23ms $self->_set_pragmas;
# spent 6.23ms making 1 call to Hailo::Storage::SQLite::_set_pragmas
59
601379ms4379ms 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
64174µs return;
6517µs1109µs};
# spent 109µs making 1 call to Mouse::before
66
67before start_training => sub {
68 my $dbh = shift->dbh;
69 $dbh->do('PRAGMA synchronous=OFF;');
70 $dbh->do('PRAGMA journal_mode=OFF;');
71 return;
7216µs189µs};
# spent 89µs making 1 call to Mouse::before
73
74after stop_training => sub {
75 my $dbh = shift->dbh;
76 $dbh->do('PRAGMA journal_mode=DELETE;');
77 $dbh->do('PRAGMA synchronous=ON;');
78 return;
7917µs194µ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
override initialized => sub {
8212µs my ($self) = @_;
83
84115µs14µs my $brain = $self->brain;
# spent 4µs making 1 call to Hailo::Storage::SQLite::brain
8512µs return unless defined $brain;
8612µs return if $brain eq ':memory:';
87142µs2815µ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
8816µs168µs};
# spent 68µs making 1 call to Mouse::override
89
90sub 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
sub _set_pragmas {
9912µs my ($self) = @_;
100
10111µs my %pragmas;
102
103 # speedy defaults when DB is not kept in memory
10412µs if (!$self->{in_memory}) {
10512µs $pragmas{synchronous} = 'OFF';
10611µs $pragmas{journal_mode} = 'OFF';
107 }
108
109118µs23µs while (my ($k, $v) = each %{ $self->arguments }) {
# spent 3µs making 2 calls to Hailo::Storage::SQLite::arguments, avg 2µs/call
110111µs13µ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
115172µs912.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
11917µs 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
sub save {
12312µs my ($self, $filename) = @_;
124110µs12µs my $file = $filename // $self->brain;
# spent 2µs making 1 call to Hailo::Storage::SQLite::brain
125
12616µs12µs return unless $self->_engaged;
# spent 2µs making 1 call to Hailo::Storage::_engaged
12713.92s33.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 }
130111µs return;
131};
132
133123µs2132µ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
139Hailo::Storage::SQLite - A storage backend for L<Hailo|Hailo> using L<DBD::SQLite>
140
141=head1 SYNOPSIS
142
143As a module:
144
145 my $hailo = Hailo->new(
146 storage_class => 'SQLite',
147 );
148 $hailo->train("hailo.trn");
149
150From the command line:
151
152 hailo --train hailo.trn --storage SQLite
153
154See L<Hailo's documentation|Hailo> for other non-MySQL specific options.
155
156=head1 DESCRIPTION
157
158This backend maintains information in an SQLite database. It is the default
159storage backend.
160
161=head1 ATTRIBUTES
162
163=head2 C<storage_args>
164
165This is a hash reference which can have the following keys:
166
167=head3 C<pragma_*>
168
169Any option starting with B<'pragma_'> will be considered to be an L<SQLite
170pragma|http://www.sqlite.org/pragma.html> which will be set after we connect
171to the database. An example of this would be
172
173 storage_args => {
174 pragma_cache_size => 10000,
175 pragma_synchronous => 'OFF',
176 }
177
178Setting B<'pragma_cache_size'> in particular can be beneficial. It's the
179size of the page cache used by SQLite. See L<SQLite's
180documentation|http://www.sqlite.org/pragma.html#pragma_cache_size> for
181more information.
182
183Increasing it might speed up Hailo, especially when disk IO is slow on
184your machine. Obviously, you shouldn't bother with this option if
185L<B<'in_memory'>|/in_memory> is enabled.
186
187Setting B<'pragma_synchronous'> to B<'OFF'> or B<'pragma_journal_mode'>
188to B<'OFF'> will speed up operations at the expense of safety. Since Hailo
189is most likely not running as a mission-critical component this trade-off
190should be acceptable in most cases. If the database becomes corrupt
191it's easy to rebuild it by retraining from the input it was trained on
192to begin with. For performance reasons, these two are set to B<'OFF'>
193by default unless L<B<'in_memory'>|/in_memory> is enabled.
194
195=head3 C<in_memory>
196
197When set to a true value, Hailo behaves much like MegaHAL. The entire
198database will be kept in memory, and only written out to disk when the
199L<C<save>|Hailo/save> method is called and/or when the Hailo object gets
200destroyed (unless you disabled
201L<C<save_on_exit>|Hailo/save_on_exit>). This is disabled by default.
202
203=head1 AUTHOR
204
205E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org>
206
207Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com
208
209=head1 LICENSE AND COPYRIGHT
210
211Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason and
212Hinrik E<Ouml>rn SigurE<eth>sson
213
214This program is free software, you can redistribute it and/or modify
215it under the same terms as Perl itself.
216
217112µs13.84ms=cut
 
# 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
sub Hailo::Storage::SQLite::CORE:ftis; # opcode
# 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::CORE:match; # opcode
# spent 8µs within Hailo::Storage::SQLite::arguments which was called 5 times, avg 2µs/call: # 3 times (5µs+0s) by Hailo::Storage::SQLite::_backup_memory_to_disk at line 49, avg 2µs/call # 2 times (3µs+0s) by Hailo::Storage::SQLite::_set_pragmas at line 109, avg 2µs/call
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
sub Hailo::Storage::SQLite::brain; # xsub
# 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
sub Hailo::Storage::SQLite::order; # xsub
# 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
sub Hailo::Storage::SQLite::tokenizer_class; # xsub