Is there a way to measure the amount/length of time a web request spends doing I/O?
By that, I mean the actual amount of time the current thread (or it's delegation) has spent utilizing the hardware.
As for measuring CPU time, there's a function getrusage()
for it:
<?php
$a = getrusage();
f();
$b = getrusage();
$sec = ($b['ru_utime.tv_sec'] - $a['ru_utime.tv_sec']) + ($b['ru_stime.tv_sec'] - $a['ru_stime.tv_sec']);
echo 'It took ~' . $sec . 's of CPU time.';
function f(){
for($x=0;$x<120000000;++$x){
// busy loop
}
}
Is there a such a function for measuring I/O?
Sample usage of said function:
<?php
$credits_remaining = 8500;
$a = Time_Spent_On_Hard_Disk_So_Far();
Get_File_From_Hard_Disk($credits_remaining); // limit request to $credits_remaining number of seconds
$b = Time_Spent_On_Hard_Disk_So_Far();
$time_spent = $b - $a;
echo "Time spent on hard disk: ", $time_spent;
$credits_remaining -= $time_spent;
(A C solution would be fine, as long as we can call it from PHP without suffering from severe overheads.)