View Issue Details

IDProjectCategoryView StatusLast Update
0000175XdebugProfilingpublic2016-12-04 16:26
ReporterGoodStuffAssigned Toderick 
PrioritynormalSeveritytrivialReproducibilityalways
Status acknowledgedResolutionopen 
PlatformPHP 5.1.2OSWindows XPOS VersionSP1
Product Version2.0.0dev 
Target Version2.2devFixed in Version 
Summary0000175: Profile: function or class definition has no entry in profile, and adds to self time in wrong place
DescriptionWhile profiling my app, I noticed something odd in the "self" times of some of my scripts.

Let's say file A require_once() file B. File B require_once() file C. File C has a lot of function or class definitions.

In the profiler, no "events" are logged for C.php. Also, almost no time is assigned to C.php, but a lot of time is (incorrectly) assigned to the "self" time of B.php.
Steps To ReproduceProfile A.php and examine the cachegrind output.

(a.php, b.php, c.php and example cachegrind output atached in zip)
TagsNo tags attached.
Operating SystemWindows XP
PHP Version5.1.2

Activities

GoodStuff

2006-04-20 16:35

reporter   ~0000386

Sorry, was no way to attach zip. Here are example files:

a.php:
"""
<?php
    require_once("b.php");
?>
<html>
    <body>
        qzna!
    </body>
</html>
"""

b.php
"""
<?php
    require_once("c.php");
?>
"""

