Skip to content

Commit

Permalink
removing the memory guard from this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
dudikeleti committed Oct 31, 2024
1 parent 1341cd8 commit ff396c5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private string CreateSnapshot()

if (members == null)
{
members = new MethodScopeMembers(0, 0);
members = new MethodScopeMembers(new MethodScopeMembersParameters(0, 0));
}

var limitInfo = new CaptureLimitInfo(
Expand Down Expand Up @@ -164,7 +164,7 @@ internal void AddScopeMember<T>(string name, Type type, T value, ScopeMemberKind
{
if (Members == null)
{
Members = new MethodScopeMembers(0, 0);
Members = new MethodScopeMembers(new MethodScopeMembersParameters(0, 0));
}

type = (type.IsGenericTypeDefinition ? value?.GetType() : type) ?? type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@

namespace Datadog.Trace.Debugger.Expressions;

internal record struct MethodScopeMembersParameters(int NumberOfLocals, int NumberOfArguments);
internal class MethodScopeMembers : IPoolable<MethodScopeMembersParameters>
{
private int _index;

public MethodScopeMembers()
{
}

internal MethodScopeMembers(MethodScopeMembersParameters parameters)
{
Set(parameters);
}

internal ScopeMember[] Members { get; private set; }

internal Exception Exception { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// <copyright file="MethodScopeMembersParameters.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

namespace Datadog.Trace.Debugger.Expressions;

internal record struct MethodScopeMembersParameters(int NumberOfLocals, int NumberOfArguments);
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private ProbeExpressionEvaluator GetOrCreateEvaluator()

public bool ShouldProcess(in ProbeData probeData)
{
return HasCondition() || (probeData.Sampler.Sample() && GlobalMemoryCircuitBreaker.Instance.CanAllocate(1024));
return HasCondition() || (probeData.Sampler.Sample());
}

public bool Process<TCapture>(ref CaptureInfo<TCapture> info, IDebuggerSnapshotCreator inSnapshotCreator, in ProbeData probeData)
Expand Down
2 changes: 1 addition & 1 deletion tracer/src/Datadog.Trace/Debugger/Helpers/IPoolable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Datadog.Trace.Debugger.Helpers
{
internal interface IPoolable<TSetParameters>
internal interface IPoolable<in TSetParameters>
{
void Set(TSetParameters parameters);

Expand Down
230 changes: 0 additions & 230 deletions tracer/src/Datadog.Trace/Debugger/Helpers/MemoryInfoRetriever.cs

This file was deleted.

19 changes: 6 additions & 13 deletions tracer/src/Datadog.Trace/Debugger/Helpers/ObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@

namespace Datadog.Trace.Debugger.Helpers
{
internal class ObjectPool<T, TSetParameters>
internal class ObjectPool<T, TSetParameters>(Func<T>? objectFactory = null, int maxSize = 100)
where T : class, IPoolable<TSetParameters>, new()
{
private readonly ConcurrentBag<T> _objects;
private readonly Func<T> _objectFactory;
private readonly int _maxSize;
private readonly ConcurrentBag<T> _objects = new();
private readonly Func<T> _objectFactory = objectFactory ?? (() => new T());
private readonly int _maxSize = maxSize;

public ObjectPool(Func<T>? objectFactory = null, int maxSize = 100)
{
_objectFactory = objectFactory ?? (() => new T());
_maxSize = maxSize;
_objects = new ConcurrentBag<T>();
}
public int Count => _objects.Count;

public T Get() => _objects.TryTake(out T item) ? item : _objectFactory();
public T? Get() => _objects.TryTake(out var item) ? item : _objectFactory();

public T? Get(TSetParameters parameters)
{
Expand All @@ -40,7 +35,5 @@ public void Return(T? item)
_objects.Add(item);
}
}

public int Count => _objects.Count;
}
}

This file was deleted.

Loading

0 comments on commit ff396c5

Please sign in to comment.