How to use memory_usage class

Best Phoronix-test-suite code snippet using memory_usage

status.php

Source:status.php Github

copy

Full Screen

...127 if (empty($context['cpu_info']['hz']) && preg_match('~dev\.cpu\.0\.freq:(.+)~', $cpuinfo, $match) != 0)128 $context['cpu_info']['hz'] = trim($match[1]);129 }130 }131 $context['memory_usage'] = array();132 function unix_memsize($str)133 {134 $str = strtr($str, array(',' => ''));135 if (strtolower(substr($str, -1)) == 'g')136 return $str * 1024 * 1024;137 elseif (strtolower(substr($str, -1)) == 'm')138 return $str * 1024;139 elseif (strtolower(substr($str, -1)) == 'k')140 return (int) $str;141 else142 return $str / 1024;143 }144 $meminfo = @get_file_data('/proc/meminfo');145 if (!empty($meminfo))146 {147 if (preg_match('~:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)~', $meminfo[1], $matches) != 0)148 {149 $context['memory_usage']['total'] = $matches[1] / 1024;150 $context['memory_usage']['used'] = $matches[2] / 1024;151 $context['memory_usage']['free'] = $matches[3] / 1024;152 /*$context['memory_usage']['shared'] = $matches[4] / 1024;153 $context['memory_usage']['buffers'] = $matches[5] / 1024;154 $context['memory_usage']['cached'] = $matches[6] / 1024;*/155 }156 else157 {158 $mem = implode('', $meminfo);159 if (preg_match('~memtotal:\s*(\d+ [kmgb])~i', $mem, $match) != 0)160 $context['memory_usage']['total'] = unix_memsize($match[1]);161 if (preg_match('~memfree:\s*(\d+ [kmgb])~i', $mem, $match) != 0)162 $context['memory_usage']['free'] = unix_memsize($match[1]);163 if (isset($context['memory_usage']['total'], $context['memory_usage']['free']))164 $context['memory_usage']['used'] = $context['memory_usage']['total'] - $context['memory_usage']['free'];165 /*if (preg_match('~buffers:\s*(\d+ [kmgb])~i', $mem, $match) != 0)166 $context['memory_usage']['buffers'] = unix_memsize($match[1]);167 if (preg_match('~cached:\s*(\d+ [kmgb])~i', $mem, $match) != 0)168 $context['memory_usage']['cached'] = unix_memsize($match[1]);*/169 if (preg_match('~swaptotal:\s*(\d+ [kmgb])~i', $mem, $match) != 0)170 $context['memory_usage']['swap_total'] = unix_memsize($match[1]);171 if (preg_match('~swapfree:\s*(\d+ [kmgb])~i', $mem, $match) != 0)172 $context['memory_usage']['swap_free'] = unix_memsize($match[1]);173 if (isset($context['memory_usage']['swap_total'], $context['memory_usage']['swap_free']))174 $context['memory_usage']['swap_used'] = $context['memory_usage']['swap_total'] - $context['memory_usage']['swap_free'];175 }176 if (preg_match('~:\s+(\d+)\s+(\d+)\s+(\d+)~', $meminfo[2], $matches) != 0)177 {178 $context['memory_usage']['swap_total'] = $matches[1] / 1024;179 $context['memory_usage']['swap_used'] = $matches[2] / 1024;180 $context['memory_usage']['swap_free'] = $matches[3] / 1024;181 }182 $meminfo = false;183 }184 // Maybe a generic free?185 elseif (empty($context['memory_usage']))186 {187 $meminfo = explode("\n", @`free -k 2>/dev/null | awk '{ if ($2 * 1 > 0) print $2, $3, $4; }'`);188 if (!empty($meminfo[0]))189 {190 $meminfo[0] = explode(' ', $meminfo[0]);191 $meminfo[1] = explode(' ', $meminfo[1]);192 $context['memory_usage']['total'] = $meminfo[0][0] / 1024;193 $context['memory_usage']['used'] = $meminfo[0][1] / 1024;194 $context['memory_usage']['free'] = $meminfo[0][2] / 1024;195 $context['memory_usage']['swap_total'] = $meminfo[1][0] / 1024;196 $context['memory_usage']['swap_used'] = $meminfo[1][1] / 1024;197 $context['memory_usage']['swap_free'] = $meminfo[1][2] / 1024;198 }199 }200 // Solaris, Mac OS X, or FreeBSD?201 if (empty($context['memory_usage']))202 {203 // Well, Solaris will have kstat.204 $meminfo = explode("\n", @`kstat -p unix:0:system_pages:physmem unix:0:system_pages:freemem 2>/dev/null | awk '{ print $2 }'`);205 if (!empty($meminfo[0]))206 {207 $pagesize = `/usr/bin/pagesize`;208 $context['memory_usage']['total'] = unix_memsize($meminfo[0] * $pagesize);209 $context['memory_usage']['free'] = unix_memsize($meminfo[1] * $pagesize);210 $context['memory_usage']['used'] = $context['memory_usage']['total'] - $context['memory_usage']['free'];211 $meminfo = explode("\n", @`swap -l 2>/dev/null | awk '{ if ($4 * 1 > 0) print $4, $5; }'`);212 $context['memory_usage']['swap_total'] = 0;213 $context['memory_usage']['swap_free'] = 0;214 foreach ($meminfo as $memline)215 {216 $memline = explode(' ', $memline);217 if (empty($memline[0]))218 continue;219 $context['memory_usage']['swap_total'] += $memline[0];220 $context['memory_usage']['swap_free'] += $memline[1];221 }222 $context['memory_usage']['swap_used'] = $context['memory_usage']['swap_total'] - $context['memory_usage']['swap_free'];223 }224 }225 if (empty($context['memory_usage']))226 {227 // FreeBSD should have hw.physmem.228 $meminfo = @`sysctl hw.physmem 2>/dev/null`;229 if (strpos(strtolower(PHP_OS), 'darwin') !== 0 && !empty($meminfo) && preg_match('~hw\.physmem: (\d+)~i', $meminfo, $match) != 0)230 {231 $context['memory_usage']['total'] = unix_memsize($match[1]);232 $meminfo = @`sysctl hw.pagesize vm.stats.vm.v_free_count 2>/dev/null`;233 if (!empty($meminfo) && preg_match('~hw\.pagesize: (\d+)~i', $meminfo, $match1) != 0 && preg_match('~vm\.stats\.vm\.v_free_count: (\d+)~i', $meminfo, $match2) != 0)234 {235 $context['memory_usage']['free'] = $match1[1] * $match2[1] / 1024;236 $context['memory_usage']['used'] = $context['memory_usage']['total'] - $context['memory_usage']['free'];237 }238 $meminfo = @`swapinfo 2>/dev/null | awk '{ print $2, $4; }'`;239 if (preg_match('~(\d+) (\d+)~', $meminfo, $match) != 0)240 {241 $context['memory_usage']['swap_total'] = $match[1];242 $context['memory_usage']['swap_free'] = $match[2];243 $context['memory_usage']['swap_used'] = $context['memory_usage']['swap_total'] - $context['memory_usage']['swap_free'];244 }245 }246 // Let's guess Mac OS X?247 else248 {249 $meminfo = @`top -l1 2>/dev/null`;250 if (!empty($meminfo) && preg_match('~PhysMem:\s+(?:.+?)\s+([\d\.]+\w) used,\s+([\d\.]+\w) free~', $meminfo, $match) != 0)251 {252 $context['memory_usage']['used'] = unix_memsize($match[1]);253 $context['memory_usage']['free'] = unix_memsize($match[2]);254 $context['memory_usage']['total'] = $context['memory_usage']['used'] + $context['memory_usage']['free'];255 }256 }257 }258 // Can we obtain an uptime?259 $lastreboot = @get_file_data('/proc/uptime');260 if (!empty($lastreboot))261 {262 $lastreboot = explode(' ', $lastreboot[0]);263 $context['lastserverreboot'] = time() - trim($lastreboot[0]);264 }265 // Mac OS X and others?266 if (empty($context['lastserverreboot']))267 {268 $lastreboot = @`sysctl kern.boottime 2>/dev/null`;269 if (!empty($lastreboot) && preg_match('~kern\.boottime: { sec\s+=\s+(\d+),~', $lastreboot, $match) != 0)270 $context['lastserverreboot'] = $match[1];271 }272 $context['operating_system']['type'] = 'unix';273 $check_release = array('centos', 'fedora', 'gentoo', 'redhat', 'slackware', 'yellowdog');274 foreach ($check_release as $os)275 {276 if (@file_exists('/etc/' . $os . '-release'))277 $context['operating_system']['name'] = implode('', get_file_data('/etc/' . $os . '-release'));278 }279 if (isset($context['operating_system']['name']))280 true;281 elseif (@file_exists('/etc/debian_version'))282 $context['operating_system']['name'] = 'Debian ' . implode('', get_file_data('/etc/debian_version'));283 elseif (@file_exists('/etc/SuSE-release'))284 {285 $temp = get_file_data('/etc/SuSE-release');286 $context['operating_system']['name'] = trim($temp[0]);287 }288 elseif (@file_exists('/etc/release'))289 {290 $temp = get_file_data('/etc/release');291 $context['operating_system']['name'] = trim($temp[0]);292 }293 else294 $context['operating_system']['name'] = trim(@`uname -s -r 2>/dev/null`);295 $context['running_processes'] = array();296 $processes = @`ps auxc 2>/dev/null | awk '{ print $2, $3, $4, $8, $11, $12 }'`;297 if (empty($processes))298 $processes = @`ps aux 2>/dev/null | awk '{ print $2, $3, $4, $8, $11, $12 }'`;299 // Maybe it's Solaris?300 if (empty($processes))301 $processes = @`ps -eo pid,pcpu,pmem,s,fname 2>/dev/null | awk '{ print $1, $2, $3, $4, $5, $6 }'`;302 // Okay, how about QNX?303 if (empty($processes))304 $processes = @`ps -eo pid,pcpu,comm 2>/dev/null | awk '{ print $1, $2, 0, "", $5, $6 }'`;305 if (!empty($processes))306 {307 $processes = explode("\n", $processes);308 $context['num_zombie_processes'] = 0;309 $context['num_sleeping_processes'] = 0;310 $context['num_running_processes'] = 0;311 for ($i = 1, $n = count($processes) - 1; $i < $n; $i++)312 {313 $proc = explode(' ', $processes[$i], 5);314 $additional = @implode('', @get_file_data('/proc/' . $proc[0] . '/statm'));315 if ($proc[4][0] != '[' && strpos($proc[4], ' ') !== false)316 $proc[4] = strtok($proc[4], ' ');317 $context['running_processes'][$proc[0]] = array(318 'id' => $proc[0],319 'cpu' => $proc[1],320 'mem' => $proc[2],321 'title' => $proc[4],322 );323 if (strpos($proc[3], 'Z') !== false)324 $context['num_zombie_processes']++;325 elseif (strpos($proc[3], 'S') !== false)326 $context['num_sleeping_processes']++;327 else328 $context['num_running_processes']++;329 if (!empty($additional))330 {331 $additional = explode(' ', $additional);332 $context['running_processes'][$proc[0]]['mem_usage'] = $additional[0];333 }334 }335 $context['top_memory_usage'] = array('(other)' => array('name' => '(other)', 'percent' => 0, 'number' => 0));336 $context['top_cpu_usage'] = array('(other)' => array('name' => '(other)', 'percent' => 0, 'number' => 0));337 foreach ($context['running_processes'] as $proc)338 {339 $id = basename($proc['title']);340 if (!isset($context['top_memory_usage'][$id]))341 $context['top_memory_usage'][$id] = array('name' => $id, 'percent' => $proc['mem'], 'number' => 1);342 else343 {344 $context['top_memory_usage'][$id]['percent'] += $proc['mem'];345 $context['top_memory_usage'][$id]['number']++;346 }347 if (!isset($context['top_cpu_usage'][$id]))348 $context['top_cpu_usage'][$id] = array('name' => $id, 'percent' => $proc['cpu'], 'number' => 1);349 else350 {351 $context['top_cpu_usage'][$id]['percent'] += $proc['cpu'];352 $context['top_cpu_usage'][$id]['number']++;353 }354 }355 // TODO: shared memory?356 foreach ($context['top_memory_usage'] as $proc)357 {358 if ($proc['percent'] >= 1 || $proc['name'] == '(other)')359 continue;360 unset($context['top_memory_usage'][$proc['name']]);361 $context['top_memory_usage']['(other)']['percent'] += $proc['percent'];362 $context['top_memory_usage']['(other)']['number']++;363 }364 foreach ($context['top_cpu_usage'] as $proc)365 {366 if ($proc['percent'] >= 0.6 || $proc['name'] == '(other)')367 continue;368 unset($context['top_cpu_usage'][$proc['name']]);369 $context['top_cpu_usage']['(other)']['percent'] += $proc['percent'];370 $context['top_cpu_usage']['(other)']['number']++;371 }372 }373}374function get_windows_data()375{376 global $context;377 $context['current_time'] = strftime('%B %d, %Y, %I:%M:%S %p');378 function windows_memsize($str)379 {380 $str = strtr($str, array(',' => ''));381 if (strtolower(substr($str, -2)) == 'gb')382 return $str * 1024 * 1024;383 elseif (strtolower(substr($str, -2)) == 'mb')384 return $str * 1024;385 elseif (strtolower(substr($str, -2)) == 'kb')386 return (int) $str;387 elseif (strtolower(substr($str, -2)) == ' b')388 return $str / 1024;389 else390 trigger_error('Unknown memory format \'' . $str . '\'', E_USER_NOTICE);391 }392 $systeminfo = @`systeminfo /fo csv`;393 if (!empty($systeminfo))394 {395 $systeminfo = explode("\n", $systeminfo);396 $headings = explode('","', substr($systeminfo[1], 1, -1));397 $values = explode('","', substr($systeminfo[2], 1, -1));398 $context['cpu_info'] = array();399 if ($i = array_search('Processor(s)', $headings))400 if (preg_match('~\[01\]: (.+?) (\~?\d+) Mhz$~i', $values[$i], $match) != 0)401 {402 $context['cpu_info']['model'] = $match[1];403 $context['cpu_info']['hz'] = $match[2];404 }405 $context['memory_usage'] = array();406 if ($i = array_search('Total Physical Memory', $headings))407 $context['memory_usage']['total'] = windows_memsize($values[$i]);408 if ($i = array_search('Available Physical Memory', $headings))409 $context['memory_usage']['free'] = windows_memsize($values[$i]);410 if (isset($context['memory_usage']['total'], $context['memory_usage']['free']))411 $context['memory_usage']['used'] = $context['memory_usage']['total'] - $context['memory_usage']['free'];412 if ($i = array_search('Virtual Memory: Available', $headings))413 $context['memory_usage']['swap_total'] = windows_memsize($values[$i]);414 if ($i = array_search('Virtual Memory: In Use', $headings))415 $context['memory_usage']['swap_used'] = windows_memsize($values[$i]);416 if (isset($context['memory_usage']['swap_total'], $context['memory_usage']['swap_free']))417 $context['memory_usage']['swap_free'] = $context['memory_usage']['swap_total'] - $context['memory_usage']['swap_used'];418 }419 $context['operating_system']['type'] = 'windows';420 $context['operating_system']['name'] = `ver`;421 if (empty($context['operating_system']['name']))422 $context['operating_system']['name'] = 'Microsoft Windows';423 $context['running_processes'] = array();424 $processes = @`tasklist /fo csv /v /nh`;425 if (!empty($processes))426 {427 $processes = explode("\n", $processes);428 $total_mem = 0;429 $total_cpu = 0;430 $context['num_zombie_processes'] = 0;431 $context['num_sleeping_processes'] = 0;432 $context['num_running_processes'] = 0;433 foreach ($processes as $proc)434 {435 if (empty($proc))436 continue;437 $proc = explode('","', substr($proc, 1, -1));438 $proc[7] = explode(':', $proc[7]);439 $proc[7] = ($proc[7][0] * 3600) + ($proc[7][1] * 60) + $proc[7][2];440 if (substr($proc[4], -1) == 'K')441 $proc[4] = (int) $proc[4];442 elseif (substr($proc[4], -1) == 'M')443 $proc[4] = $proc[4] * 1024;444 elseif (substr($proc[4], -1) == 'G')445 $proc[4] = $proc[4] * 1024 * 1024;446 else447 $proc[4] = $proc[4] / 1024;448 $context['running_processes'][$proc[1]] = array(449 'id' => $proc[1],450 'cpu_time' => $proc[7],451 'mem_usage' => $proc[4],452 'title' => $proc[0],453 );454 if (strpos($proc[5], 'Not') !== false)455 $context['num_zombie_processes']++;456 else457 $context['num_running_processes']++;458 $total_mem += $proc[4];459 $total_cpu += $proc[7];460 }461 foreach ($context['running_processes'] as $proc)462 {463 $context['running_processes'][$proc['id']]['cpu'] = ($proc['cpu_time'] * 100) / $total_cpu;464 $context['running_processes'][$proc['id']]['mem'] = ($proc['mem_usage'] * 100) / $total_mem;465 }466 $context['top_memory_usage'] = array('(other)' => array('name' => '(other)', 'percent' => 0, 'number' => 0));467 $context['top_cpu_usage'] = array('(other)' => array('name' => '(other)', 'percent' => 0, 'number' => 0));468 foreach ($context['running_processes'] as $proc)469 {470 $id = basename($proc['title']);471 if (!isset($context['top_memory_usage'][$id]))472 $context['top_memory_usage'][$id] = array('name' => $id, 'percent' => $proc['mem'], 'number' => 1);473 else474 {475 $context['top_memory_usage'][$id]['percent'] += $proc['mem'];476 $context['top_memory_usage'][$id]['number']++;477 }478 if (!isset($context['top_cpu_usage'][$id]))479 $context['top_cpu_usage'][$id] = array('name' => $id, 'percent' => $proc['cpu'], 'number' => 1);480 else481 {482 $context['top_cpu_usage'][$id]['percent'] += $proc['cpu'];483 $context['top_cpu_usage'][$id]['number']++;484 }485 }486 // TODO: shared memory?487 foreach ($context['top_memory_usage'] as $proc)488 {489 if ($proc['percent'] >= 1 || $proc['name'] == '(other)')490 continue;491 unset($context['top_memory_usage'][$proc['name']]);492 $context['top_memory_usage']['(other)']['percent'] += $proc['percent'];493 $context['top_memory_usage']['(other)']['number']++;494 }495 foreach ($context['top_cpu_usage'] as $proc)496 {497 if ($proc['percent'] >= 0.6 || $proc['name'] == '(other)')498 continue;499 unset($context['top_cpu_usage'][$proc['name']]);500 $context['top_cpu_usage']['(other)']['percent'] += $proc['percent'];501 $context['top_cpu_usage']['(other)']['number']++;502 }503 }504}505function get_mysql_data()506{507 global $context, $db_prefix;508 if (!isset($db_prefix) || $db_prefix === false)509 return;510 $request = mysql_query("511 SELECT CONCAT(SUBSTRING(VERSION(), 1, LOCATE('.', VERSION(), 3)), 'x')");512 list ($context['mysql_version']) = mysql_fetch_row($request);513 mysql_free_result($request);514 $request = mysql_query("515 SHOW VARIABLES");516 $context['mysql_variables'] = array();517 while ($row = @mysql_fetch_row($request))518 $context['mysql_variables'][$row[0]] = array(519 'name' => $row[0],520 'value' => $row[1],521 );522 @mysql_free_result($request);523 $request = mysql_query("524 SHOW /*!50000 GLOBAL */ STATUS");525 $context['mysql_status'] = array();526 while ($row = @mysql_fetch_row($request))527 $context['mysql_status'][$row[0]] = array(528 'name' => $row[0],529 'value' => $row[1],530 );531 @mysql_free_result($request);532 $context['mysql_num_sleeping_processes'] = 0;533 $context['mysql_num_locked_processes'] = 0;534 $context['mysql_num_running_processes'] = 0;535 $request = mysql_query("536 SHOW FULL PROCESSLIST");537 $context['mysql_processes'] = array();538 while ($row = @mysql_fetch_assoc($request))539 {540 if ($row['State'] == 'Locked' || $row['State'] == 'Waiting for tables')541 $context['mysql_num_locked_processes']++;542 elseif ($row['Command'] == 'Sleep')543 $context['mysql_num_sleeping_processes']++;544 elseif (trim($row['Info']) == 'SHOW FULL PROCESSLIST' && $row['Time'] == 0 || trim($row['Info']) == '')545 $context['mysql_num_running_processes']++;546 else547 {548 $context['mysql_num_running_processes']++;549 $context['mysql_processes'][] = array(550 'id' => $row['Id'],551 'database' => $row['db'],552 'time' => $row['Time'],553 'state' => $row['State'],554 'query' => $row['Info'],555 );556 }557 }558 @mysql_free_result($request);559 $context['mysql_statistics'] = array();560 if (isset($context['mysql_status']['Connections'], $context['mysql_status']['Uptime']))561 $context['mysql_statistics'][] = array(562 'description' => 'Connections per second',563 'value' => $context['mysql_status']['Connections']['value'] / max(1, $context['mysql_status']['Uptime']['value']),564 );565 if (isset($context['mysql_status']['Bytes_received'], $context['mysql_status']['Uptime']))566 $context['mysql_statistics'][] = array(567 'description' => 'Kilobytes received per second',568 'value' => ($context['mysql_status']['Bytes_received']['value'] / max(1, $context['mysql_status']['Uptime']['value'])) / 1024,569 );570 if (isset($context['mysql_status']['Bytes_sent'], $context['mysql_status']['Uptime']))571 $context['mysql_statistics'][] = array(572 'description' => 'Kilobytes sent per second',573 'value' => ($context['mysql_status']['Bytes_sent']['value'] / max(1, $context['mysql_status']['Uptime']['value'])) / 1024,574 );575 if (isset($context['mysql_status']['Questions'], $context['mysql_status']['Uptime']))576 $context['mysql_statistics'][] = array(577 'description' => 'Queries per second',578 'value' => $context['mysql_status']['Questions']['value'] / max(1, $context['mysql_status']['Uptime']['value']),579 );580 if (isset($context['mysql_status']['Slow_queries'], $context['mysql_status']['Questions']))581 $context['mysql_statistics'][] = array(582 'description' => 'Percentage of slow queries',583 'value' => $context['mysql_status']['Slow_queries']['value'] / max(1, $context['mysql_status']['Questions']['value']),584 );585 if (isset($context['mysql_status']['Opened_tables'], $context['mysql_status']['Open_tables']))586 $context['mysql_statistics'][] = array(587 'description' => 'Opened vs. Open tables',588 'value' => $context['mysql_status']['Opened_tables']['value'] / max(1, $context['mysql_status']['Open_tables']['value']),589 'setting' => 'table_cache',590 'max' => 80,591 );592 if (isset($context['mysql_status']['Opened_tables'], $context['mysql_variables']['table_cache']['value']))593 $context['mysql_statistics'][] = array(594 'description' => 'Table cache usage',595 'value' => $context['mysql_status']['Open_tables']['value'] / max(1, $context['mysql_variables']['table_cache']['value']),596 'setting' => 'table_cache',597 'min' => 0.5,598 'max' => 0.9,599 );600 if (isset($context['mysql_status']['Key_reads'], $context['mysql_status']['Key_read_requests']))601 $context['mysql_statistics'][] = array(602 'description' => 'Key buffer read hit rate',603 'value' => $context['mysql_status']['Key_reads']['value'] / max(1, $context['mysql_status']['Key_read_requests']['value']),604 'setting' => 'key_buffer_size',605 'max' => 0.01,606 );607 if (isset($context['mysql_status']['Key_writes'], $context['mysql_status']['Key_write_requests']))608 $context['mysql_statistics'][] = array(609 'description' => 'Key buffer write hit rate',610 'value' => $context['mysql_status']['Key_writes']['value'] / max(1, $context['mysql_status']['Key_write_requests']['value']),611 'setting' => 'key_buffer_size',612 'max' => 0.5,613 );614 if (isset($context['mysql_status']['Threads_created'], $context['mysql_status']['Connections']))615 $context['mysql_statistics'][] = array(616 'description' => 'Thread cache hit rate',617 'value' => $context['mysql_status']['Connections']['value'] / max(1, $context['mysql_status']['Threads_created']['value']),618 'setting' => 'thread_cache_size',619 'min' => 30,620 );621 if (isset($context['mysql_status']['Threads_created'], $context['mysql_variables']['thread_cache_size']))622 $context['mysql_statistics'][] = array(623 'description' => 'Thread cache usage',624 'value' => $context['mysql_status']['Threads_cached']['value'] / max(1, $context['mysql_variables']['thread_cache_size']['value']),625 'setting' => 'thread_cache_size',626 'min' => 0.7,627 'max' => 0.9,628 );629 if (isset($context['mysql_status']['Created_tmp_tables'], $context['mysql_status']['Created_tmp_disk_tables']))630 $context['mysql_statistics'][] = array(631 'description' => 'Temporary table disk usage',632 'value' => $context['mysql_status']['Created_tmp_disk_tables']['value'] / max(1, $context['mysql_status']['Created_tmp_tables']['value']),633 'setting' => 'tmp_table_size',634 'max' => 0.5,635 );636 if (isset($context['mysql_status']['Sort_merge_passes'], $context['mysql_status']['Sort_rows']))637 $context['mysql_statistics'][] = array(638 'description' => 'Sort merge pass rate',639 'value' => $context['mysql_status']['Sort_merge_passes']['value'] / max(1, $context['mysql_status']['Sort_rows']['value']),640 'setting' => 'sort_buffer',641 'max' => 0.001,642 );643 $context['mysql_statistics'][] = array(644 'description' => 'Query cache enabled',645 'value' => !empty($context['mysql_variables']['query_cache_type']['value']) ? (int) ($context['mysql_variables']['query_cache_type']['value'] == 'ON') : 0,646 'setting' => 'query_cache_type',647 'min' => 1,648 'max' => 1,649 );650 if (isset($context['mysql_status']['Qcache_not_cached'], $context['mysql_status']['Com_select']))651 $context['mysql_statistics'][] = array(652 'description' => 'Query cache miss rate',653 'value' => 1 - $context['mysql_status']['Qcache_hits']['value'] / max(1, $context['mysql_status']['Com_select']['value'] + $context['mysql_status']['Qcache_hits']['value']),654 'setting' => 'query_cache_limit',655 'max' => 0.5,656 );657 if (isset($context['mysql_status']['Qcache_lowmem_prunes'], $context['mysql_status']['Com_select']))658 $context['mysql_statistics'][] = array(659 'description' => 'Query cache prune rate',660 'value' => $context['mysql_status']['Qcache_lowmem_prunes']['value'] / max(1, $context['mysql_status']['Com_select']['value']),661 'setting' => 'query_cache_size',662 'max' => 0.05,663 );664}665function generate_status()666{667 global $context, $command_line, $db_show_debug;668 $context['debug'] = empty($db_show_debug) ? false : true;669 show_header();670 if (strpos(strtolower(PHP_OS), 'win') === 0)671 get_windows_data();672 else673 get_linux_data();674 get_mysql_data();675 if ($command_line)676 {677 if (!empty($context['operating_system']['name']))678 echo 'Operating System: ', trim($context['operating_system']['name']), "\n";679 if (!empty($context['cpu_info']))680 echo 'Processor: ', trim($context['cpu_info']['model']), ' (', trim($context['cpu_info']['hz']), $context['cpu_info']['frequency'], ')', "\n";681 if ($context['debug'] && !empty($context['lastserverreboot']))682 echo 'Server Last Reboot: ', date(DATE_RSS, $context['lastserverreboot']), "\n";683 if (isset($context['load_averages']))684 echo 'Load averages: ', implode(', ', $context['load_averages']), "\n";685 if (!empty($context['running_processes']))686 echo 'Current processes: ', count($context['running_processes']), ' (', !empty($context['num_sleeping_processes']) ? $context['num_sleeping_processes'] . ' sleeping, ' : '', $context['num_running_processes'], ' running, ', $context['num_zombie_processes'], ' zombie)', "\n";687 if (!empty($context['top_cpu_usage']))688 {689 echo 'Processes by CPU: ';690 $temp = array();691 foreach ($context['top_cpu_usage'] as $proc)692 $temp[$proc['percent']] = $proc['name'] . ($proc['number'] > 1 ? ' (' . $proc['number'] . ') ' : ' ') . number_format($proc['percent'], 1) . '%';693 krsort($temp);694 echo implode(', ', $temp), "\n";695 }696 if (!empty($context['memory_usage']))697 echo 'Memory usage: ', round(($context['memory_usage']['used'] * 100) / $context['memory_usage']['total'], 3), '% (', $context['memory_usage']['used'], 'k / ', $context['memory_usage']['total'], 'k)', "\n";698 if (isset($context['memory_usage']['swap_used']))699 echo 'Swap usage: ', round(($context['memory_usage']['swap_used'] * 100) / max(1, $context['memory_usage']['swap_total']), 3), '% (', $context['memory_usage']['swap_used'], 'k / ', $context['memory_usage']['swap_total'], 'k)', "\n";700 if (!empty($context['mysql_processes']) || !empty($context['mysql_num_sleeping_processes']) || !empty($context['mysql_num_locked_processes']))701 echo 'MySQL processes: ', $context['mysql_num_running_processes'] + $context['mysql_num_locked_processes'] + $context['mysql_num_sleeping_processes'], ' (', $context['mysql_num_sleeping_processes'], ' sleeping, ', $context['mysql_num_running_processes'], ' running, ', $context['mysql_num_locked_processes'], ' locked)', "\n";702 if (!empty($context['mysql_statistics']))703 {704 echo "\n", 'MySQL statistics:', "\n";705 foreach ($context['mysql_statistics'] as $stat)706 {707 $warning = (isset($stat['max']) && $stat['value'] > $stat['max']) || (isset($stat['min']) && $stat['value'] < $stat['min']);708 $warning = $warning ? '(should be ' . (isset($stat['min']) ? '>= ' . $stat['min'] . ' ' : '') . (isset($stat['max'], $stat['min']) ? 'and ' : '') . (isset($stat['max']) ? '<= ' . $stat['max'] : '') . ')' : '';709 echo sprintf('%-34s%-6.6s %34s', $stat['description'] . ':', round($stat['value'], 4), $warning), "\n";710 }711 }712 return;713 }714 echo '715 <div class="panel">716 <h2>Basic Information</h2>717 <div class="righttext">', $context['current_time'], '</div>718 <table width="100%" cellpadding="2" cellspacing="0" border="0">';719 if (!empty($context['operating_system']['name']))720 echo '721 <tr>722 <th valign="top" style="text-align: left; width: 30%;">Operating System:</th>723 <td>', $context['operating_system']['name'], '</td>724 </tr>';725 if (!empty($context['cpu_info']))726 echo '727 <tr>728 <th valign="top" style="text-align: left; width: 30%;">Processor:</th>729 <td>', strtr($context['cpu_info']['model'], array('(R)' => '&reg;')), ' (', $context['cpu_info']['hz'], $context['cpu_info']['frequency'], ')</td>730 </tr>';731 if ($context['debug'] && !empty($context['lastserverreboot']))732 echo '733 <tr>734 <th valign="top" style="text-align: left; width: 30%;">Server Last Reboot:</th>735 <td>', date(DATE_RSS, $context['lastserverreboot']), '</td>736 </tr>';737 if (isset($context['load_averages']))738 echo '739 <tr>740 <th style="text-align: left; width: 30%;">Load averages:</th>741 <td>', implode(', ', $context['load_averages']), '</td>742 </tr>';743 if (!empty($context['running_processes']))744 echo '745 <tr>746 <th style="text-align: left; width: 30%;">Current processes:</th>747 <td>', count($context['running_processes']), ' (', !empty($context['num_sleeping_processes']) ? $context['num_sleeping_processes'] . ' sleeping, ' : '', $context['num_running_processes'], ' running, ', $context['num_zombie_processes'], ' zombie)</td>748 </tr>';749 if (!empty($context['top_cpu_usage']))750 {751 echo '752 <tr>753 <th style="text-align: left; width: 30%;">Processes by CPU:</th>754 <td>';755 $temp = array();756 foreach ($context['top_cpu_usage'] as $proc)757 $temp[$proc['percent']] = htmlspecialchars($proc['name']) . ' <em>(' . $proc['number'] . ')</em> ' . number_format($proc['percent'], 1) . '%';758 krsort($temp);759 echo implode(', ', $temp);760 echo '761 </td>762 </tr>';763 }764 if (!empty($context['memory_usage']))765 {766 echo '767 <tr>768 <th valign="top" style="text-align: left; width: 30%;">Memory usage:</th>769 <td>770 ', round(($context['memory_usage']['used'] * 100) / $context['memory_usage']['total'], 3), '% (', $context['memory_usage']['used'], 'k / ', $context['memory_usage']['total'], 'k)';771 if (isset($context['memory_usage']['swap_used']))772 echo '<br />773 Swap: ', round(($context['memory_usage']['swap_used'] * 100) / max(1, $context['memory_usage']['swap_total']), 3), '% (', $context['memory_usage']['swap_used'], 'k / ', $context['memory_usage']['swap_total'], 'k)';774 echo '775 </td>776 </tr>';777 }778 echo '779 </table>780 </div>';781 if (!empty($context['mysql_processes']) || !empty($context['mysql_num_sleeping_processes']) || !empty($context['mysql_num_locked_processes']))782 {783 echo '784 <div class="panel">785 <h2>MySQL processes</h2>786 <table width="100%" cellpadding="2" cellspacing="0" border="0">787 <tr>...

