Skip to content

Commit

Permalink
Merge branch 'master' into dev1.2
Browse files Browse the repository at this point in the history
Conflicts:
	Graph.cs
	Output/MemGraph/MemGraph.dll
	Properties/AssemblyInfo.cs
Updated to version 1.1.0.2
  • Loading branch information
Gerry1135 committed Oct 17, 2016
2 parents b2e474f + 7cc1fcd commit 10f3469
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void Awake()
instance = this;

windowId = Guid.NewGuid().GetHashCode();
windowTitle = "MemGraph 1.1.0.1";
windowTitle = "MemGraph 1.1.0.2";

strBuild = new StringBuilder(128);
Log = new LogMsg();
Expand Down
Binary file modified Output/MemGraph/MemGraph.dll
Binary file not shown.
12 changes: 7 additions & 5 deletions Output/MemGraph/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# MemGraph
Copyright (c) 2016 Gerry Iles (Padishar)

This is a simple plugin to display of graph of memory allocation and garbage collection. It is intended as a troubleshooting
and development aid rather than for general use.
This started as a simple plugin that displays a graph of the Mono heap allocation rate and garbage collection, mainly intended
as a troubleshooting and development aid rather than for general use. However, I have since devised a way to force Mono to keep
significantly more free space in the heap, which can significantly reduce the frequency at which the heap fills up and the Mono
garbage collection causes a stutter, so I have added it to this mod.

## Installation
Copy the DLL from the zip file into the GameData folder of your KSP installation.
Copy the MemGraph folder from the zip file into the GameData folder of your KSP installation.

## Usage
Mod-KeypadMultiply toggles the display of the window.
Expand All @@ -29,7 +31,7 @@ Mod-End activates the heap padding. The amount of padding is controlled by the
of the file is very simple. Each line controls the number of padding blocks allocated of each size. The first value is the
size of each block allocated and the second is the number of blocks. The first values are only present for illustration,
they don't actually control the size of the blocks, these are hardwired to the sizes in the default configuration. The
default configuration allocates around 900 MB of padding.
default configuration allocates around 1024 MB of padding.

I recommend that you run the game normally and load up a situation that has noticeable stutter. Display the graph, setting
the scale so the regular allocation rate fits nicely and the garbage collection red lines can be seen. Let it run for several
Expand All @@ -40,7 +42,7 @@ would be very helpful along with details about your setup (and preferably, an ou
Tig for the testing and very well presented data he provided.

One other thing I should add, though it should be obvious with only a little thought, is that the heap padding mechanism is
only intended for 64 bit versions of the game. Trying to allocate 900 MB of extra heap space on the 32 bit version is unlikely
only intended for 64 bit versions of the game. Trying to allocate 1024 MB of extra heap space on the 32 bit version is unlikely
to be successful and, if it is, then it will probably cause the game to crash before long due to running out of address space.
It is also unlikely to work effectively if your machine has only 4GB of RAM as the total usage of KSP is likely to grow close
to 4GB even without loading a save, resulting in virtual memory paging which will seriously hurt performance.
Expand Down
30 changes: 22 additions & 8 deletions PadHeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void Pad()
Log.buf.Append("Pad started, memory = ");
Log.buf.Append((curMem / 1024));
Log.buf.AppendLine(" KB");
//Log.Flush();

head8 = null;
head16 = null;
Expand All @@ -81,6 +82,7 @@ public void Pad()
Log.buf.Append("After disard and collect, memory = ");
Log.buf.Append((curMem / 1024));
Log.buf.AppendLine(" KB");
//Log.Flush();

// Do the small sizes with custom classes
Pad8();
Expand All @@ -95,12 +97,14 @@ public void Pad()
Log.buf.Append("After padding, memory = ");
Log.buf.Append((curMem / 1024));
Log.buf.AppendLine(" KB");
//Log.Flush();

GC.Collect();
curMem = GC.GetTotalMemory(false);
Log.buf.Append("After final collect, memory = ");
Log.buf.Append((curMem / 1024));
Log.buf.AppendLine(" KB");
//Log.Flush();
}
catch (Exception e)
{
Expand Down Expand Up @@ -155,6 +159,8 @@ void UpdateFromConfig()
}
else
Log.buf.AppendLine("Can't find padheap.cfg");

//Log.Flush();
}

void Pad8()
Expand All @@ -163,9 +169,10 @@ void Pad8()
Log.buf.Append("Pad(8): ");
Log.buf.Append(count);
Log.buf.AppendLine("");
//Log.Flush();

