Refactor profile input loading responsibilities - #58
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors profile input loading in ProfileTool by extracting trace/heap input handling and shared “static utility” responsibilities (kind resolution, defaults policy, label generation, and memory result creation) into focused collaborators, leaving ProfileInputLoader as a thin facade.
Changes:
- Extracted trace and heap input loaders (
TraceProfileInputLoader,HeapProfileInputLoader) and updatedProfileInputLoaderto delegate to them. - Centralized input kind resolution, default mode selection, label creation, and memory result creation into dedicated helpers.
- Updated call sites and tests to use the extracted helpers.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Asynkron.Profiler.Tests/ProfileInputLoaderTests.cs | Updated tests to use new factories/policy instead of ProfileInputLoader static helpers. |
| src/ProfileTool/ProfilerExecutionRequestFactory.cs | Switched label/default-mode selection to new helpers when --input is provided. |
| src/ProfileTool/ProfileInputLoader.cs | Reduced to a facade that composes and delegates to the new input loaders. |
| src/ProfileTool/ProfileCollectionRunner.cs | Switched memory result construction to MemoryProfileResultFactory. |
| src/ProfileTool/Input/TraceProfileInputLoader.cs | New: handles trace/speedscope input validation and analysis with consistent error reporting. |
| src/ProfileTool/Input/HeapProfileInputLoader.cs | New: handles heap input kinds (.gcdump vs report files) and tool availability. |
| src/ProfileTool/Input/ProfileInputLabelFactory.cs | New: builds sanitized input labels from file names. |
| src/ProfileTool/Input/ProfileInputKindResolver.cs | New: resolves ProfileInputKind from file extensions and identifies trace inputs. |
| src/ProfileTool/Input/ProfileInputKind.cs | New: enum representing supported input kinds. |
| src/ProfileTool/Input/ProfileInputDefaultsPolicy.cs | New: applies default run-mode flags based on resolved input kind. |
| src/ProfileTool/Input/MemoryProfileResultFactory.cs | New: constructs MemoryProfileResult from allocation call trees (sort + cap to 50). |
Comments suppressed due to low confidence (1)
src/ProfileTool/ProfilerExecutionRequestFactory.cs:52
ProfileInputDefaultsPolicy.Applyis invoked withrunCpu/runMemorypotentially alreadytrue(because they’re initialized asinvocation.* || !hasExplicitModes). Since the policy only turns flags on and never clears them, inputs like.etlx/.gcdumpwill still end up running CPU/memory by default, which contradicts the defaults asserted inProfileInputLoaderTests.ApplyInputDefaults_MapsExtensionsToExpectedModesand can cause spurious “Unsupported CPU input” errors for heap-only inputs. Consider resetting allrun*flags tofalsebefore applying the policy whenhasInput && !hasExplicitModes, or haveProfileInputDefaultsPolicy.Applyexplicitly set all flags based on the resolved input kind (clearing those not applicable).
if (!hasExplicitModes)
{
ProfileInputDefaultsPolicy.Apply(
invocation.InputPath!,
ref runCpu,
ref runMemory,
ref runHeap,
ref runException,
ref runContention);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
ProfileInputLoaderinto focused collaborators for trace input handling, heap input handling, input kind resolution, default mode policy, label generation, and memory profile result creationTesting
roslynator fix src/ProfilerCore/Asynkron.Profiler.Core.csprojroslynator fix src/ProfileTool/ProfileTool.csprojroslynator fix tests/Asynkron.Profiler.Tests/Asynkron.Profiler.Tests.csprojdotnet build Asynkron.Profiler.sln -warnaserrordotnet test Asynkron.Profiler.slnquickdup -path src -ext .cs -select 0..20 -min 2 -exclude ".g.,.generated."dotnet format Asynkron.Profiler.slnNotes
roslynator fix Asynkron.Profiler.slnhits the current CLI solution-parser issue in this environment, so Roslynator was run project-by-project instead.