1 BEGIN { eval "use Devel::AutoProfiler;"; } #only if installed...
2 #BEGIN { package Devel::AutoProfiler; use vars qw(%caller_info); }
3 #use Devel::AutoProfiler;
6 use vars qw( $cgi $p );
9 #use CGI::Carp qw(fatalsToBrowser);
17 use String::Approx qw(amatch);
18 use Chart::LinesPoints;
19 use HTML::Widgets::SelectLayers 0.03;
20 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
21 use FS::Record qw(qsearch qsearchs fields dbdef);
23 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
24 small_custview myexit http_header);
25 use FS::Msgcat qw(gettext geterror);
26 use FS::Misc qw( send_email );
27 use FS::Report::Table::Monthly;
31 use FS::domain_record;
33 use FS::cust_bill_pay;
35 use FS::cust_credit_bill;
37 use FS::cust_main_county;
43 use FS::part_bill_event;
45 use FS::part_referral;
47 use FS::part_svc_router;
48 use FS::part_virtual_field;
51 use FS::queue qw(joblisting);
55 use FS::svc_acct_pop qw(popselector);
61 use FS::svc_broadband;
65 use FS::part_export_option;
70 $Response->AddHeader('Pragma' => 'no-cache');
71 $Response->AddHeader('Cache-control' => 'no-cache');
72 # $Response->AddHeader('Expires' => 0);
73 $Response->{Expires} = -36288000;
78 #print $cgi->header( '-expires' => 'now' );
79 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
80 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
82 #really should check for FS::Profiler or something
83 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
84 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
85 #should check to see it's my special version. well, switch to FS::Profiler
87 #nicked from Devel::AutoProfiler::INIT
88 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
91 SUB : while( my ($name, $ref) = each(%subs) )
93 #next if $name =~ /^(main::)?Apache::/;
94 next unless $name =~ /FS/;
95 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
102 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
103 #warn "INIT name is $name \n";
104 Devel::AutoProfiler::__instrument_sub($name, $ref);
112 my $ref = $Response->{BinaryRef};
113 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
114 #$$ref = $cgi->header() . $$ref;
115 #warn "Script_OnFlush called with dbh ". dbh. "\n";
116 #if ( dbh->can('sprintProfile') ) {
117 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
118 #warn "dbh can sprintProfile\n";
119 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
120 #warn "contenttype is sprintProfile\n";
121 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
122 or warn "can't remove";
124 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
126 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
127 "\n\n". &sprintAutoProfile(). '</PRE>';
129 $$ref .= '</BODY></HTML>';
131 dbh->{'private_profile'} = {};
135 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
136 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
137 if ( defined(@DBIx::Profile::ISA) ) {
139 #warn "enabling profiling redirects";
140 *CGI::redirect = sub {
141 my( $self, $location) = @_;
144 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
146 ( UNIVERSAL::can(dbh, 'sprintProfile')
147 ? encode_entities(dbh->sprintProfile())
148 : 'DBIx::Profile missing sprintProfile method;'.
149 'unpatched or too old?' ).
150 "\n\n". &sprintAutoProfile(). '</PRE>'.
152 dbh->{'private_profile'} = {};
160 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
163 sub sprintAutoProfile {
164 my %caller_info = %Devel::AutoProfiler::caller_info;
165 return unless keys %caller_info;
167 %Devel::AutoProfiler::caller_info = ();
169 my @keys = keys(%caller_info);
171 foreach my $key (@keys)
173 my $href = $caller_info{$key};
175 $href->{who_am_i} = $key;
178 my @subs = values(%caller_info);
180 #my @sorted = sort by_total_time ( @subs );
181 my @sorted = reverse sort by_total_time ( @subs );
183 # print Dumper \@sorted;
187 foreach my $sort (@sorted)
189 push(@readable_info, delete($sort->{who_am_i}));
190 push(@readable_info, $sort);
194 return encode_entities(Dumper(\@readable_info));
199 $Response->Include(@_);
202 if ( defined(@DBIx::Profile::ISA) ) {
204 #false laziness w/above
208 ${$Response->{BinaryRef}} =
210 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
212 ( UNIVERSAL::can(dbh, 'sprintProfile')
213 ? encode_entities(dbh->sprintProfile())
214 : 'DBIx::Profile missing sprintProfile method;'.
215 'unpatched or too old?' ).
216 "\n\n". &sprintAutoProfile(). '</PRE>'.
219 dbh->{'private_profile'} = {};
228 $Response->Redirect(@_);