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);
20 use Net::Whois::Raw qw(whois);
22 eval "use Net::Whois::Raw 0.32 qw(whois)";
26 use Spreadsheet::WriteExcel;
27 use Business::CreditCard;
28 use String::Approx qw(amatch);
29 use Chart::LinesPoints;
30 use HTML::Widgets::SelectLayers 0.03;
32 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
33 use FS::Record qw(qsearch qsearchs fields dbdef);
35 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
36 small_custview myexit http_header);
38 use FS::Msgcat qw(gettext geterror);
39 use FS::Misc qw( send_email );
40 use FS::Report::Table::Monthly;
45 use FS::domain_record;
47 use FS::cust_bill_pay;
49 use FS::cust_credit_bill;
51 use FS::cust_main_county;
57 use FS::part_bill_event;
59 use FS::part_referral;
61 use FS::part_svc_router;
62 use FS::part_virtual_field;
65 use FS::queue qw(joblisting);
69 use FS::svc_acct_pop qw(popselector);
75 use FS::svc_broadband;
79 use FS::part_export_option;
87 $Response->AddHeader('Cache-control' => 'no-cache');
88 # $Response->AddHeader('Expires' => 0);
89 $Response->{Expires} = -36288000;
94 #print $cgi->header( '-expires' => 'now' );
95 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
96 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
98 #really should check for FS::Profiler or something
99 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
100 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
101 #should check to see it's my special version. well, switch to FS::Profiler
103 #nicked from Devel::AutoProfiler::INIT
104 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
107 SUB : while( my ($name, $ref) = each(%subs) )
109 #next if $name =~ /^(main::)?Apache::/;
110 next unless $name =~ /FS/;
111 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
118 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
119 #warn "INIT name is $name \n";
120 Devel::AutoProfiler::__instrument_sub($name, $ref);
128 my $ref = $Response->{BinaryRef};
129 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
130 #$$ref = $cgi->header() . $$ref;
131 #warn "Script_OnFlush called with dbh ". dbh. "\n";
132 #if ( dbh->can('sprintProfile') ) {
133 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
134 #warn "dbh can sprintProfile\n";
135 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
136 #warn "contenttype is sprintProfile\n";
137 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
138 or warn "can't remove";
140 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
142 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
143 "\n\n". &sprintAutoProfile(). '</PRE>';
145 $$ref .= '</BODY></HTML>';
147 dbh->{'private_profile'} = {};
151 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
152 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
153 if ( defined(@DBIx::Profile::ISA) ) {
155 #warn "enabling profiling redirects";
156 *CGI::redirect = sub {
157 my( $self, $location) = @_;
160 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
162 ( UNIVERSAL::can(dbh, 'sprintProfile')
163 ? encode_entities(dbh->sprintProfile())
164 : 'DBIx::Profile missing sprintProfile method;'.
165 'unpatched or too old?' ).
166 "\n\n". &sprintAutoProfile(). '</PRE>'.
168 dbh->{'private_profile'} = {};
176 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
179 sub sprintAutoProfile {
180 my %caller_info = %Devel::AutoProfiler::caller_info;
181 return unless keys %caller_info;
183 %Devel::AutoProfiler::caller_info = ();
185 my @keys = keys(%caller_info);
187 foreach my $key (@keys)
189 my $href = $caller_info{$key};
191 $href->{who_am_i} = $key;
194 my @subs = values(%caller_info);
196 #my @sorted = sort by_total_time ( @subs );
197 my @sorted = reverse sort by_total_time ( @subs );
199 # print Dumper \@sorted;
203 foreach my $sort (@sorted)
205 push(@readable_info, delete($sort->{who_am_i}));
206 push(@readable_info, $sort);
210 return encode_entities(Dumper(\@readable_info));
217 if ( $file =~ m(^([^/].*)/[^/]+) ) {
218 unshift @{$Response->{asp}{includes_dir}}, "./$1";
221 $file =~ s(^/)(%%%FREESIDE_DOCUMENT_ROOT%%%/);
222 #broken in 5.005# ${$Response->TrapInclude($file, @_)};
223 my $ref = $Response->TrapInclude($file, @_);
224 shift @{$Response->{asp}{includes_dir}} if $shift;
228 if ( defined(@DBIx::Profile::ISA) ) {
230 #false laziness w/above
234 ${$Response->{BinaryRef}} =
236 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
238 ( UNIVERSAL::can(dbh, 'sprintProfile')
239 ? encode_entities(dbh->sprintProfile())
240 : 'DBIx::Profile missing sprintProfile method;'.
241 'unpatched or too old?' ).
242 "\n\n". &sprintAutoProfile(). '</PRE>'.
245 dbh->{'private_profile'} = {};
254 $Response->Redirect(@_);