Re: Memory and CPU Usage Script

2014-06-15 Thread Mark Wieder
Richard-

Thursday, June 12, 2014, 3:45:55 PM, you wrote:

 http://osxbook.com/book/bonus/ancient/procfs/

That's a dead link, and even osxbook.com just returns Hello.

I treasure my hardcopy of that book, and apparently there's an updated
version in the works. Serious geeky wonderfulness for anyone willing
do dive that deep, but definitely in need of an upgrade: a lot has
changed since 2006.

http://blog.darkrainfall.org/2013/01/os-x-internals/

For now, check out the sysctl commands:

https://superuser.com/questions/631693/where-is-the-proc-folder-on-mac-os-x

-- 
-Mark Wieder
 ahsoftw...@gmail.com

This communication may be unlawfully collected and stored by the National 
Security Agency (NSA) in secret. The parties to this email do not 
consent to the retrieving or storing of this communication and any 
related metadata, as well as printing, copying, re-transmitting, 
disseminating, or otherwise using it. If you believe you have received 
this communication in error, please delete it immediately.


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-12 Thread J. Landman Gay

On 6/6/2014, 7:33 PM, Richard Gaskin wrote:


But even more fun, you can take a trip back to 1997 to read Scott
Raney's article in Linux Journal about using LiveCode (back then called
MetaCard) to build a GUI for top:
http://porky.linuxjournal.com:8080/LJ/043/2110.html


This looked pretty cool so I recreated his stack. I think Mavericks 
stores the file somewhere else because the scripts ran just fine but I 
got no data back.


If anyone knows where Mavericks put the file, I'd like to try it. As-is, 
it's looking for /proc/stat and there is no proc folder in OS X.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-12 Thread Richard Gaskin

J. Landman Gay wrote:


On 6/6/2014, 7:33 PM, Richard Gaskin wrote:


But even more fun, you can take a trip back to 1997 to read Scott
Raney's article in Linux Journal about using LiveCode (back then called
MetaCard) to build a GUI for top:
http://porky.linuxjournal.com:8080/LJ/043/2110.html


This looked pretty cool so I recreated his stack. I think Mavericks
stores the file somewhere else because the scripts ran just fine but I
got no data back.

If anyone knows where Mavericks put the file, I'd like to try it. As-is,
it's looking for /proc/stat and there is no proc folder in OS X.


One nice thing about Unix/Linux is that everything is setup to appear as 
a file, so piping and other goodies work together nicely.


One tricky thing about Unix/Linux is that not everything that appears to 
be a file is actually a file. :)


/proc is a virtual file system containing system info (processes). 
It's more akin to an associative array than a directory tree.


Handy as it is, not all *nixes support it - this site explains more, 
with some suggestions of OS X alternatives to some /proc info:


http://osxbook.com/book/bonus/ancient/procfs/

--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-12 Thread J. Landman Gay

On 6/12/2014, 5:45 PM, Richard Gaskin wrote:


Handy as it is, not all *nixes support it - this site explains more,
with some suggestions of OS X alternatives to some /proc info:

http://osxbook.com/book/bonus/ancient/procfs/



Thanks, but this would be way more work than the simple example I was 
trying to build, so until I become proficient with *nix I think I'll let 
this go. I'd have to study for days before I could even understand what 
that web page is saying. I'll just put my little stack into a pending 
folder for now.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Memory and CPU Usage Script

2014-06-06 Thread Kay C Lan
For the first time, on OS X, I ran out of memory. Whilst Activity
Monitor is good, it doesn’t really give you a way to log memory usage
and trace areas that may be causing concern. So I googled the problem
and discovered a LOT of answers involving php,ruby,awk,grep,pipes and
a bunch of other stuff that suggested I could roll my own with LC. So
at the bottom you’ll find a script that will output* some nice tab
formatted memory and CPU info:

Physical Memory = 16 GB
  Free   Active Inactive  Spec.   Wired  Page InPage Out
 2.16 GB 2.64 GB 0.79 GB 9.08 GB 1.32 GB  236138   0
 Application   Time  % CPU% Mem  Real  Virtual
Dock  0:17.13  0.0  1.7 0.27 GB 2.71 GB
   LiveCode661GM105:56.16 15.7  1.4 0.22 GB 0.97 GB
  WebContent  1:05.35  0.0  1.1 0.17 GB 4.01 GB
   IconServicesAgent  0:04.12  0.0  1.0 0.16 GB 2.55 GB
 Dropbox  0:35.55  0.0  0.581.09 MB 0.98 GB
  BBEdit101:41.12  0.0  0.466.02 MB 1.11 GB
 ManOpen  0:18.63  0.0  0.228.92 MB 2.49 GB
  RegExhibit  0:53.09  0.0  0.227.37 MB 0.73 GB
  BBEdit  0:00.09  0.0  0.0 1.73 MB 0.66 GB

Currently you’ll note that my script is a switch structure with a
single case for OS X. Win and Linux users may wish to add appropriate
code to make this work for them.

*The output above isn’t exactly what you’ll get from the script below.
In my case, all my development tools live in a folder cryptically
called ‘Development’, so I have some extra code that filters the ps
output to the top 5 most % memory + all the running development apps.
Any duplicates are removed. It will be noted that there are two
records for BBEdit, but they are different, one is the program itself
and the other is it’s crash reporter.

For the curious: BBEdit is what I feed my log files into; ManOpen is a
man page reader where I found the options for id and ps; RegExhibit is
what I use to build and test regex entries for matchText etc.

Known errors: if an app's Time exceeds 999:99.9 mins it will not be Listed

!! be careful of line breaks, there's a very long regex entry for matchText() !!
SCRIPTSCRIPTSCRIPTSCRIPT

switch (the platform)
  case (MacOS)
 --get the system physical memory
 put shell(sysctl -n hw.memsize) into tData
 put round(tData/1024/1024/1024,1) into tPhyMem
 --memory titles
 put Physical Memory =   tPhyMem   GB  crFree  
 tab   Active   tab  Inactive  tabSpec.   tab  \
 Wired   tab   Page In  tab  Page Out  cr
into tOutput

 --get the virtual memory
 put shell(vm_stat) into tData

 put (word -2 of line 1 of tData)/1024/1024 into tPage
 put char 1 to -2 of word -1 of line 2 of tData * tPage into tFree
 put char 1 to -2 of word -1 of line 3 of tData * tPage into tActive
 put char 1 to -2 of word -1 of line 4 of tData * tPage into tInactive
 put char 1 to -2 of word -1 of line 5 of tData * tPage into tSpec
 put char 1 to -2 of word -1 of line 7 of tData * tPage into tWire
 put char 1 to -2 of word -1 of line 20 of tData into tPageIn
 put char 1 to -2 of word -1 of line 21 of tData  into tPageOut

 if (tFree  99) then --we want the number in GB
put format(%5.2f,tFree/1024)   GB  tab after tOutput
 else --we want the numbers in MB
put format(%5.2f,tFree)   MB  tab after tOutput
 end if
 if (tActive  99) then --we want the number in GB
put format(%5.2f,tActive/1024)   GB  tab after tOutput
 else --we want the numbers in MB
put round(tActive,2)   MB  tab after tOutput
 end if
 if (tInactive  99) then --we want the number in GB
put format(%5.2f,tInactive/1024)   GB  tab after tOutput
 else --we want the numbers in MB
put format(%5.2f,tInactive)   MB  tab after tOutput
 end if
 if (tSpec  99) then --we want the number in GB
put format(%5.2f,tSpec/1024)   GB  tab after tOutput
 else --we want the numbers in MB
put format(%5.2f,tSpec)   MB  tab after tOutput
 end if
 if (tWire  99) then --we want the number in GB
put format(%5.2f,tWire/1024)   GB  tab after tOutput
 else --we want the numbers in MB
