本文整理汇总了PHP中getrusage函数的典型用法代码示例。如果您正苦于以下问题:PHP getrusage函数的具体用法?PHP getrusage怎么用?PHP getrusage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getrusage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCpuUsage
public function getCpuUsage()
{
$proc = getrusage();
$proc["ru_utime.tv_usec"] = $proc["ru_utime.tv_sec"] * 1000000.0 + $proc["ru_utime.tv_usec"] - $this->rusage;
$time = (microtime(true) - $this->tusage) * 1000000;
return $time > 0 ? sprintf("%01.2f", $proc["ru_utime.tv_usec"] / $time * 100) : '0.00';
}
示例2: getCpuTime
function getCpuTime($ru = null)
{
if ($ru == null) {
$ru = getrusage();
}
return $ru['ru_utime.tv_sec'] + $ru['ru_stime.tv_sec'] + ($ru['ru_utime.tv_usec'] + $ru['ru_stime.tv_usec']) * 1.0E-6;
}
示例3: thold_display_rusage
function thold_display_rusage()
{
global $thold_start_rusage;
if (function_exists('getrusage')) {
$dat = getrusage();
html_start_box('', '100%', '', '3', 'left', '');
print '<tr>';
if (!isset($thold_start_rusage)) {
print "<td colspan='10'>ERROR: Can not display RUSAGE please call thold_initialize_rusage first</td>";
} else {
$i_u_time = $thold_start_rusage['ru_utime.tv_sec'] + $thold_start_rusage['ru_utime.tv_usec'] * 1.0E-6;
$i_s_time = $thold_start_rusage['ru_stime.tv_sec'] + $thold_start_rusage['ru_stime.tv_usec'] * 1.0E-6;
$s_s = $thold_start_rusage['ru_nswap'];
$s_pf = $thold_start_rusage['ru_majflt'];
list($micro, $seconds) = explode(' ', $thold_start_rusage['microtime']);
$start_time = $seconds + $micro;
list($micro, $seconds) = explode(' ', microtime());
$end_time = $seconds + $micro;
$utime = $dat['ru_utime.tv_sec'] + $dat['ru_utime.tv_usec'] * 1.0E-6 - $i_u_time;
$stime = $dat['ru_stime.tv_sec'] + $dat['ru_stime.tv_usec'] * 1.0E-6 - $i_s_time;
$swaps = $dat['ru_nswap'] - $s_s;
$pages = $dat['ru_majflt'] - $s_pf;
print "<td colspan='10' width='1%' style='text-align:left;'>";
print '<b>' . __('Time:') . '</b> ' . round($end_time - $start_time, 2) . ' seconds, ';
print '<b>' . __('User:') . '</b> ' . round($utime, 2) . ' seconds, ';
print '<b>' . __('System:') . '</b> ' . round($stime, 2) . ' seconds, ';
print '<b>' . __('Swaps:') . '</b> ' . $swaps . ' swaps, ';
print '<b>' . __('Pages:') . '</b> ' . $pages . ' pages';
print '</td>';
}
print '</tr>';
html_end_box(false);
}
}
示例4: thold_display_rusage
function thold_display_rusage()
{
global $colors, $thold_start_rusage;
if (function_exists("getrusage")) {
$dat = getrusage();
html_start_box("", "100%", $colors["header"], "3", "left", "");
print "<tr>";
if (!isset($thold_start_rusage)) {
print "<td colspan='10'>ERROR: Can not display RUSAGE please call thold_initialize_rusage first</td>";
} else {
$i_u_time = $thold_start_rusage["ru_utime.tv_sec"] + $thold_start_rusage["ru_utime.tv_usec"] * 1.0E-6;
$i_s_time = $thold_start_rusage["ru_stime.tv_sec"] + $thold_start_rusage["ru_stime.tv_usec"] * 1.0E-6;
$s_s = $thold_start_rusage["ru_nswap"];
$s_pf = $thold_start_rusage["ru_majflt"];
list($micro, $seconds) = split(" ", $thold_start_rusage["microtime"]);
$start_time = $seconds + $micro;
list($micro, $seconds) = split(" ", microtime());
$end_time = $seconds + $micro;
$utime = $dat["ru_utime.tv_sec"] + $dat["ru_utime.tv_usec"] * 1.0E-6 - $i_u_time;
$stime = $dat["ru_stime.tv_sec"] + $dat["ru_stime.tv_usec"] * 1.0E-6 - $i_s_time;
$swaps = $dat["ru_nswap"] - $s_s;
$pages = $dat["ru_majflt"] - $s_pf;
print "<td colspan='10' width='1%' style='text-align:left;'>";
print "<b>Time:</b> " . round($end_time - $start_time, 2) . " seconds, ";
print "<b>User:</b> " . round($utime, 2) . " seconds, ";
print "<b>System:</b> " . round($stime, 2) . " seconds, ";
print "<b>Swaps:</b> " . $swaps . " swaps, ";
print "<b>Pages:</b> " . $pages . " pages";
print "</td>";
}
print "</tr>";
html_end_box(false);
}
}
示例5: cpuTime
public static function cpuTime()
{
$dat = getrusage();
$tv_usec = $dat["ru_utime.tv_sec"] * 1000000.0 + $dat["ru_utime.tv_usec"] - self::$RUSAGE;
$time = (microtime(true) - self::$TUSAGE) * 1000000.0;
$cpuusage = $tv_usec / $time;
return round($time / 1000 * $cpuusage);
}
示例6: log
/**
* @param $name
* @param $type
*/
public function log($name, $type)
{
if (!array_key_exists($type, $this->_typeList)) {
throw new \InvalidArgumentException("Type {$type} is incorrect");
}
$cpu = getrusage();
$this->_message[] = ['type' => $type, 'message' => $name, 'time' => microtime(true), 'memory' => memory_get_usage(true), 'cpu' => $cpu['ru_utime.tv_usec'] + $cpu['ru_stime.tv_usec']];
}
示例7: getTimeUsage
private function getTimeUsage()
{
if (!function_exists('getrusage')) {
return null;
}
$ru = getrusage();
return array('user_time' => $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1000000, 'system_time' => $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1000000);
}
示例8: sendHeaders
public function sendHeaders($serverErrorString = null)
{
// check we can send these first
if (headers_sent()) {
throw new ImThumbException("Could not set image headers, output already started", ImThumb::ERR_OUTPUTTING);
}
$modifiedDate = gmdate('D, d M Y H:i:s') . ' GMT';
// get image size. Have to workaround bugs in Imagick that return 0 for size by counting ourselves.
$byteSize = $this->image->getImageSize();
if ($this->image->hasBrowserCache()) {
header('HTTP/1.0 304 Not Modified');
} else {
if ($serverErrorString) {
header('HTTP/1.0 500 Internal Server Error');
header('X-ImThumb-Error: ' . $serverErrorString);
} else {
if (!$this->image->isValid()) {
header('HTTP/1.0 404 Not Found');
} else {
header('HTTP/1.0 200 OK');
}
}
header('Content-Type: ' . $this->image->getMime());
header('Accept-Ranges: none');
header('Last-Modified: ' . $modifiedDate);
header('Content-Length: ' . $byteSize);
if (!$this->image->param('browserCache')) {
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header("Pragma: no-cache");
header('Expires: ' . gmdate('D, d M Y H:i:s', time()));
} else {
$maxAge = $this->image->param('browserCacheMaxAge');
$expiryDate = gmdate('D, d M Y H:i:s', strtotime('now +' . $maxAge . ' seconds')) . ' GMT';
header('Cache-Control: max-age=' . $maxAge . ', must-revalidate');
header('Expires: ' . $expiryDate);
}
}
// informational headers
if (!$this->image->param('silent')) {
$im = new Imagick();
$imVer = $im->getVersion();
header('X-Generator: ImThumb v' . ImThumb::VERSION . '; ' . $imVer['versionString']);
if ($this->image->cache && $this->image->cache->isCached()) {
header('X-Img-Cache: HIT');
} else {
header('X-Img-Cache: MISS');
}
if ($this->image->param('debug')) {
list($startTime, $startCPU_u, $startCPU_s) = $this->image->getTimingStats();
header('X-Generated-In: ' . number_format(microtime(true) - $startTime, 6) . 's');
header('X-Memory-Peak: ' . number_format(memory_get_peak_usage() / 1024, 3, '.', '') . 'KB');
$data = getrusage();
$memusage = array((double) ($data['ru_utime.tv_sec'] + $data['ru_utime.tv_usec'] / 1000000), (double) ($data['ru_stime.tv_sec'] + $data['ru_stime.tv_usec'] / 1000000));
header('X-CPU-Utilisation:' . ' Usr ' . number_format($memusage[0] - $startCPU_u, 6) . ', Sys ' . number_format($memusage[1] - $startCPU_s, 6) . '; Base ' . number_format($startCPU_u, 6) . ', ' . number_format($startCPU_s, 6));
}
}
}
示例9: stop_time
public function stop_time()
{
$e_tmr = count($this->etime);
$this->etime[$e_tmr] = getrusage();
$ctime = $this->calc_time($this->etime[$e_tmr], $this->stime[$e_tmr], "utime");
$sctime = $this->calc_time($this->etime[$e_tmr], $this->stime[$e_tmr], "stime");
$this->results[$e_tmr]['compute'] = $ctime . " ms";
$this->results[$e_tmr]['calls'] = $sctime . " ms";
}
示例10: printResult
public function printResult()
{
$ru = getrusage();
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
echo '<b>Memory :</b> ' . memory_get_peak_usage() . '<br />';
echo '<b>Process Time :</b> ' . $time * 1000 . ' ms<br />';
echo 'This process used ' . self::_getrtime($ru, $this->start, "utime") . ' ms for its computations<br />';
echo 'It spent ' . self::_getrtime($ru, $this->start, "stime") . ' ms in system calls';
}
示例11: randomBytes
function randomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0)
{
static $lastRandom = "";
$output = "";
$length = abs((int) $length);
$secureValue = "";
$rounds = 0;
$drop = 0;
while (!isset($output[$length - 1])) {
//some entropy, but works ^^
$weakEntropy = array(is_array($startEntropy) ? implode($startEntropy) : $startEntropy, serialize(stat(__FILE__)), __DIR__, PHP_OS, microtime(), (string) lcg_value(), (string) PHP_MAXPATHLEN, PHP_SAPI, (string) PHP_INT_MAX . "." . PHP_INT_SIZE, serialize($_SERVER), serialize(get_defined_constants()), get_current_user(), serialize(ini_get_all()), (string) memory_get_usage() . "." . memory_get_peak_usage(), php_uname(), phpversion(), extension_loaded("gmp") ? gmp_strval(gmp_random(4)) : microtime(), zend_version(), (string) getmypid(), (string) getmyuid(), (string) mt_rand(), (string) getmyinode(), (string) getmygid(), (string) rand(), function_exists("zend_thread_id") ? (string) zend_thread_id() : microtime(), var_export(@get_browser(), true), function_exists("getrusage") ? @implode(getrusage()) : microtime(), function_exists("sys_getloadavg") ? @implode(sys_getloadavg()) : microtime(), serialize(get_loaded_extensions()), sys_get_temp_dir(), (string) disk_free_space("."), (string) disk_total_space("."), uniqid(microtime(), true), file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : microtime());
shuffle($weakEntropy);
$value = hash("sha512", implode($weakEntropy), true);
$lastRandom .= $value;
foreach ($weakEntropy as $k => $c) {
//mixing entropy values with XOR and hash randomness extractor
$value ^= hash("sha256", $c . microtime() . $k, true) . hash("sha256", mt_rand() . microtime() . $k . $c, true);
$value ^= hash("sha512", (string) lcg_value() . $c . microtime() . $k, true);
}
unset($weakEntropy);
if ($secure === true) {
$strongEntropyValues = array(is_array($startEntropy) ? hash("sha512", $startEntropy[($rounds + $drop) % count($startEntropy)], true) : hash("sha512", $startEntropy, true), file_exists("/dev/urandom") ? fread(fopen("/dev/urandom", "rb"), 64) : str_repeat("", 64), (function_exists("openssl_random_pseudo_bytes") and version_compare(PHP_VERSION, "5.3.4", ">=")) ? openssl_random_pseudo_bytes(64) : str_repeat("", 64), function_exists("mcrypt_create_iv") ? mcrypt_create_iv(64, MCRYPT_DEV_URANDOM) : str_repeat("", 64), $value);
$strongEntropy = array_pop($strongEntropyValues);
foreach ($strongEntropyValues as $value) {
$strongEntropy = $strongEntropy ^ $value;
}
$value = "";
//Von Neumann randomness extractor, increases entropy
$bitcnt = 0;
for ($j = 0; $j < 64; ++$j) {
$a = ord($strongEntropy[$j]);
for ($i = 0; $i < 8; $i += 2) {
$b = ($a & 1 << $i) > 0 ? 1 : 0;
if ($b != (($a & 1 << $i + 1) > 0 ? 1 : 0)) {
$secureValue |= $b << $bitcnt;
if ($bitcnt == 7) {
$value .= chr($secureValue);
$secureValue = 0;
$bitcnt = 0;
} else {
++$bitcnt;
}
++$drop;
} else {
$drop += 2;
}
}
}
}
$output .= substr($value, 0, min($length - strlen($output), $length));
unset($value);
++$rounds;
}
$lastRandom = hash("sha512", $lastRandom, true);
return $raw === false ? bin2hex($output) : $output;
}
示例12: wfGetRusage
/**
* Get system resource usage of current request context.
* Invokes the getrusage(2) system call, requesting RUSAGE_SELF if on PHP5
* or RUSAGE_THREAD if on HHVM. Returns false if getrusage is not available.
*
* @since 1.24
* @return array|bool Resource usage data or false if no data available.
*/
function wfGetRusage()
{
if (!function_exists('getrusage')) {
return false;
} elseif (defined('HHVM_VERSION')) {
return getrusage(2);
} else {
return getrusage(0);
}
}
示例13: getNow
public static function getNow()
{
$time = microtime(true);
$usage = getrusage();
$child_usage = getrusage(1);
$sys_time = sprintf("%d.%f", $usage["ru_stime.tv_sec"], $usage["ru_stime.tv_usec"]);
$user_time = sprintf("%d.%f", $usage["ru_utime.tv_sec"], $usage["ru_utime.tv_usec"]);
$child_sys_time = sprintf("%d.%f", $child_usage["ru_stime.tv_sec"], $child_usage["ru_stime.tv_usec"]);
$child_user_time = sprintf("%d.%f", $child_usage["ru_utime.tv_sec"], $child_usage["ru_utime.tv_usec"]);
return new Time($time, $sys_time, $user_time, $child_sys_time, $child_user_time);
}
示例14: getUsage
protected function getUsage()
{
/*
* getrusage is not available on windows with php < 7
*/
if (!function_exists('getrusage')) {
return 0;
}
$cpu = getrusage();
return $cpu["ru_utime.tv_sec"] * 1000000.0 + $cpu["ru_utime.tv_usec"];
}
示例15: _save
public function _save()
{
$root = self::_calculate_item(array_pop(self::$_stack));
$result = array('url' => $_SERVER['REQUEST_URI'], 'microtime' => $this->_microtime, 'data' => $root, 'log' => self::$_log, 'included_files' => get_included_files(), 'declared_classes' => get_declared_classes(), 'memory' => array('usage' => memory_get_usage(), 'peak' => memory_get_peak_usage()), 'rusage' => getrusage(), 'queries' => Database::$log, 'post' => $_POST, 'get' => $_GET);
$json = json_encode($result, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
$microtime = explode(' ', $this->_microtime);
$seconds = $microtime[1];
$millis = $microtime[0];
$filename = $seconds . '[' . $millis . '].json';
file_put_contents($this->_cwd . '/profiling/' . $filename, $json);
}