Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xhprof-viewer does not reading .xhprof files #20

Open
karthikeayan opened this issue Jun 14, 2018 · 3 comments
Open

xhprof-viewer does not reading .xhprof files #20

karthikeayan opened this issue Jun 14, 2018 · 3 comments

Comments

@karthikeayan
Copy link

php version: PHP 7.1.18 (cli) (built: May 24 2018 07:59:58) ( NTS )
apache httpd-2.4.6-67.el7.centos.6.x86_64

Copied my .xhprof files to apache server.

But still sugarcrm xhprof viewer does not picking up any files. Rows are always empty!

@synapdk
Copy link

synapdk commented Jun 30, 2018

It looks filenames of a particular format are required. I can't find documentation on it, but by experimenting I found that a filename of <timestamp>.xhprof where the timestamp is in the filter range will at least be listed as "no-name", and thus be viewable.

@karthikeayan
Copy link
Author

karthikeayan commented Jul 30, 2018

if anyone is here in future, can be unix epoch time. example: 1532946627.xhprof

@fabianofa
Copy link

@synapdk

TL;DR: To set Profile name either use the filename as: <timestamp>.0.0.0.<profilename>.xhprof and Min Wall Time filter to 0, or <timestamp>.0.0.<sum of wall time from xhprof>.<profilename>.xhprof and adjust Min Wall Time accordingly.


To understand how to set "Profile" value, you have to look into how the app defines the values at FileStorage::parseFilename method:

    protected function parseFilename($filename)
    {
        if (preg_match('/^(\d+)d(\d+)d(\d+)d(\d+)d(\d+)\.([^.]+)$/', $filename, $matches)) {
            return array(
                'timestamp' => floatval($matches[1] . '.' . $matches[2]),
                'wall_time' => $matches[3],
                'sql_queries' => $matches[4],
                'elastic_queries' => $matches[5],
                'namespace' => $matches[6]
            );
        }

        // Check of OOTB Sugar file format
        if (preg_match('/^([A-Za-z0-9]+)\.(\d+-\d+)-(.*)$/', $filename, $matches)) {
            return array(
                'timestamp' => floatval(str_replace('-', '.', $matches[2])),
                'wall_time' => null,
                'sql_queries' => null,
                'namespace' => $matches[3]
            );
        }

        $name_parts = explode('.', $filename);

        $shortname = array_shift($name_parts);
        $shortname .= '.' . array_shift($name_parts);
        $slq_queries = array_shift($name_parts);
        $wt = array_shift($name_parts);

        $namespace = implode('_', $name_parts);
        $buf = array(
            'timestamp' => floatval($shortname),
            'wall_time' => $wt,
            'sql_queries' => intval($slq_queries),
            'namespace' => $namespace
        );

        return $buf;
    }

So to define a valid filename with a profile it would be something like:

<timestamp>.0.0.0.<profilename>.xhprof

Now, beware that the fourth name parameter (considering each parameter a value between a dot), it means the wall time. If you set the Min Wall Time to >= 1, it will multiply by 1e-3, thus if you name a file <timestamp>.0.0.1.<profile>.xhprof and set Min Wall Time to 1, you won't see the file because it filters the fourth name parameter as milliseconds. :


src/php/Storage/FileStorage.php

     public function getRunsList($params = array())
     {

           ...
           
         if (!empty($params['wall_time_min'])) {
            foreach ($bufFiles as $index => $file) {
                if (!is_null($file['wall_time']) && $file['wall_time'] < $params['wall_time_min'] * 1E3) {
                    unset($bufFiles[$index]);
                }
            }
        }

Also, avoid using the Min Wall Time to 120 because it will redirect you to a default page, which the default Min Wall Time is 300:

src/php/Controllers/RunsListController.php

   ...

    public function indexAction()
    {
        if ($this->getParam('f_wt_min') == 120) {
            header('Location: ?dir=sugar');exit;
        }

        ...
     }

If you want to make use of the wall time filter, considering you're using Tideways XHProf, you can do it as:

        $data = tideways_xhprof_disable();
        $wt = 0;
        foreach ($data as $d) {
            $wt += $d['wt'];
        }

        $profileName = basename(__FILE__);
        file_put_contents(
            "/var/www/html/xhprof-data/" . time(). ".0.0.{$wt}.{$profileName}.xhprof",
            serialize($data)
        );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants