App RAM usage

Post

Posted
Rating:
#1 (In Topic #1504)
Regular
rj71 is in the usergroup ‘Regular’
 When you launch your app from the Gambas IDE, the IDE shows you how much RAM your app is using. Is it possible to implement something like this in an app without using Shell? I have my movies app that loads lots of images and would be handy to keep tabs on how much RAM it's using. I thought it might be with gb.application or gb.system but I don't see anything relevant. If Shell is the only option then I can figure that out myself, just thought there might be something I haven't discovered. Thanks!
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’

rj71 said

When you launch your <COLOR color="#80BF00">app</COLOR> from the Gambas IDE, the IDE shows you how much RAM your <COLOR color="#80BF00">app</COLOR> is using.

What? How? Where? Who?  :)  :?:

I don't think there is anything apart from an instantaneous memory map dump that could tell you how much physical memory your <COLOR color="#FF0000">APPLICATION</COLOR>  :x is using. And why would you care? That's what the OS is there for.
Memory usage reporting is a vague and mystical art practiced by the Unseen University and never published in a way that mortals could possibly understand.

I think if you are worried about how much something-or-other your application is using, as you described as "lots of images", then you should be more interested in how much file buffer space is being consumed by the process as they are loaded.

Some idea of this can be got from the buff/cache column reported by free -h. But also refer to ulimit -a to check what levels of resources are being allowed by your kernel.

I had a bit of a look through the IDE code to see if I could find what it is reporting in that little bar at the top of the debugger panel but gave up. So I can't even tell you what it thinks it's saying.

SO, in short, not to put a fine point on it, in summation, no there is no quick solution.
 :cry:
b

Online now: No Back to the top

Post

Posted
Rating:
#3
Banned
Nah, Gambas does not have a way but there is a way with shell.

Code

ps -o %cpu,%mem -p <pid>


Code (gambas)

  1. Shell "ps --no-header -o %cpu,%mem -p " & Application.ID To sResult
  2.  
2.3  0.6

check out the source for GambasProcWatch
Bruce Steers / gambasprocwatch · GitLab

it show mem and CPU usage of all running gambas programs using ps.
Online now: No Back to the top

Post

Posted
Rating:
#4
Banned
PS. This is how the gambas IDE does it while debugging.
In Design.module / Public Sub TimerWatch_Timer()
(it uses the Pss field of the file called smaps_rollup in /proc/<pid>)

Code (gambas)

  1.   sDir = "/proc" &/ CStr(ProcessId)
  2.   If Not IsDir(sDir) Then
  3.     $hTimerWatch.Stop
  4.     Return
  5.  
  6.   Try ProcessFiles = Dir(sDir &/ "fd").Count
  7.   If Error Then ProcessFiles = -1
  8.  
  9.   ProcessMemory = 0
  10.   Try aMaps = Split(Trim(File.Load(sDir &/ "smaps_rollup")), "\n")
  11.   If aMaps Then
  12.     For Each sMap In aMaps
  13.       If sMap Begins "Pss:" Then
  14.         sMap = LTrim(Mid$(sMap, 5))
  15.         iPos = InStr(sMap, " ")
  16.         ProcessMemory = CLong(Left(sMap, iPos - 1)) * 1024
  17.         Break
  18.       Endif
  19.     Next
  20.  
  21.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
rj71 is in the usergroup ‘Regular’
I thought it was pretty cool how the IDE could show you that. Thanks guys!
Online now: No Back to the top
1 guest and 0 members have just viewed this.