Jump to content

[1.0.2] Sentinel Memory Monitoring Utility (v0.3 Beta)


Zeenobit

Recommended Posts

Sentinel Memory Monitoring Utility

Version 0.3 Beta for KSP 1.0.2

Brought to you by the Kerbal Space Exploration Agency:

L7rpnwm.png

This lightweight utility mod simply monitors your KSP memory usage and if it crosses pre-defined percentages, it slaps a warning text on your screen. This way you can save your progress and restart KSP, or do anything else you need to do before KSP just gives up and ruins your perfect rescue mission.

Inspired by GCMonitor, which is a much more elaborate tool (and definitely recommended if you're looking for a more elaborate memory monitoring utility), Sentinel also uses the same native library to grab the KSP process memory usage. All credit goes to sarbian and the original author for this method.

The differences between Sentinel and GCMonitor are:

  • Sentinel is much more lightweight without any additional changes other than the warning messages.
  • Sentinel is also a developers tool that can notify other plugins when memory limits are being reached.

Please do keep in mind that this mod is not currently compatible with GCMonitor. You can have one or the other, not both.

Download: <Link snipped pending source availability>

License: GNU General Public License

Sentinel Version 0.3 Beta

  • Full re-write of the code for a more data-driven approach
  • Custom situation support
  • Automatic game pause support during flight
  • Custom notification settings
  • Settings file version tracking
  • Launcher button to suppress notifications and indicate situation

Installation:

  1. Download the zip file from the link above
  2. Unzip the contents into your KSP installation directory

Notification Mechanism

Javascript is disabled. View full album

In order to notify players when they should prepare for exceeding the memory limit, Sentinel can warn the user when they approach pre-defined situations. By default, Sentinel has two situations: Distressed (usage over 70%), and Critical (usage over 80%). You can define custom situations or tweak existing ones using the settings file.

When memory usage is over the situation percentage value, depending on the situation configuration, Sentinel performs various actions. These actions may include showing a notification text or pausing the game while in flight.

The settings file is located in GameData\KSEA\Sentinel\Sentinel.cfg.

Events

Sentinel is designed to allow other mod developers to easy perform tasks when memory usage reaches player-defined levels. For example, a plugin could perform any last minute saves and prepare for a shutdown or free up unnecessary resources to lower memory usage.

In order to listen to Sentinel memory events, you must first reference GameData/KSEA/Sentinel/Sentinel.dll in your project. Then, listening to the event is simply a matter of registering a delegate to the KSEA.Sentinel.OnSituation event.

Example:

using UnityEngine;
using KSEA;


namespace Sample
{
public class Sample
{
public Sample()
{
Sentinel.OnSituation += Sentinel_OnSituation;
}


private void Sentinel_OnSituation(Sentinel.Situation situation)
{
// ...
}
}
}

Planned Features:

  • Potentially a GUI configuration interface, although that might go against the intended design of this mod being lightweight.
  • Compatibility with GCMonitor

Disclaimer: This is my first mod, and I'm hoping to help the community as best as I can, because without the modding community, KSP means very little to me. It is more of a learning experience rather than the next hit mod. Any feedback would be much appreciated, and use it at your own risk. :P

Edited by Red Iron Crown
Link to comment
Share on other sites

This will be very useful, congratulations. The new KSP uses much less memory, so it's easy to add more and more mods until it becomes unplayable.

Thank you! :)

Version 0.2 Uploaded (Check OP for Download):

  • Adjusted the notification text to be less verbose and more noticeable
  • Changed default refresh period to 1 second
  • Added to KerbalStuff

Link to comment
Share on other sites

Ok, I tried hit, and it works as said. If I can suggest something, it will be good to stop the message of warning if willed. I received the Critical Warning and I finished my mission (dock, transfer crew and re-entry on Kerbin from LKO) with the red message in the center of my screen. When it was displayed at first, I made a Quicksave but was unable a way to hide the message.

Btw, very good work!

Link to comment
Share on other sites

Ok, I tried hit, and it works as said. If I can suggest something, it will be good to stop the message of warning if willed. I received the Critical Warning and I finished my mission (dock, transfer crew and re-entry on Kerbin from LKO) with the red message in the center of my screen. When it was displayed at first, I made a Quicksave but was unable a way to hide the message.

Btw, very good work!

That's a good idea. Although I want to avoid having any GUI elements to make it as minimal as possible. I'll see if I can work in a customization shortcut key to disable it.

Link to comment
Share on other sites

It might be good to have an option for message position. Middle of the screen is attention grabbing but a little annoying. A good place for it would be near the top of the screen just below the gauges, that way its out of your main view and still super visible.

Link to comment
Share on other sites

I have been using this mod today for a number of hours.. and I think it might have its own memory leak. I was hitting up to 3.5GB usage (Task Manager) with it.. and tended to hover around 2.7GB to 3GB without it. Same mods, same career path with same ships.

Could just be my setup. If you need any logs etc. I could probably send it to you.. but I am not using your addon atm.

Excellent and most wanted mod of course. :D

Link to comment
Share on other sites

