logo       

CVS: phpwiki/lib stdlib.php,1.229,1.230: msg#00146

web.wiki.phpwiki.checkins

Subject: CVS: phpwiki/lib stdlib.php,1.229,1.230

Update of /cvsroot/phpwiki/phpwiki/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31374/lib

Modified Files:
stdlib.php
Log Message:
add getMemoryUsage to stdlib

Index: stdlib.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/stdlib.php,v
retrieving revision 1.229
retrieving revision 1.230
diff -u -2 -b -p -d -r1.229 -r1.230
--- stdlib.php 21 Jan 2005 11:51:22 -0000 1.229
+++ stdlib.php 25 Jan 2005 07:10:51 -0000 1.230
@@ -1882,5 +1882,39 @@ function printSimpleTrace($bt) {
}

+/**
+ * Return the used process memory (in byte?)
+ * Enable the section which will work for you. (They are very slow)
+ * Special quirks for Windows: Requires cygwin.
+ */
+function getMemoryUsage() {
+ if (function_exists('memory_get_usage') and memory_get_usage()) {
+ return memory_get_usage();
+// } elseif (function_exists('getrusage') and ($u = getrusage()) and
!empty($u['ru_maxrss'])) {
+// $mem = $u['ru_maxrss'];
+ } elseif (1 and substr(PHP_OS,0,3) == 'WIN') { // requires a newer cygwin
+ // what we want is the process memory only: apache or php
+ $pid = getmypid();
+ // This works only if it's a cygwin process (apache or php)
+ //$mem = (integer) trim(exec("cat /proc/$pid/statm |cut -f1"));
+ // if it's native windows use something like this:
+ // (requires pslist from sysinternals.com)
+ $memstr = exec("pslist $pid|grep -A1 Mem|sed 1d|perl -ane\"print
\$"."F[5]\"");
+ return (integer) trim($memstr);
+ } elseif (0) {
+ $pid = getmypid();
+ //%MEM: Percentage of total memory in use by this process
+ //VSZ: Total virtual memory size, in 1K blocks.
+ //RSS: Real Set Size, the actual amount of physical memory allocated
to this process.
+ //CPU time used by process since it started.
+ //echo "%",`ps -o%mem,vsz,rss,time -p $pid|sed 1d`,"\n";
+ $memstr = exec("ps -orss -p $pid|sed 1d");
+ return (integer) trim($memstr);
+ }
+}
+
// $Log$
+// Revision 1.230 2005/01/25 07:10:51 rurban
+// add getMemoryUsage to stdlib
+//
// Revision 1.229 2005/01/21 11:51:22 rurban
// changed (c)



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise