Slim ThreadStressLogData and simplify GetStressMessages API#129673
Open
max-charlamb wants to merge 1 commit into
Open
Slim ThreadStressLogData and simplify GetStressMessages API#129673max-charlamb wants to merge 1 commit into
max-charlamb wants to merge 1 commit into
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR narrows the stress log contract surface by slimming ThreadStressLogData down to essential fields and by changing IStressLog.GetStressMessages to accept a TargetPointer address (instead of a ThreadStressLogData value), updating SOS and tooling call sites accordingly.
Changes:
- Reduce
ThreadStressLogDatato{ Address, ThreadId, WriteHasWrapped }in the cDAC abstractions/design docs and adjust contract construction. - Change
GetStressMessagessignature toGetStressMessages(TargetPointer threadStressLogAddress)and re-readThreadStressLoginternally in the contract implementation. - Update consumers (SOSDacImpl bridge, dump tests, StressLogAnalyzer) to pass the thread log address.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tools/StressLogAnalyzer/src/StressLogAnalyzer.cs | Updates calls to GetStressMessages to pass log.Address. |
| src/native/managed/cdac/tests/DumpTests/StressLogDumpTests.cs | Updates contract test to pass thread.Address into GetStressMessages. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs | Simplifies message enumerator creation by passing the thread log address directly to the contract. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StressLog.cs | Refactors contract traversal to accept a thread log address and re-read ThreadStressLog data internally. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IStressLog.cs | Slims ThreadStressLogData and updates GetStressMessages signature in the abstraction contract. |
| docs/design/datacontracts/StressLog.md | Updates design documentation to reflect slimmer thread data and the new GetStressMessages signature. |
Comment on lines
+7323
to
7325
| TargetPointer address = threadStressLogAddress.ToTargetPointer(_target); | ||
| IEnumerable<Contracts.StressMsgData> messages = stressLogContract.GetStressMessages(address); | ||
| ppEnum.Interface = new SOSStressLogMsgEnum(_target, messages); |
Comment on lines
+126
to
+135
| public IEnumerable<StressMsgData> GetStressMessages(TargetPointer threadStressLogAddress) | ||
| { | ||
| uint stressMsgHeaderSize = target.GetTypeInfo(DataType.StressMsgHeader).Size!.Value; | ||
| uint pointerSize = (uint)target.PointerSize; | ||
|
|
||
| Data.ThreadStressLog threadLog = target.ProcessedData.GetOrAdd<Data.ThreadStressLog>(threadStressLogAddress); | ||
|
|
||
| Data.StressLogChunk currentChunkData = target.ProcessedData.GetOrAdd<Data.StressLogChunk>(threadLog.CurrentWriteChunk); | ||
| TargetPointer currentReadChunk = threadLog.CurrentWriteChunk; | ||
| TargetPointer readPointer = threadLog.CurrentPointer; | ||
| TargetPointer readPointer = threadLog.CurrentPtr; |
Reduce ThreadStressLogData public record from 8 fields to 3:
{Address, ThreadId, WriteHasWrapped}. The removed fields
(NextPointer, CurrentPointer, ChunkListHead, ChunkListTail,
CurrentWriteChunk) are internal traversal state that only the
contract implementation needs.
Change GetStressMessages to take a TargetPointer (the thread stress
log address) instead of the full record. The contract re-reads the
ThreadStressLog data internally from that address.
This also simplifies GetStressLogMessageEnumerator in SOSDacImpl --
it no longer needs to re-enumerate all threads to find the matching
one; it passes the address directly to the contract.
Fix pre-existing StressLogAnalyzer crash: contract version was
specified as numeric 2 instead of string "c2" in the hardcoded
contract descriptor JSON.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0c7050b to
210d5a8
Compare
Comment on lines
7319
to
+7323
| Contracts.IStressLog stressLogContract = _target.Contracts.StressLog; | ||
| if (!stressLogContract.HasStressLog()) | ||
| return HResults.S_FALSE; | ||
|
|
||
| Contracts.StressLogData logData = stressLogContract.GetStressLogData(); | ||
|
|
||
| // Find the matching thread | ||
| Contracts.ThreadStressLogData? matchedThread = null; | ||
| foreach (var thread in stressLogContract.GetThreadStressLogs(logData.Logs)) | ||
| { | ||
| if (thread.Address == threadStressLogAddress.ToTargetPointer(_target)) | ||
| { | ||
| matchedThread = thread; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (matchedThread is null) | ||
| return HResults.E_INVALIDARG; | ||
|
|
||
| IEnumerable<Contracts.StressMsgData> messages = stressLogContract.GetStressMessages(matchedThread.Value); | ||
| TargetPointer address = threadStressLogAddress.ToTargetPointer(_target); |
Comment on lines
+126
to
134
| public IEnumerable<StressMsgData> GetStressMessages(TargetPointer threadStressLogAddress) | ||
| { | ||
| uint stressMsgHeaderSize = target.GetTypeInfo(DataType.StressMsgHeader).Size!.Value; | ||
| uint pointerSize = (uint)target.PointerSize; | ||
|
|
||
| Data.ThreadStressLog threadLog = target.ProcessedData.GetOrAdd<Data.ThreadStressLog>(threadStressLogAddress); | ||
|
|
||
| Data.StressLogChunk currentChunkData = target.ProcessedData.GetOrAdd<Data.StressLogChunk>(threadLog.CurrentWriteChunk); | ||
| TargetPointer currentReadChunk = threadLog.CurrentWriteChunk; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up based on #129272 (comment)
Summary
Reduce the public surface of
ThreadStressLogDataand simplify theGetStressMessagesAPI signature.Changes
ThreadStressLogData: Trimmed from 8 fields to 3:{Address, ThreadId, WriteHasWrapped}. The removed fields (NextPointer,CurrentPointer,ChunkListHead,ChunkListTail,CurrentWriteChunk) are internal traversal state only needed by the contract implementation.GetStressMessages: Changed fromGetStressMessages(ThreadStressLogData threadLog)toGetStressMessages(TargetPointer threadStressLogAddress). The contract re-reads theThreadStressLogdata internally from the address.SOSDacImpl.GetStressLogMessageEnumerator: Simplified -- no longer needs to re-enumerate all threads to find the matching one. Passes the address directly to the contract.Motivation
Feedback from PR #129272 review (noahfalk): the public
ThreadStressLogDatarecord exposed internal data structure implementation details (chunk pointers, write positions) that consumers don't need. OnlyThreadId,WriteHasWrapped, andAddressare used externally.Related