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 Net::Whois::Raw qw(whois);
18 use Business::CreditCard;
19 use String::Approx qw(amatch);
20 use Chart::LinesPoints;
21 use HTML::Widgets::SelectLayers 0.03;
22 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
23 use FS::Record qw(qsearch qsearchs fields dbdef);
25 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
26 small_custview myexit http_header);
27 use FS::Msgcat qw(gettext geterror);
28 use FS::Misc qw( send_email );
29 use FS::Report::Table::Monthly;
33 use FS::domain_record;
35 use FS::cust_bill_pay;
37 use FS::cust_credit_bill;
39 use FS::cust_main_county;
45 use FS::part_bill_event;
47 use FS::part_referral;
49 use FS::part_svc_router;
50 use FS::part_virtual_field;
53 use FS::queue qw(joblisting);
57 use FS::svc_acct_pop qw(popselector);
63 use FS::svc_broadband;
67 use FS::part_export_option;
72 $Response->AddHeader('Cache-control' => 'no-cache');
73 # $Response->AddHeader('Expires' => 0);
74 $Response->{Expires} = -36288000;
79 #print $cgi->header( '-expires' => 'now' );
80 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
81 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
83 #really should check for FS::Profiler or something
84 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
85 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
86 #should check to see it's my special version. well, switch to FS::Profiler
88 #nicked from Devel::AutoProfiler::INIT
89 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
92 SUB : while( my ($name, $ref) = each(%subs) )
94 #next if $name =~ /^(main::)?Apache::/;
95 next unless $name =~ /FS/;
96 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
103 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
104 #warn "INIT name is $name \n";
105 Devel::AutoProfiler::__instrument_sub($name, $ref);
113 my $ref = $Response->{BinaryRef};
114 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
115 #$$ref = $cgi->header() . $$ref;
116 #warn "Script_OnFlush called with dbh ". dbh. "\n";
117 #if ( dbh->can('sprintProfile') ) {
118 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
119 #warn "dbh can sprintProfile\n";
120 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
121 #warn "contenttype is sprintProfile\n";
122 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
123 or warn "can't remove";
125 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
127 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
128 "\n\n". &sprintAutoProfile(). '</PRE>';
130 $$ref .= '</BODY></HTML>';
132 dbh->{'private_profile'} = {};
136 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
137 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
138 if ( defined(@DBIx::Profile::ISA) ) {
140 #warn "enabling profiling redirects";
141 *CGI::redirect = sub {
142 my( $self, $location) = @_;
145 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
147 ( UNIVERSAL::can(dbh, 'sprintProfile')
148 ? encode_entities(dbh->sprintProfile())
149 : 'DBIx::Profile missing sprintProfile method;'.
150 'unpatched or too old?' ).
151 "\n\n". &sprintAutoProfile(). '</PRE>'.
153 dbh->{'private_profile'} = {};
161 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
164 sub sprintAutoProfile {
165 my %caller_info = %Devel::AutoProfiler::caller_info;
166 return unless keys %caller_info;
168 %Devel::AutoProfiler::caller_info = ();
170 my @keys = keys(%caller_info);
172 foreach my $key (@keys)
174 my $href = $caller_info{$key};
176 $href->{who_am_i} = $key;
179 my @subs = values(%caller_info);
181 #my @sorted = sort by_total_time ( @subs );
182 my @sorted = reverse sort by_total_time ( @subs );
184 # print Dumper \@sorted;
188 foreach my $sort (@sorted)
190 push(@readable_info, delete($sort->{who_am_i}));
191 push(@readable_info, $sort);
195 return encode_entities(Dumper(\@readable_info));
200 ( my $file = shift ) =~ s(^/)();
201 $Response->Include($file, @_);
205 if ( defined(@DBIx::Profile::ISA) ) {
207 #false laziness w/above
211 ${$Response->{BinaryRef}} =
213 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
215 ( UNIVERSAL::can(dbh, 'sprintProfile')
216 ? encode_entities(dbh->sprintProfile())
217 : 'DBIx::Profile missing sprintProfile method;'.
218 'unpatched or too old?' ).
219 "\n\n". &sprintAutoProfile(). '</PRE>'.
222 dbh->{'private_profile'} = {};
231 $Response->Redirect(@_);