c.php
"""
<?php

   function a()
   {
       Header("Content-type: text/html");
       Header("Cache-Control: no-cache, must-revalidate");
       Header("Pragma: no-cache");
    }

    function b($a,$b)
    {
        echo "<a href=\"$a\">$b</a>";
    }

   function c($input)
   {
    $input = str_replace(array("&","""), array("&","'"), $input);
      $input = htmlspecialchars($input);
      $output = "";

      for ($i=0;$i<strlen($input);$i++)
      {
         $c = $input{$i};

         if (ord($c) > 127)
        {
            $output .= "&#" . ord($c) . ";";
         }
        elseif ($c == "$")
        {
            $output .= "$$";
        }
        else
        {
            $output .= $c;
         }
      }

      return $output;
   }

   function d($input)
   {
      $output = "";

      for ($i=0;$i<strlen($input);$i++)
      {
         if (ereg("[[:alnum:]., '()?-]",$input{$i}))
        {
            $output .= $input{$i};
         }
      }

      return $output;
   }

   function br()
   {
       return "
\n";
   }

   function e($name, $value, $options)
   {
       $element = "<select name=\"$name\" value=\"$value\">\n";

       while (list($key, $val) = each($options))
       {
           $element .= " <option value=\"$key\">$val</option>\n";
       }

       $element .= "</select>";

       return $element;
   }


   function f($text, $key, $value=NULL)
   {
       if ($value === NULL)
       {
           return "$text<input name=\"$key\"/>";
       }
       else
       {
           return "$text<input name=\"$key\" value=\"$value\"/>";
       }
   }


   function g($text, $img = "")
   {

     if (isset($_SESSION['user']))
     {
         $dir = $_SESSION['user']->theme;
         $display = ($dir != "off" and $dir != "");
     }
     else
     {
         $dir = "default";
         $display = true;
     }

      if ($img == "")
        $img = strtolower($text);

      if ($display)
          return "<img alt=\"$text\" src=\"./theme/$dir/$img.gif\"/>";
      else
          return "$text";
   }

   function h($url, $text, $postfield = NULL, $setvar = NULL, $method = "get")
   {
       $element = "";

       if ($method == "get")
       {
           if ($setvar === NULL)
           {
               $element .= "<a href=\"$url";

               if ($postfield !== NULL)
               {
                   $first = true;
                   reset($postfield);
                   while (list($key, $val) = each($postfield))
                   {
                       if ($first)
                       {
                           $first = false;
                           $element .= "?";
                       }
                       else
                       {
                           $element .= "&";
                       }
                       $element .= "$key=$val";
                   }
               }

               $element .= "\">$text</a>";
           }
           else
           {
               $element .= "<anchor>$text<go href=\"$url";

               if (trim(session_id())!="" AND trim(session_id())!="deleted")
                   $postfield["PHPSESSID"] = session_id();

               if ($postfield !== NULL)
               {
                   $first = true;
                   reset($postfield);
                   while (list($key, $val) = each($postfield))
                   {
                       if ($first)
                       {
                           $first = false;
                           $element .= "?";
                       }
                       else
                       {
                           $element .= "&";
                       }
                       $element .= "$key=$val";
                   }
               }

               $element .= "\" method=\"get\">\n";

               reset($setvar);
               while (list($key, $val) = each($setvar))
               {
                   $element .= " <setvar name=\"$key\" value=\"$val\"/>\n";
               }

               $element .= "</go></anchor>";
           }
       }
       elseif ($method = "post")
       {
           if ($setvar === NULL)
           {
               if (trim(session_id())!="" AND trim(session_id())!="deleted")
                   $postfield["PHPSESSID"] = session_id();

               if ($postfield === NULL)
               {
                   $element .= "<a href=\"$url\">$text</a>";
               }
               else
               {
                   $element .= "<anchor>$text<go href=\"$url\" method=\"post\">\n";

                   reset($postfield);
                   while (list($key, $val) = each($postfield))
                   {
                       $element .= " <postfield name=\"$key\" value=\"$val\"/>\n";
                   }

                   $element .= "</go></anchor>";
               }
           }
           else
           {
               $element .= "<anchor>$text<go href=\"$url\" method=\"post\">\n";

               if (trim(session_id())!="" AND trim(session_id())!="deleted")
                   $postfield["PHPSESSID"] = session_id();

               reset($postfield);
               while (list($key, $val) = each($postfield))
               {
                   $element .= " <postfield name=\"$key\" value=\"$val\"/>\n";
               }

               reset($setvar);
               while (list($key, $val) = each($setvar))
               {
                   $element .= " <setvar name=\"$key\" value=\"$val\"/>\n";
               }

               $element .= "</go></anchor>";
           }
       }

       return $element;
   }

   function i($code, $heading, $feed)
   {
       echo g("headlines.php",$heading,array("code"=>$code,"feed"=>$feed),NULL,"post") . br();
   }

   function j($haystack, $char_list)
   {
        if (!is_scalar($haystack)) {
            user_error('strpbrk() expects parameter 1 to be string, ' .
                gettype($haystack) . ' given', E_USER_WARNING);
            return false;
        }

        if (!is_scalar($char_list)) {
            user_error('strpbrk() expects parameter 2 to be scalar, ' .
                gettype($needle) . ' given', E_USER_WARNING);
            return false;
        }

        $haystack = (string) $haystack;
        $char_list = (string) $char_list;

        $len = strlen($haystack);
        for ($i = 0; $i < $len; $i++) {
            $char = substr($haystack, $i, 1);
            if (strpos($char_list, $char) === false) {
                continue;
            }
            return substr($haystack, $i);
        }

        return false;
   }

?>
"""

cachegrind.out.1398746969:
"""
version: 0.9.6
cmd: C:\Inetpub\waproot\test\a.php
part: 1

events: Time

fl=C:\Inetpub\waproot\test\c.php
fn=require_once::C:\Inetpub\waproot\test\c.php
1 240

fl=C:\Inetpub\waproot\test\b.php
fn=require_once::C:\Inetpub\waproot\test\b.php
1 19378
cfn=require_once::C:\Inetpub\waproot\test\c.php
calls=1 0 0
2 240

fl=C:\Inetpub\waproot\test\a.php
fn={main}

summary: 25269

0 5650
cfn=require_once::C:\Inetpub\waproot\test\b.php
calls=1 0 0
2 19619

"""

Issue History

Date Modified Username Field Change
2006-04-20 16:32 GoodStuff New Issue
2006-04-20 16:35 GoodStuff Note Added: 0000386
2010-03-20 23:47 derick Target Version => 2.2dev
2016-07-31 12:35 derick Category Debug client (console) => debugclient (debugging tool)
2016-07-31 12:35 derick Category debugclient (debugging tool) => (No Category)
2016-08-02 18:46 derick Category (No Category) => Profiling
2016-12-04 16:26 derick Assigned To => derick
2016-12-04 16:26 derick Status new => acknowledged