Maybe an icon on the stock toolbar that appears on alarm on. You click on hit and disable the warning message.

I might try that. I'm thinking of having the text message show up, but then changing the color of the toolbar icon to indicate the situation after you dismiss the text.

It might be good to have an option for message position. Middle of the screen is attention grabbing but a little annoying. A good place for it would be near the top of the screen just below the gauges, that way its out of your main view and still super visible.

That's on my To Do list already. I'm thinking making it configurable with 33% from the top of the screen by default.

I have been using this mod today for a number of hours.. and I think it might have its own memory leak. I was hitting up to 3.5GB usage (Task Manager) with it.. and tended to hover around 2.7GB to 3GB without it. Same mods, same career path with same ships.

Could just be my setup. If you need any logs etc. I could probably send it to you.. but I am not using your addon atm.

Excellent and most wanted mod of course. :D

I'm not quite sure how this is possible since the mod does next-to-nothing until the memory usage crosses the limits. Even if it does leak, the leak wouldn't be noticeable at all, let alone 0.5 GB. I'll investigate it before the next update, but did you get this behavior consistently with multiple tries?

Link to comment
Share on other sites

I'm not quite sure how this is possible since the mod does next-to-nothing until the memory usage crosses the limits. Even if it does leak, the leak wouldn't be noticeable at all, let alone 0.5 GB. I'll investigate it before the next update, but did you get this behavior consistently with multiple tries?

Unfortunately yes.. I got it with multiple tries until I removed it.. and then my memory stayed down. Again, could be an interaction of another addon and this, but the problem did resolve after I removed Sentinel. If you would like I could share (privately) my GameData and Career Save I was using for your testing.

Link to comment
Share on other sites

Unfortunately yes.. I got it with multiple tries until I removed it.. and then my memory stayed down. Again, could be an interaction of another addon and this, but the problem did resolve after I removed Sentinel. If you would like I could share (privately) my GameData and Career Save I was using for your testing.

Sure. PM me with what you can. So far, I can't reproduce this leak on my end.

Link to comment
Share on other sites

Version 0.3 Beta Uploaded. Click the link in OP to download.

  • Full re-write of the code for a more data-driven approach
  • Custom situation support
  • Automatic game pause support during flight
  • Custom notification settings
  • Settings file version tracking
  • Launcher button to suppress notifications and indicate situation

I haven't been able to reproduce any memory leak issues so far. So nothing to fix on that front! :)

Link to comment
Share on other sites

Version 0.3 Beta Uploaded. Click the link in OP to download.

  • Full re-write of the code for a more data-driven approach
  • Custom situation support
  • Automatic game pause support during flight
  • Custom notification settings
  • Settings file version tracking
  • Launcher button to suppress notifications and indicate situation

I haven't been able to reproduce any memory leak issues so far. So nothing to fix on that front! :)

Thanks. I have been messing around with addons.. again... and will try this version out. Let you know if I discover anything new.. Chances are it was just a fluke on my side with one of the other addons. Unfortunate that we cannot get a detailed list of memory usage.

Link to comment
Share on other sites

Quick Update.

It appears that the heat gauges and "science alert" have memory leaks. This is probably what I was seeing and not your addon. Maybe I was just doing slightly different things that was causing it when I was playing with and without your addon.

Just thought you should know.

Cheers

Link to comment
Share on other sites

Any chance you can implement the ability to have it do an automatic quicksave if you are in flight and in a situation where you can quick save? I really like the configure ability of this and having this option as well as the pause option would be great!

Link to comment
Share on other sites

Nice mod, I've experimented with an old ram optimizer and whenever Sentinel changes in the yellow alert, I push a hotkey and the optimizer (RAMRush) does its job and bring Sentinel back in white safety. No yellow or red warnings anymore! No crashes, stable for a few hours with 70% of RAM during the start KSP and after the clean-up RAM of less than 70% for hours.

Link to comment
Share on other sites

Quick Update.

It appears that the heat gauges and "science alert" have memory leaks. This is probably what I was seeing and not your addon. Maybe I was just doing slightly different things that was causing it when I was playing with and without your addon.

Just thought you should know.

Cheers

Good to hear. More for myself than you. :)

Any chance you can implement the ability to have it do an automatic quicksave if you are in flight and in a situation where you can quick save? I really like the configure ability of this and having this option as well as the pause option would be great!

That's actually a big feature I'm trying to implement. Unfortunately, it's being a lot trickier than I thought. Mainly because KSP doesn't really enjoy kicking a quicksave immediately when you load into flight mode (which is when the biggest memory fluctuations happen). I'd have to somehow add strict conditions to only quick save if you've been X minutes into flight or something along those lines.

Nice mod, I've experimented with an old ram optimizer and whenever Sentinel changes in the yellow alert, I push a hotkey and the optimizer (RAMRush) does its job and bring Sentinel back in white safety. No yellow or red warnings anymore! No crashes, stable for a few hours with 70% of RAM during the start KSP and after the clean-up RAM of less than 70% for hours.

Excellent! :D

Link to comment
Share on other sites

Nice mod, I've experimented with an old ram optimizer and whenever Sentinel changes in the yellow alert, I push a hotkey and the optimizer (RAMRush) does its job and bring Sentinel back in white safety. No yellow or red warnings anymore! No crashes, stable for a few hours with 70% of RAM during the start KSP and after the clean-up RAM of less than 70% for hours.

Just wanted to re-quote this post. I do not intend to update this mod anymore as it's made obsolete by RAMRush. I searched for this RAMRush utility and it is astonishingly effective.

Currently, with a very mod-heavy load out (82 folders under GameData, yes, that's my metric for mod density), at the main menu, I'm at 2 GB memory usage with ATM and OpenGL.

Then I simply open RAMRush and let it do its thing.

It drops my usage to exactly 130 MB. :confused:

That's all you have to do. During normal gameplay, my memory never goes over 1.5 GB usage. I'm not quite sure how RAMRush works, but I know that Unity is rather generous when it comes to garbage collection in favour of runtime performance. It is entirely possible this program forces a GC cycle. But this entirely a speculation.

You can download the application here:

http://www.fcleaner.com/ramrush.htm

I suggest anyone frustrated of memory issues in KSP to try it. All credit goes to mrsnoid for finding this gem. :)

Link to comment
Share on other sites

It is a bit unclear what RamRush does and how exactly does it find KSP in order to optimize it's RAM usage. Does it tap into Unity or hook into KSP somehow? Do you point it to the program you want optimized? Are you sure it doesn't do this by unloading assets that are otherwise needed?

Link to comment
Share on other sites

Those soft have nothing to do with Garbage Collection. They just push memory to the swap. If you look at KSP virtual memory instead of the resident use you see that the memory is still here. It is pure snake oil.

Link to comment
Share on other sites

Those soft have nothing to do with Garbage Collection. They just push memory to the swap. If you look at KSP virtual memory instead of the resident use you see that the memory is still here. It is pure snake oil.

Results suggest it's not though. I managed to play over 5 hours continuously yesterday with just running RAMRush once at the start of KSP, which is something I was never able to do with KSP always crashing after one or two missions with my heavy mod loadout. I was very skeptical myself at first. If it's .NET based, it is entirely possible that it kicks off the GC. If it pushes physical memory to virtual, it would make a lot of sense. And it would reduce performance if it actually does that, unless you are running on a high performance SSD as I am.

In regards to unloading any assets that are actually needed by KSP, I have not seen it, and I'm not sure that's possible, with GC or without. Unity manages the assets, and it has it's own rules on what to keep or not to keep. Unless the third party software communicates directly with Unity, it has no way of locating assets generically, causing immediate memory corruption if it tried it.

- - - Updated - - -

Another possibility might have to with the *.dds texture format. If the textures are pushed directly to GPU memory, there is no reason why they should take up space on the system RAM and they might just be garbage waiting to be collected after they were loaded in and processed by Unity. I'm not expert on GPU memory though, so this is just a guess.

Link to comment
Share on other sites

Is this normal?

Failed to load assembly C:\Kerbal Space Program 1.0\GameData\KSEA\Sentinel\Native\getRSS_x86.dll:
System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.

at Mono.Cecil.PE.ImageReader.ReadOptionalHeaders (System.UInt16& subsystem, System.UInt16& dll_characteristics) [0x00000] in <filename unknown>:0

at Mono.Cecil.PE.ImageReader.ReadImage () [0x00000] in <filename unknown>:0

at Mono.Cecil.PE.ImageReader.ReadImageFrom (System.IO.Stream stream) [0x00000] in <filename unknown>:0

at Mono.Cecil.ModuleDefinition.ReadModule (System.IO.Stream stream, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0

at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0

at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName) [0x00000] in <filename unknown>:0

at AssemblyLoader.ScanForBadTypeRefs (System.String file) [0x00000] in <filename unknown>:0

at AssemblyLoader.LoadExternalAssembly (System.String file) [0x00000] in <filename unknown>:0

Link to comment
Share on other sites

Results suggest it's not though. I managed to play over 5 hours continuously yesterday with just running RAMRush once at the start of KSP, which is something I was never able to do with KSP always crashing after one or two missions with my heavy mod loadout. I was very skeptical myself at first. If it's .NET based, it is entirely possible that it kicks off the GC. If it pushes physical memory to virtual, it would make a lot of sense. And it would reduce performance if it actually does that, unless you are running on a high performance SSD as I am.

In regards to unloading any assets that are actually needed by KSP, I have not seen it, and I'm not sure that's possible, with GC or without. Unity manages the assets, and it has it's own rules on what to keep or not to keep. Unless the third party software communicates directly with Unity, it has no way of locating assets generically, causing immediate memory corruption if it tried it.

- - - Updated - - -

Another possibility might have to with the *.dds texture format. If the textures are pushed directly to GPU memory, there is no reason why they should take up space on the system RAM and they might just be garbage waiting to be collected after they were loaded in and processed by Unity. I'm not expert on GPU memory though, so this is just a guess.

After some tests, RamRush does not stop the game from crashing, and also distorts some planets ground textures. My Kerbin's grass texture became wavy.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...