long lastMem = GC.GetTotalMemory(false);
Item8 temp;
Item8 temp = null;
Item8 test;
while (count > 0)
{
Expand All @@ -182,7 +189,8 @@ void Pad8()
}
else
{
// Store the block temporarily so the next new doesn't reuse it
// Store the block in the temp list
test.next = temp;
temp = test;
}

Expand All @@ -196,9 +204,10 @@ void Pad16()
Log.buf.Append("Pad(16): ");
Log.buf.Append(count);
Log.buf.AppendLine("");
//Log.Flush();

long lastMem = GC.GetTotalMemory(false);
Item16 temp;
Item16 temp = null;
Item16 test;
while (count > 0)
{
Expand All @@ -215,7 +224,8 @@ void Pad16()
}
else
{
// Store the block temporarily so the next new doesn't reuse it
// Store the block in the temp list
test.next = temp;
temp = test;
}

Expand All @@ -229,9 +239,10 @@ void Pad24()
Log.buf.Append("Pad(24): ");
Log.buf.Append(count);
Log.buf.AppendLine("");
//Log.Flush();

long lastMem = GC.GetTotalMemory(false);
Item24 temp;
Item24 temp = null;
Item24 test;
while (count > 0)
{
Expand All @@ -248,7 +259,8 @@ void Pad24()
}
else
{
// Store the block temporarily so the next new doesn't reuse it
// Store the block in the temp list
test.next = temp;
temp = test;
}

Expand All @@ -267,9 +279,10 @@ void PadArray(int index)
Log.buf.Append("): ");
Log.buf.Append(count);
Log.buf.AppendLine("");
//Log.Flush();

long lastMem = GC.GetTotalMemory(false);
object[] temp;
object[] temp = null;
object[] test;
while (count > 0)
{
Expand All @@ -286,7 +299,8 @@ void PadArray(int index)
}
else
{
// Store the block temporarily so the next new doesn't reuse it
// Store the block in the temp list
test[0] = temp;
temp = test;
}

Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.1")]
[assembly: AssemblyFileVersion("1.1.0.1")]
[assembly: AssemblyVersion("1.1.0.2")]
[assembly: AssemblyFileVersion("1.1.0.2")]
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# MemGraph
Copyright (c) 2016 Gerry Iles (Padishar)

This is a simple plugin to display of graph of memory allocation and garbage collection. It is intended as a troubleshooting
and development aid rather than for general use.
This started as a simple plugin that displays a graph of the Mono heap allocation rate and garbage collection, mainly intended
as a troubleshooting and development aid rather than for general use. However, I have since devised a way to force Mono to keep
significantly more free space in the heap, which can significantly reduce the frequency at which the heap fills up and the Mono
garbage collection causes a stutter, so I have added it to this mod.

## Installation
Copy the DLL from the zip file into the GameData folder of your KSP installation.
Copy the MemGraph folder from the zip file into the GameData folder of your KSP installation.

## Usage
Mod-KeypadMultiply toggles the display of the window.
Expand All @@ -29,7 +31,7 @@ Mod-End activates the heap padding. The amount of padding is controlled by the
of the file is very simple. Each line controls the number of padding blocks allocated of each size. The first value is the
size of each block allocated and the second is the number of blocks. The first values are only present for illustration,
they don't actually control the size of the blocks, these are hardwired to the sizes in the default configuration. The
default configuration allocates around 900 MB of padding.
default configuration allocates around 1024 MB of padding.

I recommend that you run the game normally and load up a situation that has noticeable stutter. Display the graph, setting
the scale so the regular allocation rate fits nicely and the garbage collection red lines can be seen. Let it run for several
Expand All @@ -40,7 +42,7 @@ would be very helpful along with details about your setup (and preferably, an ou
Tig for the testing and very well presented data he provided.

One other thing I should add, though it should be obvious with only a little thought, is that the heap padding mechanism is
only intended for 64 bit versions of the game. Trying to allocate 900 MB of extra heap space on the 32 bit version is unlikely
only intended for 64 bit versions of the game. Trying to allocate 1024 MB of extra heap space on the 32 bit version is unlikely
to be successful and, if it is, then it will probably cause the game to crash before long due to running out of address space.
It is also unlikely to work effectively if your machine has only 4GB of RAM as the total usage of KSP is likely to grow close
to 4GB even without loading a save, resulting in virtual memory paging which will seriously hurt performance.
Expand Down

0 comments on commit 10f3469

Please sign in to comment.