Full Screen

Full Screen

FileImportReport.php

Source:FileImportReport.php Github

copy

Full Screen

...42 private $runtime = 0;43 /**44 * @var int45 */46 private $memory_usage = 0;47 /**48 * @param Common\FileInterface $import_file49 * @param Data\MultiTypeIdListInterface $map50 * @param $blog_id51 * @param array $data {52 * Common\File $map_file,53 * DateTime $date,54 * int $runtime,55 * int $memory_usage,56 * string $name57 * }58 */59 public function __construct(60 Common\FileInterface $import_file,61 Data\MultiTypeIdListInterface $map,62 $blog_id,63 array $data = []64 ) {65 $this->import_file = $import_file;66 $this->map = $map;67 $this->blog_id = (int) $blog_id;68 $this->map_file = isset( $data[ 'map_file' ] )69 && is_a( $data[ 'map_file' ], 'W2M\Import\Common\File' )70 ? $data[ 'map_file' ]71 : NULL;72 $this->date = isset( $data[ 'date' ] )73 && is_a( $data[ 'date' ], 'DateTime' )74 ? $data[ 'date' ]75 : new DateTime;76 $this->runtime = isset( $data[ 'runtime' ] )77 ? (int) $data[ 'runtime' ]78 : 0;79 $this->memory_usage = isset( $data[ 'memory_usage' ] )80 ? (int) $data[ 'memory_usage' ]81 : 0;82 $this->name = isset( $data[ 'name' ] )83 ? (string) $data[ 'name' ]84 : '';85 }86 /**87 * @return Common\FileInterface The file with the import data88 */89 public function import_file() {90 return $this->import_file;91 }92 /**93 * @return Common\FileInterface|NULL The file that was used as id-map94 */95 public function map_file() {96 return $this->map_file;97 }98 /**99 * @return string100 */101 public function name() {102 return $this->name;103 }104 /**105 * @return DateTime106 */107 public function date() {108 return $this->date;109 }110 /**111 * @param DateTime $end (Optional, defines the end of the runtime relative to date() )112 *113 * @return int (Runtime in seconds)114 */115 public function runtime( DateTime $end = NULL ) {116 if ( $end ) {117 $this->runtime = $end->getTimestamp() - $this->date->getTimestamp();118 }119 return $this->runtime;120 }121 /**122 * @param int $memory_usage (Optional, sets the memory usage if provided)123 *124 * @return int (peak memory usage in byte)125 */126 public function memory_usage( $memory_usage = NULL ) {127 if ( ! is_null( $memory_usage ) ) {128 $this->memory_usage = (int) $memory_usage;129 }130 return $this->memory_usage;131 }132 /**133 * @param string $type (comment, post, term, user)134 *135 * @return array Associative list [ old_id => new_id ]136 */137 public function id_map( $type ) {138 return $this->map->id_map( $type );139 }140 /**141 * @return object142 */143 public function jsonSerialize() {144 /* @link https://secure.php.net/manual/en/function.memory-get-usage.php */145 $convert = function( $size ) {146 $unit = [ 'B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB' ];147 return round( $size / pow( 1024, ( $i = (int) floor( log( $size, 1024 ) ) ) ), 2 ) . ' ' . $unit[ $i ];148 };149 return (object) [150 'name' => $this->name(),151 'date' => $this->date()->format( DateTime::W3C ),152 'runtime' => "{$this->runtime()} s",153 'memory_usage' => $convert( $this->memory_usage() ),154 'import_file' => $this->import_file()->name(),155 'map_file' => $this->map_file() ? $this->map_file()->name() : '',156 'maps' => (object) [157 'comments' => (object) $this->id_map( 'comment' ),158 'posts' => (object) $this->id_map( 'post' ),159 'terms' => (object) $this->id_map( 'term' ),160 'users' => (object) $this->id_map( 'user' )161 ]162 ];163 }164}...

