Skip to content

Commit

Permalink
first stab at adding metadata to the xhprof files in a backwards comp…
Browse files Browse the repository at this point in the history
…atible way
  • Loading branch information
Geoff Flarity committed Apr 24, 2012
1 parent b242640 commit b872893
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions xhprof_lib/utils/xhprof_runs.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function get_run($run_id, $type, &$run_desc);
* Returns the run id for the saved XHProf run.
*
*/
public function save_run($xhprof_data, $type, $run_id = null);
public function save_run($xhprof_data, $type, $run_id = null, $meta_data = null );
}


Expand Down Expand Up @@ -120,14 +120,50 @@ public function get_run($run_id, $type, &$run_desc) {
$data = gzfile($file_name);
$contents = implode($data);
$run_desc = "XHProf Run (Namespace=$type)";
return unserialize($contents);
$unserialized = unserialize($contents);

#if the unserialized data is an arrray, the data is using the metadata format
#we only return the xhprof_data to maintains api compatibility
if ( gettype( $unserialized ) == 'array' ) {
return $unserialized['xhprof_data']
}
else {
return $unserialized;
}
}

public function get_meta_data($run_id, $type, &$run_desc) {
$file_name = $this->file_name($run_id, $type);

if (!file_exists($file_name)) {
xhprof_error("Could not find file $file_name");
$run_desc = "Invalid Run Id = $run_id";
return null;
}

$data = gzfile($file_name);
$contents = implode($data);
$run_desc = "XHProf Run (Namespace=$type)";
$unserialized = unserialize($contents);

#if the unserialized data is an arrray, the data is using the metadata format
#we only return the xhprof_data to maintains api compatibility
if ( gettype( $unserialized ) == 'array' ) {
return $unserialized['meta_data']
}
else {
return null;
}
}

public function save_run($xhprof_data, $type, $run_id = null) {
public function save_run($xhprof_data, $type, $run_id = null, $metadata = null ) {

// Use PHP serialize function to store the XHProf's
// raw profiler data.
$xhprof_data = serialize($xhprof_data);
$all_data = array(
"xhprof_data" => $xhprof_data,
"meta_data" => $meta_data,
);

if ($run_id === null) {
$run_id = $this->gen_run_id($type);
Expand All @@ -137,7 +173,7 @@ public function save_run($xhprof_data, $type, $run_id = null) {
$file = gzopen($file_name, 'w');

if ($file) {
gzwrite($file, $xhprof_data);
gzwrite($file, $all_data);
gzclose($file);
} else {
xhprof_error("Could not open $file_name\n");
Expand Down

0 comments on commit b872893

Please sign in to comment.