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 );
30 use FS::domain_record;
32 use FS::cust_bill_pay;
34 use FS::cust_credit_bill;
36 use FS::cust_main_county;
42 use FS::part_bill_event;
44 use FS::part_referral;
46 use FS::part_svc_router;
47 use FS::part_virtual_field;
50 use FS::queue qw(joblisting);
54 use FS::svc_acct_pop qw(popselector);
60 use FS::svc_broadband;
64 use FS::part_export_option;
69 $Response->AddHeader('Pragma' => 'no-cache');
70 $Response->AddHeader('Cache-control' => 'no-cache');
71 # $Response->AddHeader('Expires' => 0);
72 $Response->{Expires} = -36288000;
77 #print $cgi->header( '-expires' => 'now' );
78 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
79 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
81 #really should check for FS::Profiler or something
82 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
83 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
84 #should check to see it's my special version. well, switch to FS::Profiler
86 #nicked from Devel::AutoProfiler::INIT
87 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
90 SUB : while( my ($name, $ref) = each(%subs) )
92 #next if $name =~ /^(main::)?Apache::/;
93 next unless $name =~ /FS/;
94 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
101 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
102 #warn "INIT name is $name \n";
103 Devel::AutoProfiler::__instrument_sub($name, $ref);
111 my $ref = $Response->{BinaryRef};
112 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
113 #$$ref = $cgi->header() . $$ref;
114 #warn "Script_OnFlush called with dbh ". dbh. "\n";
115 #if ( dbh->can('sprintProfile') ) {
116 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
117 #warn "dbh can sprintProfile\n";
118 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
119 #warn "contenttype is sprintProfile\n";
120 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
121 or warn "can't remove";
123 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
125 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
126 "\n\n". &sprintAutoProfile(). '</PRE>';
128 $$ref .= '</BODY></HTML>';
130 dbh->{'private_profile'} = {};
134 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
135 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
136 if ( defined(@DBIx::Profile::ISA) ) {
138 #warn "enabling profiling redirects";
139 *CGI::redirect = sub {
140 my( $self, $location) = @_;
143 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
145 ( UNIVERSAL::can(dbh, 'sprintProfile')
146 ? encode_entities(dbh->sprintProfile())
147 : 'DBIx::Profile missing sprintProfile method;'.
148 'unpatched or too old?' ).
149 "\n\n". &sprintAutoProfile(). '</PRE>'.
151 dbh->{'private_profile'} = {};
159 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
162 sub sprintAutoProfile {
163 my %caller_info = %Devel::AutoProfiler::caller_info;
164 return unless keys %caller_info;
166 %Devel::AutoProfiler::caller_info = ();
168 my @keys = keys(%caller_info);
170 foreach my $key (@keys)
172 my $href = $caller_info{$key};
174 $href->{who_am_i} = $key;
177 my @subs = values(%caller_info);
179 #my @sorted = sort by_total_time ( @subs );
180 my @sorted = reverse sort by_total_time ( @subs );
182 # print Dumper \@sorted;
186 foreach my $sort (@sorted)
188 push(@readable_info, delete($sort->{who_am_i}));
189 push(@readable_info, $sort);
193 return encode_entities(Dumper(\@readable_info));
198 $Response->Include(@_);
201 if ( defined(@DBIx::Profile::ISA) ) {
203 #false laziness w/above
207 ${$Response->{BinaryRef}} =
209 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
211 ( UNIVERSAL::can(dbh, 'sprintProfile')
212 ? encode_entities(dbh->sprintProfile())
213 : 'DBIx::Profile missing sprintProfile method;'.
214 'unpatched or too old?' ).
215 "\n\n". &sprintAutoProfile(). '</PRE>'.
218 dbh->{'private_profile'} = {};
227 $Response->Redirect(@_);