← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/hailo
  Run on Thu Oct 21 22:50:37 2010
Reported on Thu Oct 21 22:52:09 2010

Filename/mnt/stuff/src/my-cpan/hailo/lib/Hailo/Storage/SQLite.pm
StatementsExecuted 73 statements in 1.28ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11157µs143µsHailo::Storage::SQLite::::BEGIN@3Hailo::Storage::SQLite::BEGIN@3
33151µs64µsHailo::Storage::SQLite::::_backup_memory_to_diskHailo::Storage::SQLite::_backup_memory_to_disk
11143µs273µsHailo::Storage::SQLite::::_set_pragmasHailo::Storage::SQLite::_set_pragmas
22139µs47µsHailo::Storage::SQLite::::readyHailo::Storage::SQLite::ready
11126µs51µsHailo::Storage::SQLite::::saveHailo::Storage::SQLite::save
11125µs360µsHailo::Storage::SQLite::::__ANON__[lib/Hailo/Storage/SQLite.pm:73]Hailo::Storage::SQLite::__ANON__[lib/Hailo/Storage/SQLite.pm:73]
11125µs160µsHailo::Storage::SQLite::::__ANON__[lib/Hailo/Storage/SQLite.pm:36]Hailo::Storage::SQLite::__ANON__[lib/Hailo/Storage/SQLite.pm:36]
11123µs302µsHailo::Storage::SQLite::::__ANON__[lib/Hailo/Storage/SQLite.pm:82]Hailo::Storage::SQLite::__ANON__[lib/Hailo/Storage/SQLite.pm:82]
11123µs47.4msHailo::Storage::SQLite::::__ANON__[lib/Hailo/Storage/SQLite.pm:66]Hailo::Storage::SQLite::__ANON__[lib/Hailo/Storage/SQLite.pm:66]
157221µs21µsHailo::Storage::SQLite::::brainHailo::Storage::SQLite::brain (xsub)
11119µs313µsHailo::Storage::SQLite::::__ANON__[lib/Hailo/Storage/SQLite.pm:59]Hailo::Storage::SQLite::__ANON__[lib/Hailo/Storage/SQLite.pm:59]
11115µs1.31msHailo::Storage::SQLite::::BEGIN@6Hailo::Storage::SQLite::BEGIN@6
11114µs86µsHailo::Storage::SQLite::::BEGIN@3.11Hailo::Storage::SQLite::BEGIN@3.11
11114µs715µsHailo::Storage::SQLite::::BEGIN@4Hailo::Storage::SQLite::BEGIN@4
11111µs360µsHailo::Storage::SQLite::::BEGIN@5Hailo::Storage::SQLite::BEGIN@5
1118µs25µsHailo::Storage::SQLite::::__ANON__[lib/Hailo/Storage/SQLite.pm:18]Hailo::Storage::SQLite::__ANON__[lib/Hailo/Storage/SQLite.pm:18]
4216µs6µsHailo::Storage::SQLite::::argumentsHailo::Storage::SQLite::arguments (xsub)
3314µs4µsHailo::Storage::SQLite::::orderHailo::Storage::SQLite::order (xsub)
1114µs4µsHailo::Storage::SQLite::::CORE:ftisHailo::Storage::SQLite::CORE:ftis (opcode)
1113µs3µsHailo::Storage::SQLite::::_build_dbdHailo::Storage::SQLite::_build_dbd
1112µs2µsHailo::Storage::SQLite::::tokenizer_classHailo::Storage::SQLite::tokenizer_class (xsub)
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
3474µs3301µs
# spent 143µs (57+86) within Hailo::Storage::SQLite::BEGIN@3 which was called: # once (57µs+86µs) by Hailo::_new_class at line 3 # spent 86µs (14+72) within Hailo::Storage::SQLite::BEGIN@3.11 which was called: # once (14µs+72µs) by Hailo::Storage::SQLite::BEGIN@3 at line 3
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
4233µs21.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
use Any::Moose;
# spent 715µs making 1 call to Hailo::Storage::SQLite::BEGIN@4 # spent 701µs making 1 call to Any::Moose::import
5233µs2708µ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
use Any::Moose 'X::StrictConstructor';
# spent 360µs making 1 call to Hailo::Storage::SQLite::BEGIN@5 # spent 348µs making 1 call to Any::Moose::import
62634µs22.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
use namespace::clean -except => 'meta';
# spent 1.31ms making 1 call to Hailo::Storage::SQLite::BEGIN@6 # spent 1.29ms making 1 call to namespace::clean::import
7
815µs119.4msextends 'Hailo::Storage';
# spent 19.4ms making 1 call to Mouse::extends
916µs119.4mswith qw(Hailo::Role::Arguments Hailo::Role::Storage);
# spent 19.4ms making 1 call to Mouse::with
10
1118µ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
sub _build_dbd { return 'SQLite' };
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
override _build_dbd_options => sub {
14 return {
1519µs117µs %{ super() },
# spent 17µs making 1 call to Mouse::super
16 sqlite_unicode => 1,
17 };
1817µs177µ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
around _build_dbi_options => sub {
21515µs my $orig = shift;
22 my $self = shift;
23
24 my $return;
2515µs121µ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 {
321114µs $return = $self->$orig(@_);
# spent 114µs making 1 call to Hailo::Storage::_build_dbi_options
33 }
34
35 return $return;
3618µs1120µ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
sub _backup_memory_to_disk {
41671µs my ($self) = @_;
42
43913µ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
before _engage => sub {
49417µs my ($self) = @_;
50
51 # Set any user-defined pragmas
521273µs $self->_set_pragmas;
# spent 273µs making 1 call to Hailo::Storage::SQLite::_set_pragmas
53
54121µ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;
59115µs198µ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
before start_training => sub {
62459µs493.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
6316µs2553µ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
6415µs2226µ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;
6617µs187µ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
after stop_training => sub {
69436µs14µs my $dbh = shift->dbh;
# spent 4µs making 1 call to Hailo::Storage::dbh
7015µs2416µ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
7115µs2224µ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;
7317µs196µ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
override initialized => sub {
76530µs my ($self) = @_;
77
7811µ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:';
812277µ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
8217µs168µ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
sub ready {
851049µs my ($self) = @_;
8623µs my $brain = $self->brain;
# spent 3µs making 2 calls to Hailo::Storage::SQLite::brain, avg 1µs/call
8722µs return unless defined $self->brain;
# spent 2µs making 2 calls to Hailo::Storage::SQLite::brain, avg 1µs/call
8823µ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
sub _set_pragmas {
93648µs my ($self) = @_;
94
95 my %pragmas;
96
97 # speedy defaults when DB is not kept in memory
9824µs if (!$self->{in_memory}) {
99 $pragmas{synchronous} = 'OFF';
100 $pragmas{journal_mode} = 'OFF';
101 }
102
10312µ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
10918µs6442µ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
sub save {
117533µs my ($self, $filename) = @_;
11812µs my $file = $filename // $self->brain;
# spent 2µs making 1 call to Hailo::Storage::SQLite::brain
119
12012µs return unless $self->_engaged;
# spent 2µs making 1 call to Hailo::Storage::_engaged
121122µ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
127123µs2129µ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
133Hailo::Storage::SQLite - A storage backend for L<Hailo|Hailo> using L<DBD::SQLite>
134
135=head1 SYNOPSIS
136
137As a module:
138
139 my $hailo = Hailo->new(
140 storage_class => 'SQLite',
141 );
142 $hailo->train("hailo.trn");
143
144From the command line:
145
146 hailo --train hailo.trn --storage SQLite
147
148See L<Hailo's documentation|Hailo> for other non-MySQL specific options.
149
150=head1 DESCRIPTION
151
152This backend maintains information in an SQLite database. It is the default
153storage backend.
154
155=head1 ATTRIBUTES
156
157=head2 C<storage_args>
158
159This is a hash reference which can have the following keys:
160
161=head3 C<pragma_*>
162
163Any option starting with B<'pragma_'> will be considered to be an L<SQLite
164pragma|http://www.sqlite.org/pragma.html> which will be set after we connect
165to the database. An example of this would be
166
167 storage_args => {
168 pragma_cache_size => 10000,
169 pragma_synchronous => 'OFF',
170 }
171
172Setting B<'pragma_cache_size'> in particular can be beneficial. It's the
173size of the page cache used by SQLite. See L<SQLite's
174documentation|http://www.sqlite.org/pragma.html#pragma_cache_size> for
175more information.
176
177Increasing it might speed up Hailo, especially when disk IO is slow on
178your machine. Obviously, you shouldn't bother with this option if
179L<B<'in_memory'>|/in_memory> is enabled.
180
181Setting B<'pragma_synchronous'> to B<'OFF'> or B<'pragma_journal_mode'>
182to B<'OFF'> will speed up operations at the expense of safety. Since Hailo
183is most likely not running as a mission-critical component this trade-off
184should be acceptable in most cases. If the database becomes corrupt
185it's easy to rebuild it by retraining from the input it was trained on
186to begin with. For performance reasons, these two are set to B<'OFF'>
187by default unless L<B<'in_memory'>|/in_memory> is enabled.
188
189=head3 C<in_memory>
190
191When set to a true value, Hailo behaves much like MegaHAL. The entire
192database will be kept in memory, and only written out to disk when the
193L<C<save>|Hailo/save> method is called and/or when the Hailo object gets
194destroyed (unless you disabled
195L<C<save_on_exit>|Hailo/save_on_exit>). This is disabled by default.
196
197=head1 AUTHOR
198
199E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org>
200
201Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com
202
203=head1 LICENSE AND COPYRIGHT
204
205Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason and
206Hinrik E<Ouml>rn SigurE<eth>sson
207
208This program is free software, you can redistribute it and/or modify
209it under the same terms as Perl itself.
210
211111µs13.83ms=cut
 
# 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::CORE:ftis; # opcode
# spent 6µs within Hailo::Storage::SQLite::arguments which was called 4 times, avg 1µs/call: # 3 times (4µs+0s) by Hailo::Storage::SQLite::_backup_memory_to_disk at line 43, avg 1µs/call # once (2µs+0s) by Hailo::Storage::SQLite::_set_pragmas at line 103
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
sub Hailo::Storage::SQLite::brain; # xsub
# 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
sub Hailo::Storage::SQLite::order; # xsub
# 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
sub Hailo::Storage::SQLite::tokenizer_class; # xsub