put format(%5.2f,tWire)   MB  tab after tOutput
 end if
 put format(%8s,tPageIn)  tab  format(%8s,tPageOut)  cr
after tOutput


 --virtual memory titles
 put  Application  tab Timetab  %
CPU  tab  % Mem  tabRealtab  Virtual  cr after
tOutput

 --gets the current logged in users UID (normally 501)
 put shell(id -u) 

Re: Memory and CPU Usage Script

2014-06-06 Thread Earthednet-wp
Kay,
Thanks for that. It may come in handy some time.
Bill

William Prothero
http://es.earthednet.org

 On Jun 6, 2014, at 4:38 AM, Kay C Lan lan.kc.macm...@gmail.com wrote:
 
 For the first time, on OS X, I ran out of memory. Whilst Activity
 Monitor is good, it doesn’t really give you a way to log memory usage
 and trace areas that may be causing concern. So I googled the problem
 and discovered a LOT of answers involving php,ruby,awk,grep,pipes and
 a bunch of other stuff that suggested I could roll my own with LC. So
 at the bottom you’ll find a script that will output* some nice tab
 formatted memory and CPU info:

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Memory and CPU Usage Script

2014-06-06 Thread Mark Wieder
Kay C Lan lan.kc.macmail@... writes:

 at the bottom you’ll find a script that will output* some nice tab
 formatted memory and CPU info:

Nice, but top didn't give you what you were looking for?

-- 
 Mark Wieder
 ahsoftw...@gmail.com



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Memory and CPU Usage Script

2014-06-06 Thread Kay C Lan
On Sat, Jun 7, 2014 at 2:21 AM, Mark Wieder mwie...@ahsoftware.net wrote:

 Nice, but top didn't give you what you were looking for?

I noticed in my search that people reported top as being quite CPU
intensive and in my own tests it went to No2, just below LC when I was
running my stacks; so a bit chicken and egg, I wanted to know what was
using my memory and CPU and using top was always going to place itself
in the list.  This is understandable as top is active whilst the id,
ps, and vm_stat are all static, but I notice that even Activity
Monitor with all it's bells and whistles uses significantly less CPU
than top.

Plus, it was more of an exercise to see if I could reinvent the wheel
and build something similar in LC that could be customised to report
exactly what I was interested in, when I was interested in it, no
more, no less. Hopefully it will provide a stepping off point for
others to adjust the output to exactly meet their needs.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-06 Thread Richard Gaskin

Kay C Lan wrote:

 I wanted to know what was using my memory and CPU and using top
 was always going to place itself in the list.  This is understandable
 as top is active whilst the id, ps, and vm_stat are all static, but I
 notice that even Activity Monitor with all it's bells and whistles
 uses significantly less CPU than top.

You can run top just once with:

top -bn1

But even more fun, you can take a trip back to 1997 to read Scott 
Raney's article in Linux Journal about using LiveCode (back then called 
MetaCard) to build a GUI for top:

http://porky.linuxjournal.com:8080/LJ/043/2110.html

--
 Richard Gaskin
 Fourth World
 LiveCode training and consulting: http://www.fourthworld.com
 Webzine for LiveCode developers: http://www.LiveCodeJournal.com
 Follow me on Twitter:  http://twitter.com/FourthWorldSys

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-06 Thread Kay C Lan
Thanks Richard, I strangely feel chuffed about the fact that I'm
reinventing a wheel already built by the legendary Man himself. I
might have to look into a few more of the top options: -bn1 didn't
work on my 10.9.3 but clearly there must be an OS X equivalent.

