XHProfRuns_Default::save_run PHP Méthode

save_run() public méthode

Save the run in the database.
public save_run ( string $xhprof_data, mixed $type, string $run_id = null, mixed $xhprof_details = null ) : string
$xhprof_data string
$type mixed
$run_id string
$xhprof_details mixed
Résultat string
    public function save_run($xhprof_data, $type, $run_id = null, $xhprof_details = null)
    {
        global $_xhprof;
        $sql = array();
        if ($run_id === null) {
            $run_id = $this->gen_run_id($type);
        }
        /*
        		Session data is ommitted purposefully, mostly because it's not likely that the data
        		that resides in $_SESSION at this point is the same as the data that the application
        		started off with (for most apps, it's likely that session data is manipulated on most
        		pageloads).
        The goal of storing get, post and cookie is to help explain why an application chose
        		a particular code execution path, pehaps it was a poorly filled out form, or a cookie that
        		overwrote some default parameters. So having them helps. Most applications don't push data
        		back into those super globals, so we're safe(ish) storing them now. 
        We can't just clone the session data in header.php to be sneaky either, starting the session
        		is an application decision, and we don't want to go starting sessions where none are needed
        		(not good performance wise). We could be extra sneaky and do something like:
        		if(isset($_COOKIE['phpsessid']))
        		{
        			session_start();
        			$_xhprof['session_data'] = $_SESSION;
        		} 
        		but starting session support really feels like an application level decision, not one that
        		a supposedly unobtrusive profiler makes for you. 
        */
        if (!isset($GLOBALS['_xhprof']['serializer']) || strtolower($GLOBALS['_xhprof']['serializer'] == 'php')) {
            $sql['get'] = $this->db->escape(serialize($_GET));
            $sql['cookie'] = $this->db->escape(serialize($_COOKIE));
            //This code has not been tested
            if (isset($_xhprof['savepost']) && $_xhprof['savepost']) {
                $sql['post'] = $this->db->escape(serialize($_POST));
            } else {
                $sql['post'] = $this->db->escape(serialize(array("Skipped" => "Post data omitted by rule")));
            }
        } else {
            $sql['get'] = $this->db->escape(json_encode($_GET));
            $sql['cookie'] = $this->db->escape(json_encode($_COOKIE));
            //This code has not been tested
            if (isset($_xhprof['savepost']) && $_xhprof['savepost']) {
                $sql['post'] = $this->db->escape(json_encode($_POST));
            } else {
                $sql['post'] = $this->db->escape(json_encode(array("Skipped" => "Post data omitted by rule")));
            }
        }
        $sql['pmu'] = isset($xhprof_data['main()']['pmu']) ? $xhprof_data['main()']['pmu'] : 0;
        $sql['wt'] = isset($xhprof_data['main()']['wt']) ? $xhprof_data['main()']['wt'] : 0;
        $sql['cpu'] = isset($xhprof_data['main()']['cpu']) ? $xhprof_data['main()']['cpu'] : 0;
        // The value of 2 seems to be light enugh that we're not killing the server, but still gives us lots of breathing room on
        // full production code.
        if (!isset($GLOBALS['_xhprof']['serializer']) || strtolower($GLOBALS['_xhprof']['serializer'] == 'php')) {
            $sql['data'] = $this->db->escape(gzcompress(serialize($xhprof_data), 2));
        } else {
            $sql['data'] = $this->db->escape(gzcompress(json_encode($xhprof_data), 2));
        }
        $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
        $sname = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
        $sql['url'] = $this->db->escape($url);
        $sql['c_url'] = $this->db->escape(_urlSimilartor($_SERVER['REQUEST_URI']));
        $sql['servername'] = $this->db->escape($sname);
        $sql['type'] = (int) (isset($xhprof_details['type']) ? $xhprof_details['type'] : 0);
        $sql['timestamp'] = $this->db->escape($_SERVER['REQUEST_TIME']);
        $sql['server_id'] = $this->db->escape($_xhprof['servername']);
        $sql['aggregateCalls_include'] = getenv('xhprof_aggregateCalls_include') ? getenv('xhprof_aggregateCalls_include') : '';
        $query = "INSERT INTO `details` (`id`, `url`, `c_url`, `timestamp`, `server name`, `perfdata`, `type`, `cookie`, `post`, `get`, `pmu`, `wt`, `cpu`, `server_id`, `aggregateCalls_include`) VALUES('{$run_id}', '{$sql['url']}', '{$sql['c_url']}', FROM_UNIXTIME('{$sql['timestamp']}'), '{$sql['servername']}', '{$sql['data']}', '{$sql['type']}', '{$sql['cookie']}', '{$sql['post']}', '{$sql['get']}', '{$sql['pmu']}', '{$sql['wt']}', '{$sql['cpu']}', '{$sql['server_id']}', '{$sql['aggregateCalls_include']}')";
        $this->db->query($query);
        if ($this->db->affectedRows($this->db->linkID) == 1) {
            return $run_id;
        } else {
            global $_xhprof;
            if ($_xhprof['display'] === true) {
                echo "Failed to insert: {$query} <br>\n";
            }
            return -1;
        }
    }

Usage Example

Exemple #1
0
function profilingFinalize($pre)
{
    include_once "/usr/share/php5-xhprof/xhprof_lib/utils/xhprof_lib.php";
    include_once "/usr/share/php5-xhprof/xhprof_lib/utils/xhprof_runs.php";
    $xhprof_runs = new XHProfRuns_Default();
    $xhprof_runs->save_run(xhprof_disable(), 'nagvis-' . $pre);
}
All Usage Examples Of XHProfRuns_Default::save_run