• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Profiler is showing multiple query sections?

#1
In CI2, the Profiler would show a single Query section showing all queries ran in that request.

Now in CI3, the Profiler shows multiple Query sections, they each show the same set of queries, so it seems a tad redundant?

Is this the same for anyone else? Is this working as intended? And can I change it show it only shows one section?
Reply

#2
The error display is:
DATABASE:  dbname (Welcome:$db)   QUERIES: 13 (0.0614 seconds)  (Hide)
DATABASE:  dbname (Common_model:$_database)   QUERIES: 13 (0.0614 seconds)  (Hide)
DATABASE:  dbname (Member_model:$_database)   QUERIES: 13 (0.0614 seconds)  (Hide)
DATABASE:  dbname (Homepage_model:$_database)   QUERIES: 13 (0.0614 seconds)  (Hide)

CI v3.x change history:
https://github.com/bcit-ci/CodeIgniter/b...ofiler.php
https://github.com/bcit-ci/CodeIgniter/c...d00569ec96
https://github.com/bcit-ci/CodeIgniter/issues/1220

PHP Code:
        // Let's determine which databases are currently connected to
        
foreach (get_object_vars($this->CI) as $name => $cobject)
        {
            if (
is_object($cobject))
            {
                if (
$cobject instanceof CI_DB)
                {
                    
$dbs[get_class($this->CI).':$'.$name] = $cobject;
                }
                elseif (
$cobject instanceof CI_Model)
                {
                    foreach (
get_object_vars($cobject) as $mname => $mobject)
                    {
                        if (
$mobject instanceof CI_DB)
                        {
                            
$dbs[get_class($cobject).':$'.$mname] = $mobject;
                        }
                    }
                }
            }
        } 

CI v2.x change history:
https://github.com/bcit-ci/CodeIgniter/b...ofiler.php
https://github.com/bcit-ci/CodeIgniter/c...67946a9cd2

PHP Code:
        // Let's determine which databases are currently connected to
        
foreach (get_object_vars($this->CI) as $CI_object)
        {
            if (
is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') )
            {
                
$dbs[] = $CI_object;
            }
        } 

So my solution is:
file location: /application/libraries/MY_Profiler.php
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
MY_Profiler extends CI_Profiler
{
 
   protected function _compile_queries()
 
   {
 
       $dbs = array();

 
       // Let's determine which databases are currently connected to
 
       foreach (get_object_vars($this->CI) as $CI_object)
 
       {
 
           if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') )
 
           {
 
               $dbs[] = $CI_object;
 
           }
 
       }

 
       if (count($dbs) === 0)
 
       {
 
           return "\n\n"
 
               .'<fieldset id="ci_profiler_queries" style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
 
               ."\n"
 
               .'<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>'
 
               ."\n\n\n<table style=\"border:none; width:100%;\">\n"
 
               .'<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">'
 
               .$this->CI->lang->line('profiler_no_db')
 
               ."</td></tr>\n</table>\n</fieldset>";
 
       }

 
       // Load the text helper so we can highlight the SQL
 
       $this->CI->load->helper('text');

 
       // Key words we want bolded
 
       $highlight = array('SELECT''DISTINCT''FROM''WHERE''AND''LEFT&nbsp;JOIN''ORDER&nbsp;BY''GROUP&nbsp;BY''LIMIT''INSERT''INTO''VALUES''UPDATE''OR&nbsp;''HAVING''OFFSET''NOT&nbsp;IN''IN''LIKE''NOT&nbsp;LIKE''COUNT''MAX''MIN''ON''AS''AVG''SUM''('')');

 
       $output  "\n\n";
 
       $count 0;

 
       foreach ($dbs as $db)
 
       {
 
           $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' '';
 
           $total_time number_format(array_sum($db->query_times), 4).' '.$this->CI->lang->line('profiler_seconds');

 
           $show_hide_js '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_hide').'\'?\''.$this->CI->lang->line('profiler_section_show').'\':\''.$this->CI->lang->line('profiler_section_hide').'\';">'.$this->CI->lang->line('profiler_section_hide').'</span>)';

 
           if ($hide_queries !== '')
 
           {
 
               $show_hide_js '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)';
 
           }

 
           $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
 
               ."\n"
 
               .'<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database')
 
               .':&nbsp; '.$db->database.'&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries')
 
               .': '.count($db->queries).' ('.$total_time.')&nbsp;&nbsp;'.$show_hide_js."</legend>\n\n\n"
 
               .'<table style="width:100%;'.$hide_queries.'" id="ci_profiler_queries_db_'.$count."\">\n";

 
           if (count($db->queries) === 0)
 
           {
 
               $output .= '<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">'
 
                       .$this->CI->lang->line('profiler_no_queries')."</td></tr>\n";
 
           }
 
           else
            
{
 
               foreach ($db->queries as $key => $val)
 
               {
 
                   $time number_format($db->query_times[$key], 4);
 
                   $val highlight_code($val);

 
                   foreach ($highlight as $bold)
 
                   {
 
                       $val str_replace($bold'<strong>'.$bold.'</strong>'$val);
 
                   }

 
                   $output .= '<tr><td style="padding:5px;vertical-align:top;width:1%;color:#900;font-weight:normal;background-color:#ddd;">'
 
                           .$time.'&nbsp;&nbsp;</td><td style="padding:5px;color:#000;font-weight:normal;background-color:#ddd;">'
 
                           .$val."</td></tr>\n";
 
               }
 
           }

 
           $output .= "</table>\n</fieldset>";
 
           $count++;
 
       }

 
       return $output;
 
   }

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.