Skip to content

Instantly share code, notes, and snippets.

@boutell
Created April 7, 2012 14:11
Show Gist options
  • Save boutell/2329270 to your computer and use it in GitHub Desktop.
Save boutell/2329270 to your computer and use it in GitHub Desktop.
Profile CPU performance at 1-minute intervals, compare it to reported load average
<?php
$file = dirname(__FILE__) . '/profile.csv';
$out = fopen($file, 'a');
$load = @file_get_contents('/proc/loadavg');
$load = preg_split('/ /', $load);
$load = $load[0];
// Do some math, see how long it really takes
$n = 2308974928374092387430948723;
$now = date('Y-m-d H:i');
$start = microtime();
for ($i = 0; ($i < 10000); $i++)
{
$n = $n * 4 % 3;
}
$end = microtime();
// Column 1 is the time, column 2 is the reported load average,
// column 3 is how long it really took to do the math. If they
// don't correlate very well then some third factor, like
// heavy load elsewhere in the system virtualizing this VM,
// may be at fault
fputcsv($out, array($now, $load, $end-$start));
fclose($out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment