Skip to content

Commit

Permalink
Merge pull request gajus#37 from mdevine82/master
Browse files Browse the repository at this point in the history
- Add thresholds to allow run data to be ignored if it doesn't exceed se...
  • Loading branch information
staabm committed Mar 25, 2015
2 parents 8d5e788 + fb5d3ea commit f477c4d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
37 changes: 37 additions & 0 deletions inc/prepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function xhprof_shutdown()
fastcgi_finish_request();
}

//Check to see if xhprof data exceed minimum set profile times
if (!xhprof_check_min_run_values($xhprof_data, $xhprofMainConfig)) {
return;
}

try {
require_once __DIR__ . '/../xhprof/classes/data.php';

Expand All @@ -84,3 +89,35 @@ function xhprof_shutdown()
throw $e;
}
}

// Check profile run times and opt not to store the data if they are below
// set thresholds. This should reduce amount of stored data for production
// instances.
function xhprof_check_min_run_values($profile_data, $xhprofMainConfig) {
$store_flag = true;

$lastElement = end($profile_data);

$wallTimeExists = isset($lastElement['wt']) && isset($xhprofMainConfig['min_wall_time']);

if ($wallTimeExists && $lastElement['wt'] < $xhprofMainConfig['min_wall_time']) {
$store_flag = false;
}

$cpuTimeExists = isset($lastElement['cpu']) && isset($xhprofMainConfig['min_cpu_time']);
if ($store_flag && $cpuTimeExists && $lastElement['cpu'] < $xhprofMainConfig['min_cpu_time']) {
$store_flag = false;
}

$memUsageExists = isset($lastElement['mu']) && isset($xhprofMainConfig['min_mem_usage']);
if ($store_flag && $memUsageExists && $lastElement['mu'] < $xhprofMainConfig['min_mem_usage']) {
$store_flag = false;
}

$peakMemUsageExists = isset($lastElement['pmu']) && isset($xhprofMainConfig['min_peak_mem_usage']);
if ($store_flag && $peakMemUsageExists && $lastElement['pmu'] < $xhprofMainConfig['min_peak_mem_usage']) {
$store_flag = false;
}

return $store_flag;
}
8 changes: 6 additions & 2 deletions xhprof/includes/config.inc.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
'pdo' => new PDO('mysql:dbname=your_database_name;host=localhost;charset=utf8', 'username', 'password'),
'tmp_table_engine' => 'Memory', // MySQL Table Engine used for temporary tables
'cache_expiration' => '60', // How many seconds a browser allowed to cache profilling results
'profiler_enabled' => true // Global switch to disable the profiler by default
);
'profiler_enabled' => true, // Global switch to disable the profiler by default
'min_wall_time' => 0, // Only store runs with total wall time greater than value (microseconds)
'min_cpu_time' => 0, // Only store runs with total CPU time greater than value (microseconds)
'min_mem_usage' => 0, // Only store runs with memory usage greater than value (bytes)
'min_peak_mem_usage' => 0, // Only store runs with peak memory usage greater than value (bytes)
);

0 comments on commit f477c4d

Please sign in to comment.