Skip to content

Commit 183b33d

Browse files
authored
Nit: cache isReadyState for profiler in ProfilerStatus (#7873)
## Summary of changes We don't need to read and marshall a byte every time ## Reason for change ## Implementation details ## Test coverage ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. -->
1 parent 8697ca8 commit 183b33d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tracer/src/Datadog.Trace/ContinuousProfiler/ProfilerStatus.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal class ProfilerStatus : IProfilerStatus
1717
private readonly object _lockObj;
1818
private bool _isInitialized;
1919
private IntPtr _engineStatusPtr;
20+
private bool _isProfilerReadyCache;
2021

2122
public ProfilerStatus(ProfilerSettings settings)
2223
{
@@ -42,8 +43,16 @@ public bool IsProfilerReady
4243
return false;
4344
}
4445

46+
// once _isProfilerReadyCache is true, it's never false anymore
47+
if (_isProfilerReadyCache)
48+
{
49+
return true;
50+
}
51+
4552
EnsureNativeIsIntialized();
46-
return _engineStatusPtr != IntPtr.Zero && Marshal.ReadByte(_engineStatusPtr) != 0;
53+
var isReady = _engineStatusPtr != IntPtr.Zero && Marshal.ReadByte(_engineStatusPtr) != 0;
54+
_isProfilerReadyCache = isReady;
55+
return isReady;
4756
}
4857
}
4958

0 commit comments

Comments
 (0)