← Index
NYTProf Performance Profile   « block view • line view • sub view »
For ddd2.pl
  Run on Tue May 25 16:52:24 2010
Reported on Tue May 25 16:56:52 2010

File /project/perl/lib/Class/DBI/ColumnGrouper.pm
Statements Executed 4344
Statement Execution Time 52.9ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4662126.6ms47.9msClass::DBI::ColumnGrouper::::find_columnClass::DBI::ColumnGrouper::find_column
4672217.4ms29.0msClass::DBI::ColumnGrouper::::primaryClass::DBI::ColumnGrouper::primary
4733111.7ms12.1msClass::DBI::ColumnGrouper::::group_colsClass::DBI::ColumnGrouper::group_cols
411677µs2.45msClass::DBI::ColumnGrouper::::add_groupClass::DBI::ColumnGrouper::add_group
1011568µs1.14msClass::DBI::ColumnGrouper::::add_columnClass::DBI::ColumnGrouper::add_column
521212µs364µsClass::DBI::ColumnGrouper::::_uniqClass::DBI::ColumnGrouper::_uniq
422186µs968µsClass::DBI::ColumnGrouper::::columns_inClass::DBI::ColumnGrouper::columns_in
322169µs610µsClass::DBI::ColumnGrouper::::essentialClass::DBI::ColumnGrouper::essential
411131µs903µsClass::DBI::ColumnGrouper::::cloneClass::DBI::ColumnGrouper::clone
11176µs330µsClass::DBI::ColumnGrouper::::all_columnsClass::DBI::ColumnGrouper::all_columns
11156µs114µsClass::DBI::ColumnGrouper::::groups_forClass::DBI::ColumnGrouper::groups_for
11136µs36µsClass::DBI::ColumnGrouper::::newClass::DBI::ColumnGrouper::new
0000s0sClass::DBI::ColumnGrouper::::BEGINClass::DBI::ColumnGrouper::BEGIN
0000s0sClass::DBI::ColumnGrouper::::_uniqueClass::DBI::ColumnGrouper::_unique
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Class::DBI::ColumnGrouper;
2
3=head1 NAME
4
5Class::DBI::ColumnGrouper - Columns and Column Groups
6
7=head1 SYNOPSIS
8
9 my $colg = Class::DBI::ColumnGrouper->new;
10 $colg->add_group(People => qw/star director producer/);
11
12 my @cols = $colg->group_cols($group);
13
14 my @all = $colg->all_columns;
15 my @pri_col = $colg->primary;
16 my @essential_cols = $colg->essential;
17
18=head1 DESCRIPTION
19
20Each Class::DBI class maintains a list of its columns as class data.
21This provides an interface to that. You probably don't want to be dealing
22with this directly.
23
24=head1 METHODS
25
26=cut
27
283103µs124µsuse strict;
# spent 24µs making 1 call to strict::import
29
303105µs1260µsuse Carp;
# spent 260µs making 1 call to Exporter::import
313399µs1472µsuse Storable 'dclone';
# spent 472µs making 1 call to Exporter::import
3231.78msuse Class::DBI::Column;
33
34sub _unique {
35 my %seen;
36 map { $seen{$_}++ ? () : $_ } @_;
37}
38
39
# spent 364µs (212+152) within Class::DBI::ColumnGrouper::_uniq which was called 5 times, avg 73µs/call: # 4 times (189µs+152µs) by Class::DBI::ColumnGrouper::columns_in at line 149, avg 85µs/call # once (23µs+0s) by Class::DBI::ColumnGrouper::groups_for at line 136
sub _uniq {
401097µs my %tmp;
41145µs return grep !$tmp{$_}++, @_;
42}
43
44=head2 new
45
46 my $colg = Class::DBI::ColumnGrouper->new;
47
48A new blank ColumnnGrouper object.
49
50=head2 clone
51
52 my $colg2 = $colg->clone;
53
54Clone an existing ColumnGrouper.
55
56=cut
57
58
# spent 36µs within Class::DBI::ColumnGrouper::new which was called # once (36µs+0s) by base::import at line 86 of Class/DBI.pm
sub new {
59243µs my $class = shift;
60 bless {
61 _groups => {},
62 _cols => {},
63 }, $class;
64}
65
66
# spent 903µs (131+772) within Class::DBI::ColumnGrouper::clone which was called 4 times, avg 226µs/call: # 4 times (131µs+772µs) by Class::DBI::_set_columns at line 249 of Class/DBI.pm, avg 226µs/call
sub clone {
678911µs my ($class, $prev) = @_;
68 return dclone $prev;
# spent 772µs making 4 calls to Storable::dclone, avg 193µs/call
69}
70
71=head2 add_column / find_column
72
73 $colg->add_column($name);
74 my Class::DBI::Column $col = $colg->find_column($name);
75
76Add or return a Column object for the given column name.
77
78=cut
79
80
# spent 1.14ms (568µs+572µs) within Class::DBI::ColumnGrouper::add_column which was called 10 times, avg 114µs/call: # 10 times (568µs+572µs) by Class::DBI::ColumnGrouper::add_group at line 112, avg 114µs/call
sub add_column {
8130598µs my ($self, $col) = @_;
82
83 # TODO remove this
84 croak "Need a Column, got $col" unless $col->isa("Class::DBI::Column");
# spent 104µs making 10 calls to UNIVERSAL::isa, avg 10µs/call
85128µs10396µs $self->{_allcol}->{ $col->name_lc } ||= $col;
# spent 396µs making 10 calls to Class::DBI::Column::name_lc, avg 40µs/call
86}
87
88
# spent 47.9ms (26.6+21.3) within Class::DBI::ColumnGrouper::find_column which was called 466 times, avg 103µs/call: # 463 times (26.4ms+21.2ms) by Class::DBI::_find_columns at line 295 of Class/DBI.pm, avg 103µs/call # 3 times (165µs+126µs) by Class::DBI::find_column at line 289 of Class/DBI.pm, avg 97µs/call
sub find_column {
89139811.2ms my ($self, $name) = @_;
90 return $name if ref $name;
9117.00ms return unless $self->{_allcol}->{ lc $name };
92}
93
94=head2 add_group
95
96 $colg->add_group(People => qw/star director producer/);
97
98This adds a list of columns as a column group.
99
100=cut
101
102
# spent 2.45ms (677µs+1.78) within Class::DBI::ColumnGrouper::add_group which was called 4 times, avg 613µs/call: # 4 times (677µs+1.78ms) by Class::DBI::_set_columns at line 249 of Class/DBI.pm, avg 613µs/call
sub add_group {
10336489µs my ($self, $group, @names) = @_;
104 $self->add_group(Primary => $names[0])
# spent 47µs making 2 calls to Class::DBI::ColumnGrouper::group_cols, avg 24µs/call
105 if ($group eq "All" or $group eq "Essential")
106 and not $self->group_cols('Primary');
107 $self->add_group(Essential => @names)
# spent 399µs making 2 calls to Class::DBI::ColumnGrouper::essential, avg 200µs/call
108 if $group eq "All"
109 and !$self->essential;
110 @names = _unique($self->primary, @names) if $group eq "Essential";
111
112 my @cols = map $self->add_column($_), @names;
# spent 1.14ms making 10 calls to Class::DBI::ColumnGrouper::add_column, avg 114µs/call
113 $_->add_group($group) foreach @cols;
# spent 190µs making 10 calls to Class::DBI::Column::add_group, avg 19µs/call
1141144µs $self->{_groups}->{$group} = \@cols;
115 return $self;
116}
117
118=head2 group_cols / groups_for
119
120 my @colg = $cols->group_cols($group);
121 my @groups = $cols->groups_for(@cols);
122
123This returns a list of all columns which are in the given group, or the
124groups a given column is in.
125
126=cut
127
128
# spent 12.1ms (11.7+330µs) within Class::DBI::ColumnGrouper::group_cols which was called 473 times, avg 26µs/call: # 467 times (11.6ms+0s) by Class::DBI::ColumnGrouper::primary at line 178, avg 25µs/call # 4 times (111µs+330µs) by Class::DBI::ColumnGrouper::columns_in at line 149, avg 110µs/call # 2 times (47µs+0s) by Class::DBI::ColumnGrouper::add_group at line 104, avg 24µs/call
sub group_cols {
129141813.2ms my ($self, $group) = @_;
130 return $self->all_columns if $group eq "All";
# spent 330µs making 1 call to Class::DBI::ColumnGrouper::all_columns
131 @{ $self->{_groups}->{$group} || [] };
132}
133
134
# spent 114µs (56+58) within Class::DBI::ColumnGrouper::groups_for which was called # once (56µs+58µs) by Class::DBI::get at line 844 of Class/DBI.pm
sub groups_for {
135249µs my ($self, @cols) = @_;
136 return _uniq(map $_->groups, @cols);
# spent 35µs making 1 call to Class::DBI::Column::groups # spent 23µs making 1 call to Class::DBI::ColumnGrouper::_uniq
137}
138
139=head2 columns_in
140
141 my @cols = $colg->columns_in(@groups);
142
143This returns a list of all columns which are in the given groups.
144
145=cut
146
147
# spent 968µs (186+782) within Class::DBI::ColumnGrouper::columns_in which was called 4 times, avg 242µs/call: # 3 times (142µs+127µs) by Class::DBI::ColumnGrouper::essential at line 191, avg 90µs/call # once (44µs+655µs) by Class::DBI::_flesh at line 854 of Class/DBI.pm
sub columns_in {
1488177µs my ($self, @groups) = @_;
149 return _uniq(map $self->group_cols($_), @groups);
# spent 441µs making 4 calls to Class::DBI::ColumnGrouper::group_cols, avg 110µs/call # spent 341µs making 4 calls to Class::DBI::ColumnGrouper::_uniq, avg 85µs/call
150}
151
152=head2 all_columns
153
154 my @all = $colg->all_columns;
155
156This returns a list of all the real columns.
157
158=head2 primary
159
160 my $pri_col = $colg->primary;
161
162This returns a list of the columns in the Primary group.
163
164=head2 essential
165
166 my @essential_cols = $colg->essential;
167
168This returns a list of the columns in the Essential group.
169
170=cut
171
172
# spent 330µs (76+254) within Class::DBI::ColumnGrouper::all_columns which was called # once (76µs+254µs) by Class::DBI::ColumnGrouper::group_cols at line 130
sub all_columns {
173278µs my $self = shift;
174 return grep $_->in_database, values %{ $self->{_allcol} };
# spent 254µs making 4 calls to Class::DBI::Column::in_database, avg 64µs/call
175}
176
177
# spent 29.0ms (17.4+11.6) within Class::DBI::ColumnGrouper::primary which was called 467 times, avg 62µs/call: # 464 times (17.3ms+11.5ms) by Class::DBI::primary_column at line 275 of Class/DBI.pm, avg 62µs/call # 3 times (107µs+65µs) by Class::DBI::ColumnGrouper::essential at line 192, avg 57µs/call
sub primary {
178140116.4ms46711.6ms my @cols = shift->group_cols('Primary');
# spent 11.6ms making 467 calls to Class::DBI::ColumnGrouper::group_cols, avg 25µs/call
179 if (!wantarray && @cols > 1) {
180 local ($Carp::CarpLevel) = 1;
181 confess(
182 "Multiple columns in Primary group (@cols) but primary called in scalar context"
183 );
184 return $cols[0];
185 }
186 return @cols;
187}
188
189
# spent 610µs (169+441) within Class::DBI::ColumnGrouper::essential which was called 3 times, avg 203µs/call: # 2 times (114µs+285µs) by Class::DBI::ColumnGrouper::add_group at line 107, avg 200µs/call # once (55µs+156µs) by Class::DBI::_essential at line 285 of Class/DBI.pm
sub essential {
19012163µs my $self = shift;
191 my @cols = $self->columns_in('Essential');
# spent 269µs making 3 calls to Class::DBI::ColumnGrouper::columns_in, avg 90µs/call
192 @cols = $self->primary unless @cols;
# spent 172µs making 3 calls to Class::DBI::ColumnGrouper::primary, avg 57µs/call
193 return @cols;
194}
195
196114µs1;