Full Screen

Full Screen

memory_usage

Using AI Code Generation

copy

Full Screen

1$mem = new memory_usage;2$mem->start();3$mem->stop();4$mem->output();5$mem = new memory_usage;6$mem->start();7$mem->stop();8$mem->output();9$mem = new memory_usage;10$mem->start();11$mem->stop();12$mem->output();13$mem = new memory_usage;14$mem->start();15$mem->stop();16$mem->output();

Full Screen

Full Screen

memory_usage

Using AI Code Generation

copy

Full Screen

1require_once('pts-core/pts-core.php');2$memory_usage = new memory_usage();3$memory_usage->start();4$memory_usage->stop();5$memory_usage->display();6require_once('pts-core/pts-core.php');7$memory_usage = new memory_usage();8$memory_usage->start();9$memory_usage->stop();10$memory_usage->display();11require_once('pts-core/pts-core.php');12$memory_usage = new memory_usage();13$memory_usage->start();14$memory_usage->stop();15$memory_usage->display();16require_once('pts-core/pts-core.php');17$memory_usage = new memory_usage();18$memory_usage->start();19$memory_usage->stop();20$memory_usage->display();21require_once('pts-core/pts-core.php');22$memory_usage = new memory_usage();23$memory_usage->start();24$memory_usage->stop();25$memory_usage->display();26require_once('pts-core/pts-core.php');27$memory_usage = new memory_usage();28$memory_usage->start();29$memory_usage->stop();30$memory_usage->display();31require_once('pts-core/pts-core.php');32$memory_usage = new memory_usage();33$memory_usage->start();34$memory_usage->stop();35$memory_usage->display();36require_once('pts-core/pts-core.php');37$memory_usage = new memory_usage();38$memory_usage->start();39$memory_usage->stop();40$memory_usage->display();

