/**
  * Logs all database process to the internal log object.
  * Iterates all queries of the query profiler and writes the query,
  * the parameter and the elapsed seconds for the query into a new row of the log.
  */
 public function logResults(Logger $log)
 {
     /** @var $profiler \Zend_Db_Profiler */
     $profiler = $this->db->getProfiler();
     $rows = array(array('time', 'count', 'sql', 'params'));
     $counts = array(10000);
     $total_time = 0;
     $queryProfiles = $profiler->getQueryProfiles();
     if (!$queryProfiles) {
         return;
     }
     /** @var $query \Zend_Db_Profiler_Query */
     foreach ($queryProfiles as $query) {
         $id = md5($query->getQuery());
         $total_time += $query->getElapsedSecs();
         if (!isset($rows[$id])) {
             $rows[$id] = array(number_format($query->getElapsedSecs(), 5, '.', ''), 1, $query->getQuery(), $query->getQueryParams());
             $counts[$id] = $query->getElapsedSecs();
         } else {
             $rows[$id][1]++;
             $counts[$id] += $query->getElapsedSecs();
             $rows[$id][0] = number_format($counts[$id], 5, '.', '');
         }
     }
     array_multisort($counts, SORT_NUMERIC, SORT_DESC, $rows);
     $rows = array_values($rows);
     $total_time = round($total_time, 5);
     $total_count = $profiler->getTotalNumQueries();
     $label = "Database Querys ({$total_count} @ {$total_time} sec)";
     $table = array($label, $rows);
     $log->table($table);
 }