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 );
8 #use CGI::Carp qw(fatalsToBrowser);
17 use String::Approx qw(amatch);
18 use Chart::LinesPoints;
19 use HTML::Widgets::SelectLayers 0.02;
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);
29 use FS::domain_record;
31 use FS::cust_bill_pay;
33 use FS::cust_credit_bill;
35 use FS::cust_main_county;
41 use FS::part_bill_event;
43 use FS::part_referral;
45 use FS::part_svc_router;
46 use FS::part_virtual_field;
49 use FS::queue qw(joblisting);
53 use FS::svc_acct_pop qw(popselector);
59 use FS::svc_broadband;
62 use FS::part_export_option;
67 $Response->AddHeader('Pragma' => 'no-cache');
68 $Response->AddHeader('Cache-control' => 'no-cache');
69 # $Response->AddHeader('Expires' => 0);
70 $Response->{Expires} = -36288000;
75 #print $cgi->header( '-expires' => 'now' );
76 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
77 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
79 #really should check for FS::Profiler or something
80 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
81 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
82 #should check to see it's my special version. well, switch to FS::Profiler
84 #nicked from Devel::AutoProfiler::INIT
85 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
88 SUB : while( my ($name, $ref) = each(%subs) )
90 #next if $name =~ /^(main::)?Apache::/;
91 next unless $name =~ /FS/;
92 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
99 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
100 #warn "INIT name is $name \n";
101 Devel::AutoProfiler::__instrument_sub($name, $ref);
109 my $ref = $Response->{BinaryRef};
110 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
111 #$$ref = $cgi->header() . $$ref;
112 #warn "Script_OnFlush called with dbh ". dbh. "\n";
113 #if ( dbh->can('sprintProfile') ) {
114 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
115 #warn "dbh can sprintProfile\n";
116 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
117 #warn "contenttype is sprintProfile\n";
118 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
119 or warn "can't remove";
121 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
123 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
124 "\n\n". &sprintAutoProfile(). '</PRE>';
126 $$ref .= '</BODY></HTML>';
128 dbh->{'private_profile'} = {};
132 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
133 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
134 if ( defined(@DBIx::Profile::ISA) ) {
136 #warn "enabling profiling redirects";
137 *CGI::redirect = sub {
138 my( $self, $location) = @_;
141 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
143 ( UNIVERSAL::can(dbh, 'sprintProfile')
144 ? encode_entities(dbh->sprintProfile())
145 : 'DBIx::Profile missing sprintProfile method;'.
146 'unpatched or too old?' ).
147 "\n\n". &sprintAutoProfile(). '</PRE>'.
149 dbh->{'private_profile'} = {};
157 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
160 sub sprintAutoProfile {
161 my %caller_info = %Devel::AutoProfiler::caller_info;
162 return unless keys %caller_info;
164 %Devel::AutoProfiler::caller_info = ();
166 my @keys = keys(%caller_info);
168 foreach my $key (@keys)
170 my $href = $caller_info{$key};
172 $href->{who_am_i} = $key;
175 my @subs = values(%caller_info);
177 #my @sorted = sort by_total_time ( @subs );
178 my @sorted = reverse sort by_total_time ( @subs );
180 # print Dumper \@sorted;
184 foreach my $sort (@sorted)
186 push(@readable_info, delete($sort->{who_am_i}));
187 push(@readable_info, $sort);
191 return encode_entities(Dumper(\@readable_info));
196 $Response->Include(@_);
199 if ( defined(@DBIx::Profile::ISA) ) {
201 #false laziness w/above
205 ${$Response->{BinaryRef}} =
207 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
209 ( UNIVERSAL::can(dbh, 'sprintProfile')
210 ? encode_entities(dbh->sprintProfile())
211 : 'DBIx::Profile missing sprintProfile method;'.
212 'unpatched or too old?' ).
213 "\n\n". &sprintAutoProfile(). '</PRE>'.
216 dbh->{'private_profile'} = {};
225 $Response->Redirect(@_);