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);
16 use String::Approx qw(amatch);
17 use Chart::LinesPoints;
18 use HTML::Widgets::SelectLayers 0.02;
19 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
20 use FS::Record qw(qsearch qsearchs fields dbdef);
22 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
23 small_custview myexit http_header);
24 use FS::Msgcat qw(gettext geterror);
28 use FS::domain_record;
30 use FS::cust_bill_pay;
32 use FS::cust_credit_bill;
34 use FS::cust_main_county;
40 use FS::part_bill_event;
42 use FS::part_referral;
44 use FS::part_svc_router;
45 use FS::part_virtual_field;
48 use FS::queue qw(joblisting);
52 use FS::svc_acct_pop qw(popselector);
58 use FS::svc_broadband;
61 use FS::part_export_option;
66 $Response->AddHeader('Pragma' => 'no-cache');
67 $Response->AddHeader('Cache-control' => 'no-cache');
68 # $Response->AddHeader('Expires' => 0);
69 $Response->{Expires} = -36288000;
74 #print $cgi->header( '-expires' => 'now' );
75 dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
77 #really should check for FS::Profiler or something
78 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
79 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
80 #should check to see it's my special version. well, switch to FS::Profiler
82 #nicked from Devel::AutoProfiler::INIT
83 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
86 SUB : while( my ($name, $ref) = each(%subs) )
88 #next if $name =~ /^(main::)?Apache::/;
89 next unless $name =~ /FS/;
90 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
97 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
98 #warn "INIT name is $name \n";
99 Devel::AutoProfiler::__instrument_sub($name, $ref);
107 my $ref = $Response->{BinaryRef};
108 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
109 #$$ref = $cgi->header() . $$ref;
110 #warn "Script_OnFlush called with dbh ". dbh. "\n";
111 #if ( dbh->can('sprintProfile') ) {
112 if ( UNIVERSAL::can(dbh,'sprintProfile') ) {
113 #warn "dbh can sprintProfile\n";
114 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
115 #warn "contenttype is sprintProfile\n";
116 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
117 or warn "can't remove";
119 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
121 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
122 "\n\n". &sprintAutoProfile(). '</PRE>';
124 $$ref .= '</BODY></HTML>';
126 dbh->{'private_profile'} = {};
130 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
131 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
132 if ( defined(@DBIx::Profile::ISA) ) {
134 #warn "enabling profiling redirects";
135 *CGI::redirect = sub {
136 my( $self, $location) = @_;
139 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A><BR><BR>!.
140 '<PRE>'. encode_entities(dbh->sprintProfile()).
141 "\n\n". &sprintAutoProfile(). '</PRE>'.
143 dbh->{'private_profile'} = {};
151 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
154 sub sprintAutoProfile {
155 my %caller_info = %Devel::AutoProfiler::caller_info;
156 return unless keys %caller_info;
158 %Devel::AutoProfiler::caller_info = ();
160 my @keys = keys(%caller_info);
162 foreach my $key (@keys)
164 my $href = $caller_info{$key};
166 $href->{who_am_i} = $key;
169 my @subs = values(%caller_info);
171 #my @sorted = sort by_total_time ( @subs );
172 my @sorted = reverse sort by_total_time ( @subs );
174 # print Dumper \@sorted;
178 foreach my $sort (@sorted)
180 push(@readable_info, delete($sort->{who_am_i}));
181 push(@readable_info, $sort);
185 return encode_entities(Dumper(\@readable_info));