On Sat, Jun 7, 2014 at 8:33 AM, Richard Gaskin
ambassa...@fourthworld.com wrote:
 Kay C Lan wrote:

 I wanted to know what was using my memory and CPU and using top
 was always going to place itself in the list.  This is understandable
 as top is active whilst the id, ps, and vm_stat are all static, but I
 notice that even Activity Monitor with all it's bells and whistles
 uses significantly less CPU than top.

 You can run top just once with:

 top -bn1

 But even more fun, you can take a trip back to 1997 to read Scott Raney's
 article in Linux Journal about using LiveCode (back then called MetaCard)
 to build a GUI for top:
 http://porky.linuxjournal.com:8080/LJ/043/2110.html

 --
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  Follow me on Twitter:  http://twitter.com/FourthWorldSys


 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-06 Thread Richard Gaskin

Kay C Lan wrote:

 Thanks Richard, I strangely feel chuffed about the fact that I'm
 reinventing a wheel already built by the legendary Man himself.

Au contraire:  I consider it one of those great GMTA moments - at least 
you're in good company. :)


Besides, your layout bested top's - not bad.


 I might have to look into a few more of the top options: -bn1
 didn't work on my 10.9.3 but clearly there must be an OS X
 equivalent.

Yeah, there are just enough differences between OS X and Linux that it 
can get annoying jumping between them all day (worse if you need the 
latest, most secure versions of things like Apache and rsync - OS X 
ships with some surprisingly old stuff) - I think this is the OS X version:


top -l1

--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for Desktop, Mobile, and Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-06 Thread Mark Wieder
Richard-

Friday, June 6, 2014, 8:25:19 PM, you wrote:

 OS X ships with some surprisingly old stuff

homebrew

-- 
-Mark Wieder
 ahsoftw...@gmail.com

This communication may be unlawfully collected and stored by the National 
Security Agency (NSA) in secret. The parties to this email do not 
consent to the retrieving or storing of this communication and any 
related metadata, as well as printing, copying, re-transmitting, 
disseminating, or otherwise using it. If you believe you have received 
this communication in error, please delete it immediately.


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-06 Thread Mark Wieder
Kay-

Friday, June 6, 2014, 5:19:10 PM, you wrote:

 I noticed in my search that people reported top as being quite CPU
 intensive and in my own tests it went to No2, just below LC when I was
 running my stacks; so a bit chicken and egg, I wanted to know what was
 using my memory and CPU and using top was always going to place itself
 in the list.  This is understandable as top is active whilst the id,
 ps, and vm_stat are all static, but I notice that even Activity
 Monitor with all it's bells and whistles uses significantly less CPU
 than top.

OK. That makes sense. Top is cpu-intensive, and has to be in order to
do what it does. I don't think it's a memory hog, though, and I
thought that was what you were concerned with in the first place,
since you posted that you ran out of memory.

 Plus, it was more of an exercise to see if I could reinvent the wheel
 and build something similar in LC that could be customised to report
 exactly what I was interested in, when I was interested in it, no
 more, no less. Hopefully it will provide a stepping off point for
 others to adjust the output to exactly meet their needs.

Yes, thanks for posting it. It's quite nicely done.

-- 
-Mark Wieder
 ahsoftw...@gmail.com

This communication may be unlawfully collected and stored by the National 
Security Agency (NSA) in secret. The parties to this email do not 
consent to the retrieving or storing of this communication and any 
related metadata, as well as printing, copying, re-transmitting, 
disseminating, or otherwise using it. If you believe you have received 
this communication in error, please delete it immediately.


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Memory and CPU Usage Script

2014-06-06 Thread Richard Gaskin

Mark Wieder wrote:

 Richard-

 Friday, June 6, 2014, 8:25:19 PM, you wrote:

 OS X ships with some surprisingly old stuff

 homebrew

Homebrew is a great solution for people like you and me, but for most 
Mac customers Apple hasn't been forthcoming about how outdated and 
vulnerable many system components are, any more than they've let the 19% 
of Mac users still depending on Snow Leopard know that they're not 
getting any more critical security updates at all.


For a company whose marketing message frequently devolves into random 
jabs against other systems' security (often unfounded), I'm surprised 
Cook has let the situation with their own products continue in this 
cavalier way so long.  I had always seen Cook as the cool-headed 
long-term thinker


--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for Desktop, Mobile, and Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode