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