Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add current memory usage to debug information #705

Merged
merged 2 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions Jint/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ public Engine(Action<Options> options)

public GlobalSymbolRegistry GlobalSymbolRegistry { get; }

internal long CurrentMemoryUsage { get; private set; }

internal Options Options { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; }

#region Debugger
Expand Down Expand Up @@ -464,10 +466,10 @@ internal void RunBeforeExecuteStatementChecks(Statement statement)
{
if (GetAllocatedBytesForCurrentThread != null)
{
var memoryUsage = GetAllocatedBytesForCurrentThread() - _initialMemoryUsage;
if (memoryUsage > _memoryLimit)
CurrentMemoryUsage = GetAllocatedBytesForCurrentThread() - _initialMemoryUsage;
if (CurrentMemoryUsage > _memoryLimit)
{
ExceptionHelper.ThrowMemoryLimitExceededException($"Script has allocated {memoryUsage} but is limited to {_memoryLimit}");
ExceptionHelper.ThrowMemoryLimitExceededException($"Script has allocated {CurrentMemoryUsage} but is limited to {_memoryLimit}");
}
}
else
Expand Down
7 changes: 6 additions & 1 deletion Jint/Runtime/Debugger/DebugHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ private bool BpTest(Statement statement, BreakPoint breakpoint)

private DebugInformation CreateDebugInformation(Statement statement)
{
var info = new DebugInformation { CurrentStatement = statement, CallStack = _debugCallStack };
var info = new DebugInformation
{
CurrentStatement = statement,
CallStack = _debugCallStack,
CurrentMemoryUsage = _engine.CurrentMemoryUsage
};

if (_engine.ExecutionContext.LexicalEnvironment != null)
{
Expand Down
3 changes: 2 additions & 1 deletion Jint/Runtime/Debugger/DebugInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace Jint.Runtime.Debugger
{
public class DebugInformation : EventArgs
{
public Stack<String> CallStack { get; set; }
public Stack<string> CallStack { get; set; }
public Statement CurrentStatement { get; set; }
public long CurrentMemoryUsage { get; set; }
public Dictionary<string, JsValue> Locals { get; set; }
public Dictionary<string, JsValue> Globals { get; set; }
}
Expand Down