Full Screen

Full Screen

memory_usage

Using AI Code Generation

copy

Full Screen

1require_once('memory_usage.php');2$mem_usage = new memory_usage();3$mem_usage->start();4$mem_usage->end();5echo $mem_usage->get_usage();6require_once('memory_usage.php');7$mem_usage = new memory_usage();8$mem_usage->start();9$mem_usage->end();10echo $mem_usage->get_usage();11require_once('memory_usage.php');12$mem_usage = new memory_usage();13$mem_usage->start();14$mem_usage->end();15echo $mem_usage->get_usage();16require_once('memory_usage.php');17$mem_usage = new memory_usage();18$mem_usage->start();19$mem_usage->end();20echo $mem_usage->get_usage();21require_once('memory_usage.php');22$mem_usage = new memory_usage();23$mem_usage->start();24$mem_usage->end();25echo $mem_usage->get_usage();26require_once('memory_usage.php');27$mem_usage = new memory_usage();28$mem_usage->start();29$mem_usage->end();30echo $mem_usage->get_usage();31require_once('memory_usage.php');32$mem_usage = new memory_usage();33$mem_usage->start();34$mem_usage->end();

Full Screen

Full Screen

memory_usage

Using AI Code Generation

copy

Full Screen

1require_once('pts-core/pts-core.php');2$mem = new memory_usage();3$mem->start();4echo 'Memory Usage: ' . $mem->get_usage() . '5';6$mem->stop();

Full Screen

Full Screen

memory_usage

Using AI Code Generation

copy

Full Screen

1require_once('pts-core/objects/test_result_parser.php');2$mem = new memory_usage();3$memory_usage = $mem->get_memory_usage();4echo "Memory Usage: ".$memory_usage." bytes";5require_once('pts-core/objects/test_result_parser.php');6$mem = new memory_usage();7$memory_usage = $mem->get_memory_usage();8echo "Memory Usage: ".$memory_usage." bytes";9require_once('pts-core/objects/test_result_parser.php');10$mem = new memory_usage();11$memory_usage = $mem->get_memory_usage();12echo "Memory Usage: ".$memory_usage." bytes";

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phoronix-test-suite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in memory_usage

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful