Пример #1
0
 function parse_report_internal($as_html = true)
 {
     $end_time = microtime();
     $return_text = '';
     if ($as_html) {
         if (count($this->debug_strings) - count($this->time_points) > 0) {
             $return_text .= "<script>NEED_TO_FOCUS=1</script>";
         }
         $return_text .= '<table><tr><td>';
         $return_text .= '<table cellspacing=0 cellpadding=1>';
     }
     $counter = 0;
     foreach ($this->debug_strings as $debug) {
         $counter++;
         $output_data = $this->output_format[$debug['level']];
         if (is_array($output_data)) {
             $color = $output_data['color'];
             $name = $output_data['name'];
             if ($as_html) {
                 $return_text .= "<tr>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<th align='left'>{$counter})<span style='color:{$color}'>{$name}:</span></th>\r\n                          </tr>\r\n                          <tr><td><pre>" . htmlspecialchars($debug['string']) . "</pre></td></tr>";
             } else {
                 $return_text .= "{$name}: " . $debug['string'] . "\n";
             }
         }
     }
     if ($as_html) {
         $return_text .= "</table>";
         $return_text .= "<h3>Timing points:</h3>";
         $return_text .= "<table style='border: 1px solid black;' cellspacing='0' cellpadding='1'><tr><th>Checkpoint</th><th>Elapsed</th><th>Rel. Elapsed</th></tr>";
     }
     $start_time = false;
     $elapsed = 0.0;
     $rel_array = array(-1 => 0.0);
     for ($i = 0; $i < count($this->time_points); ++$i) {
         $point = $this->time_points[$i];
         $next_point = false;
         if (isset($this->time_points[$i + 1])) {
             $next_point = $this->time_points[$i + 1];
         }
         $time = debug::_time_to_float($point['time']);
         $next_time = false;
         if ($next_point !== false) {
             $next_time = debug::_time_to_float($next_point['time']);
         }
         if ($start_time === false) {
             $start_time = $time;
         }
         $elapsed = $time - $start_time;
         $rel_elapsed = $rel_array[$i - 1];
         $rel_array[] = $next_time - $time;
         if ($i % 2 == 0) {
             $class = 'timingpoint1';
         } else {
             $class = 'timingpoint2';
         }
         if ($as_html) {
             $return_text .= "<tr><td class='{$class}'>" . $point['description'] . "</td><td class='{$class}'>" . number_format($elapsed, $this->timing_accuracy) . " sec</td><td class='{$class}'>" . (number_format($rel_elapsed, $this->timing_accuracy) . " sec") . "</td>" . "</tr>";
         } else {
             $return_text .= $point['description'] . number_format($elapsed, $this->timing_accuracy) . " sec " . (number_format($rel_elapsed, $this->timing_accuracy) . " sec") . "\n";
         }
     }
     if (count($this->time_points) > 0) {
         $t_time = explode(' ', $end_time);
         ereg("0\\.([0-9]+)", '' . $t_time[0], $t1);
         $end_time = $t_time[1] . '.' . $t1[1];
         $total_elapsed = $end_time - $start_time;
         if ($as_html) {
             $return_text .= "<tr><td><b>Total runtime:</b></td><td><b>" . number_format($total_elapsed, $this->timing_accuracy) . " sec</b></td><td></td></tr>";
         } else {
             $return_text .= "Total runtime: " . number_format($total_elapsed, $this->timing_accuracy) . " sec\n";
         }
     } else {
         if ($as_html) {
             $return_text .= "<tr><td> No timing points defined</td><td>";
         } else {
             $return_text .= "No timing points defined\n";
         }
     }
     if ($as_html) {
         $return_text .= "</table>";
     }
     if ($as_html) {
         $return_text .= "<h3>Time accumulators:</h3>";
         $return_text .= "<table style='border: 1px solid black;' cellspacing='0' cellpadding='1'><tr><th>&nbsp;Accumulator</th><th>&nbsp;Elapsed</th><th>&nbsp;Percent</th><th>&nbsp;Count</th><th>&nbsp;Average</th></tr>";
         $i = 0;
     }
     $script_end_time = debug::_time_to_float(microtime());
     $total_elapsed = $script_end_time - $this->script_start;
     $time_list = $this->time_accumulator_list;
     $groups = $this->time_accumulator_group_list;
     $group_list = array();
     foreach ($groups as $group_key => $key_list) {
         if (count($key_list) == 0 && !array_key_exists($group_key, $time_list)) {
             continue;
         }
         $group_list[$group_key] = array('name' => $group_key);
         if (array_key_exists($group_key, $time_list)) {
             if ($time_list[$group_key]['time'] != 0) {
                 $group_list[$group_key]['time_data'] = $time_list[$group_key];
             }
             $group_list[$group_key]['name'] = $time_list[$group_key]['name'];
             unset($time_list[$group_key]);
         }
         $group_children = array();
         foreach ($key_list as $time_key) {
             if (array_key_exists($time_key, $time_list)) {
                 $group_children[] = $time_list[$time_key];
                 unset($time_list[$time_key]);
             }
         }
         $group_list[$group_key]['children'] = $group_children;
     }
     if (count($time_list) > 0) {
         $group_list['general'] = array('name' => 'general', 'children' => $time_list);
     }
     $j = 0;
     foreach ($group_list as $group) {
         if ($j % 2 == 0) {
             $class = 'timingpoint1';
         } else {
             $class = 'timingpoint2';
         }
         ++$j;
         $group_name = $group['name'];
         $group_children = $group['children'];
         if (count($group_children) == 0 && !array_key_exists('time_data', $group)) {
             continue;
         }
         if ($as_html) {
             $return_text .= "<tr><td class='{$class}'><b>{$group_name}</b></td>";
         } else {
             $return_text .= "Group {$group_name}: ";
         }
         if (array_key_exists('time_data', $group)) {
             $group_data = $group['time_data'];
             $group_elapsed = number_format($group_data['time'], $this->timing_accuracy);
             $group_percent = number_format($group_data['time'] * 100.0 / $total_elapsed, 1);
             $group_count = $group_data['count'];
             $group_average = number_format($group_data['time'] / $group_data['count'], $this->timing_accuracy);
             if ($as_html) {
                 $return_text .= "<td class=\"{$class}\">{$group_elapsed} sec</td>" . "<td class=\"{$class}\" align=\"right\"> {$group_percent}%</td>" . "<td class=\"{$class}\" align=\"right\"> {$group_count}</td>" . "<td class=\"{$class}\" align=\"right\"> {$group_average} sec</td>";
             } else {
                 $return_text .= "{$group_elapsed} sec ({$group_percent}%), {$group_average} avg sec ({$group_count})";
             }
         } elseif ($as_html) {
             $return_text .= "<td class=\"{$class}\"></td>" . "<td class=\"{$class}\"></td>" . "<td class=\"{$class}\"></td>" . "<td class=\"{$class}\"></td>";
         }
         if ($as_html) {
             $return_text .= "</tr>";
         } else {
             $return_text .= "\n";
         }
         $i = 0;
         foreach ($group_children as $child) {
             $child_name = $child['name'];
             $child_elapsed = number_format($child['time'], $this->timing_accuracy);
             $child_percent = number_format($child['time'] * 100.0 / $total_elapsed, $this->percent_accuracy);
             $child_count = $child['count'];
             $child_average = 0.0;
             if ($child_count > 0) {
                 $child_average = $child['time'] / $child_count;
             }
             $child_average = number_format($child_average, $this->percent_accuracy);
             if ($as_html) {
                 if ($i % 2 == 0) {
                     $class = 'timingpoint1';
                 } else {
                     $class = 'timingpoint2';
                 }
                 ++$i;
                 $return_text .= "<tr>" . "<td class=\"{$class}\">{$child_name}</td>" . "<td class=\"{$class}\">{$child_elapsed} sec</td>" . "<td class=\"{$class}\" align=\"right\">{$child_percent}%</td>" . "<td class=\"{$class}\" align=\"right\">{$child_count}</td>" . "<td class=\"{$class}\" align=\"right\">{$child_average} sec</td>" . "</tr>";
             } else {
                 $return_text .= "{$child_name}: {$child_elapsed} sec ({$child_percent}%), {$child_average} avg sec ({$child_count})";
             }
         }
     }
     if ($as_html) {
         $return_text .= "<tr><td><b>Total script time:</b></td><td><b>" . number_format($total_elapsed, $this->timing_accuracy) . " sec</b></td><td></td></tr>";
     } else {
         $return_text .= "Total script time: " . number_format($total_elapsed, $this->timing_accuracy) . " sec\n";
     }
     if ($as_html) {
         $return_text .= '</table>';
         $return_text .= '</td></tr></table>';
     }
     return $return_text;
 }
Пример #2
0
  function _parse_report_internal($as_html = true)
  {
    $end_time = microtime();
    $return_text = '';
    if ($as_html)
    {
      if ((count($this->debug_strings) - count($this->time_points)) > 0)
        $return_text .= "<script>NEED_TO_FOCUS=1</script>";

      $return_text .= '<table><tr><td>';
      $return_text .= '<table cellspacing=0 cellpadding=1>';
    }

    $counter = 0;
    foreach ($this->debug_strings as $debug)
    {
      $counter++;
      $output_data = $this->output_format[$debug['level']];
      if (is_array($output_data))
      {
        $color = $output_data['color'];
        $name = $output_data['name'];

        if ($as_html)
        {
          $return_text .= "<tr>
                          <th align='left'><a name={$counter}>{$counter})<span style='color:$color'>{$name}:</span></th>
                          </tr>
                          <tr><td>" . debug :: _parse_html_debug_info($debug) . "</td></tr>";
        }
        else
          $return_text .= "$name: " . debug :: _parse_text_debug_info($debug);
      }
    }

    if ($as_html)
    {
      $return_text .= "</table>";
      $return_text .= "<h3>Timing points:</h3>";
      $return_text .= "<table style='border: 1px solid black;' cellspacing='0' cellpadding='1'><tr><th>Checkpoint</th><th>Elapsed</th><th>Rel. Elapsed</th><th>Mem</th><th>Rel. Mem</th></tr>";
    }

    $start_time = false;
    $elapsed = 0.00;
    $rel_array = array(-1 => 0.00);
    $rel_memory_array = array(-1 => 0);

    for ($i=0; $i < count($this->time_points); ++$i)
    {
      $point = $this->time_points[$i];

      if (isset($this->time_points[$i + 1]))
        $next_point = $this->time_points[$i + 1];
      else
        $next_point = false;

      $time = debug :: _time_to_float($point['time']);
      $memory = $point['memory_usage'];
      $next_time = false;
      $next_memory = 0;

      if ($next_point !== false)
      {
        $next_time = debug :: _time_to_float($next_point['time']);
        $next_memory = $next_point['memory_usage'];
      }

      if ($start_time === false)
        $start_time = $time;

      $elapsed = $time - $start_time;
      $rel_elapsed = $rel_array[$i-1];
      $rel_memory_elapsed = $rel_memory_array[$i-1];

      $rel_array[] = $next_time - $time;
      $rel_memory_array[] = $next_memory - $memory;

      if ($i % 2 == 0)
        $class = 'timingpoint1';
      else
        $class = 'timingpoint2';

      if ($as_html)
      {
        $return_text .= "<tr><td class='$class'>" . $point['description'] . "</td><td class='$class'>" .
        number_format($elapsed, $this->timing_accuracy) . "s</td><td class='$class'>" .
        number_format($rel_elapsed, $this->timing_accuracy) . "s</td>" .
        "<td class='$class'>" . number_format($memory / 1024, 2) . "Kb&nbsp;</td>" .
        "<td class='$class'>" . number_format($rel_memory_elapsed / 1024, 2) . "Kb</td>"
        . "</tr>";
      }
      else
      {
        $return_text .= $point['description'] .
        number_format($elapsed, $this->timing_accuracy) . "s " .
        number_format($rel_elapsed, $this->timing_accuracy) . "s " .
        number_format($memory / 1024, 2) . "Kb " .
        number_format($rel_memory_elapsed / 1024, 2) . "Kb" .
        "\n";
      }
    }

    if (count($this->time_points) > 0)
    {
      $t_time = explode(' ', $end_time);
      preg_match("~0\.([0-9]+)~", '' . $t_time[0], $t1);
      $end_time = $t_time[1] . '.' . $t1[1];

      $total_elapsed = $end_time - $start_time;

      if ($as_html)
      {
        $return_text .= "<tr><td><b>Total runtime:</b></td><td><b>" .
        number_format(($total_elapsed), $this->timing_accuracy) . "s</b></td><td></td></tr>";
      }
      else
      {
        $return_text .= "Total runtime: " .
        number_format(($total_elapsed), $this->timing_accuracy) . "s\n";
      }
    }
    else
    {
      if ($as_html)
        $return_text .= "<tr><td> No timing points defined</td><td>";
      else
        $return_text .= "No timing points defined\n";
    }
    if ($as_html)
      $return_text .= "</table>";

    if ($as_html)
    {
      $return_text .= "<h3>Time accumulators:</h3>";
      $return_text .= "<table style='border: 1px solid black;' cellspacing='0' cellpadding='1'><tr><th>&nbsp;Accumulator</th><th>&nbsp;Elapsed</th><th>&nbsp;Percent</th><th>&nbsp;Count</th><th>&nbsp;Average</th></tr>";
      $i = 0;
    }

    $script_end_time = debug::_time_to_float(microtime());
    $total_elapsed = $script_end_time - $this->script_start;
    $time_list = $this->time_accumulator_list;
    $groups = $this->time_accumulator_group_list;
    $group_list = array();
    foreach ($groups as $group_key => $key_list)
    {
      if (count($key_list) == 0 && !array_key_exists($group_key, $time_list))
        continue;

      $group_list[$group_key] = array('name' => $group_key);
      if (array_key_exists($group_key, $time_list))
      {
        if ($time_list[$group_key]['time'] != 0)
          $group_list[$group_key]['time_data'] = $time_list[$group_key];

        $group_list[$group_key]['name'] = $time_list[$group_key]['name'];
        unset($time_list[$group_key]);
      }

      $group_children = array();
      foreach ($key_list as $time_key)
      {
        if (array_key_exists($time_key, $time_list))
        {
          $group_children[] = $time_list[$time_key];
          unset($time_list[$time_key]);
        }
      }
      $group_list[$group_key]['children'] = $group_children;
    }
    if (count($time_list) > 0)
    {
      $group_list['general'] = array('name' => 'general',
        'children' => $time_list);
    }

    $j = 0;
    foreach ($group_list as $group)
    {
      if ($j % 2 == 0)
        $class = 'timingpoint1';
      else
        $class = 'timingpoint2';

      ++$j;
      $group_name = $group['name'];
      $group_children = $group['children'];
      if (count($group_children) == 0 && !array_key_exists('time_data', $group))
        continue;

      if ($as_html)
        $return_text .= "<tr><td class='$class'><b>$group_name</b></td>";
      else
        $return_text .= "Group $group_name: ";

      if (array_key_exists('time_data', $group))
      {
        $group_data = $group['time_data'];
        $group_elapsed = number_format(($group_data['time']), $this->timing_accuracy);
        $group_percent = number_format(($group_data['time'] * 100.0) / $total_elapsed, 1);
        $group_count = $group_data['count'];
        $group_average = number_format(($group_data['time'] / $group_data['count']), $this->timing_accuracy);

        if ($as_html)
        {
          $return_text .= ("<td class=\"$class\">$group_elapsed sec</td>" . "<td class=\"$class\" align=\"right\"> $group_percent%</td>" . "<td class=\"$class\" align=\"right\"> $group_count</td>" . "<td class=\"$class\" align=\"right\"> $group_average sec</td>");
        }
        else
        {
          $return_text .= "$group_elapsed sec ($group_percent%), $group_average avg sec ($group_count)";
        }
      }
      elseif ($as_html)
      {
        $return_text .= ("<td class=\"$class\"></td>" . "<td class=\"$class\"></td>" . "<td class=\"$class\"></td>" . "<td class=\"$class\"></td>");
      }
      if ($as_html)
        $return_text .= "</tr>";
      else
        $return_text .= "\n";

      $i = 0;
      foreach ($group_children as $child)
      {
        $child_name = $child['name'];
        $child_elapsed = number_format(($child['time']), $this->timing_accuracy);
        $child_percent = number_format(($child['time'] * 100.0) / $total_elapsed, $this->percent_accuracy);
        $child_count = $child['count'];
        $child_average = 0.0;

        if ($child_count > 0)
          $child_average = $child['time'] / $child_count;

        $child_average = number_format($child_average, $this->percent_accuracy);

        if ($as_html)
        {
          if ($i % 2 == 0)
            $class = 'timingpoint1';
          else
            $class = 'timingpoint2';
          ++$i;

          $return_text .= ("<tr>" . "<td class=\"$class\">$child_name</td>" . "<td class=\"$class\">$child_elapsed sec</td>" . "<td class=\"$class\" align=\"right\">$child_percent%</td>" . "<td class=\"$class\" align=\"right\">$child_count</td>" . "<td class=\"$class\" align=\"right\">$child_average sec</td>" . "</tr>");
        }
        else
          $return_text .= "$child_name: $child_elapsed sec ($child_percent%), $child_average avg sec ($child_count)";
      }
    }
    if ($as_html)
      $return_text .= "<tr><td><b>Total script time:</b></td><td><b>" . number_format(($total_elapsed), $this->timing_accuracy) . " sec</b></td><td></td></tr>";
    else
      $return_text .= "Total script time: " . number_format(($total_elapsed), $this->timing_accuracy) . " sec\n";

    if ($as_html)
    {
      $return_text .= '</table>';
      $return_text .= '</td></tr></table>';
    }
    return $return_text;
  }