VAS monitoring functions
Jul 19, 2015 13:31:11 GMT
Post by MarkH on Jul 19, 2015 13:31:11 GMT
Here are some simple Lua functions I have found useful for debugging OOMs in FSX. You can get a continuous on-screen display of used / free memory or a pop-up one, depending on which you prefer. (The pop-up one is better as the continuous one makes my FSX display glitchy.) It works in full-screen mode as well as windowed mode. You will need a registered FSUIPC to do this.
Instructions:
(1) Put the following code block in a file named 'vasmonitor.lua' and save it to your FSX\modules folder.
(2) Add the two lines shown in the initial comment to FSUIPC4.ini.
You should now have a small window at the upper left of the screen that shows used/free memory and is updated every 10 seconds. You can change the position of the window by amending the 'ipc.setdisplay' line.
If you prefer a pop-up version rather than a continuous display, you can use the following two functions instead. This has two files.
Instructions:
(1) Put the first block in a file named 'showvas.lua'.
(2) Put the second block in a file named 'hidevas.lua'.
(3) Save both files in your FSX\modules folder.
(4) In the FSUIPC 'buttons and switches' dialog, set the DOWN action of a free button to 'Lua Showvas' and the corresponding UP action to 'Lua Hidevas'.
Now you should get a window with the used/free memory in it while you hold the buttton down. You can change the position of the window by amending the 'ipc.setowndisplay' line. (Note that the position works differently than 'ipc.setdisplay'. You could use ipc.setdisplay instead if you wanted to.)
showvas.lua
hidevas.lua
Instructions:
(1) Put the following code block in a file named 'vasmonitor.lua' and save it to your FSX\modules folder.
(2) Add the two lines shown in the initial comment to FSUIPC4.ini.
You should now have a small window at the upper left of the screen that shows used/free memory and is updated every 10 seconds. You can change the position of the window by amending the 'ipc.setdisplay' line.
-- Free / used memory monitor for FSX
-- by MarkH, from an idea posted by 'Gypsy Baron' in the FSUIPC forums.
--
-- Make sure you put the following in FSUIPC4.ini:
--
-- [Auto]
-- 1=Lua KillAll
-- 2=Lua ShowMem
local function Round(nVal)
return math.floor(nVal + 0.5)
end
function ShowMem(MemOffset, FreeMem)
-- This function is invoked whenever the FSUIPC-maintained record of
-- how much memory remains available to FSX changes. The value is updated
-- every 10 seconds, hence this function is invoked at most once every ten
-- seconds.
--
-- The FreeMem parameter is the updated value. MemOffset is the FSUIPC-maintained
-- offset from where it was read. (We don't need the offset here.)
local MaxMem = 2^32 / 1024 -- Size of FSX virtual address space in kilobytes
local UsedMem = MaxMem - FreeMem -- Figure out how much memory is currently being used
ipc.setdisplay(0, 60, 200, 30) -- x, y, width, height of display window in pixels.
ipc.display("Mem Used/Remaining:\n" .. Round(UsedMem / 1000) .. " / " .. Round(FreeMem / 1000) .. " KB x 1000")
end
-- Install our function as an event handler to be called whenever the
-- free memory value is updated.
local FreeMemOffset = 0x024C
event.offset(FreeMemOffset,"UD","ShowMem")
If you prefer a pop-up version rather than a continuous display, you can use the following two functions instead. This has two files.
Instructions:
(1) Put the first block in a file named 'showvas.lua'.
(2) Put the second block in a file named 'hidevas.lua'.
(3) Save both files in your FSX\modules folder.
(4) In the FSUIPC 'buttons and switches' dialog, set the DOWN action of a free button to 'Lua Showvas' and the corresponding UP action to 'Lua Hidevas'.
Now you should get a window with the used/free memory in it while you hold the buttton down. You can change the position of the window by amending the 'ipc.setowndisplay' line. (Note that the position works differently than 'ipc.setdisplay'. You could use ipc.setdisplay instead if you wanted to.)
showvas.lua
-- Free / used memory monitor for FSX
-- by MarkH
--
-- REQUIRES
--
-- showvas.lua (this file)
-- hidevas.lua
--
-- Put these two files in your FSX/modules folder.
--
-- This displays a window showing the amount of memory currently in use by FSX and
-- the amount remaining. The window is removed by calling the complementary program
-- 'hidevas'.
--
-- The two programs will appear in the list of FSX functions available to be mapped to
-- keys in FSUIPC's 'buttons and switches' dialog. They will appear as 'Lua Showvas' and
-- 'Lua Hidevas' unless you have renamed the files. I suggest you map 'Lua Showvas' to
-- a button-down event and 'Lua Hidevas' to the corresponding button-up event, so the
-- display is only shown while you hold the button down.
local function Round(nVal)
return math.floor(nVal + 0.5)
end
local MaxMem = 2^32 / 1024 -- Size of FSX virtual address space in kilobytes
ipc.setowndisplay("Mem Used / Remaining", 47.5, 0, 5, 2.5) -- Title, x, y, width and height (as % of display width and height).
ipc.set("VASWindow", 1) -- A global ipc variable we've invented to maintain the window state
-- Now we sit in a loop reading and displaying the values until our global
-- flag gets reset, typically by the button-up action.
local FreeMemOffset = 0x024C
repeat
local FreeMem = ipc.readUD(FreeMemOffset)
local UsedMem = MaxMem - FreeMem
ipc.display(Round(UsedMem / 1000) .. " / " .. Round(FreeMem / 1000) .. " KB x 1000")
ipc.sleep(200) -- Milliseconds
until ipc.get("VASWindow") == 0
hidevas.lua
-- Free / used memory monitor for FSX
-- by MarkH
--
-- REQUIRES
--
-- showvas.lua
-- hidevas.lua (this file)
--
-- Put these two files in your FSX/modules folder.
-- This resets the ipc global variable to show that we want to close the window.
-- The main program sits in a loop updating the window and watching this flag.
ipc.set("VASWindow", 0)