Skip to content

Refactor profiling into library#61

Merged
trgibeau merged 13 commits into
mainfrom
user/trgibeau/profilingLib
Jul 7, 2026
Merged

Refactor profiling into library#61
trgibeau merged 13 commits into
mainfrom
user/trgibeau/profilingLib

Conversation

@trgibeau

Copy link
Copy Markdown
Collaborator

This pull request introduces several improvements and refactorings to the profiling server and test infrastructure. The main focus is on improving function name resolution, refactoring function lookup logic for clarity and correctness, and adding new test helpers for synthetic sample and test data generation.

Profiling server improvements

  • Refactored function name resolution and lookup logic in Program.cs to use a more robust approach based on ProfileFunctionId and ProfileData, improving accuracy and maintainability. This includes changes to ResolveFunctionName, FindFunction, and related usages throughout the code. [1] [2] [3] [4]
  • Updated call tree aggregation logic to use new properties (e.g., ModuleName, FunctionName) and improved null checks for better reliability when aggregating callers, callees, and stack traces. [1] [2] [3]

Internal API and cache changes

  • Changed static cache clearing to use BinaryFileLocator.ClearResolvedCache() instead of PEBinaryInfoProvider.ClearResolvedCache() for improved binary resolution cache management.

Test infrastructure and helpers

  • Added a new SyntheticSampleBuilder helper class for generating synthetic profile samples and images for unit tests, supporting various common test scenarios.
  • Added a new TestDataHelper utility class for locating test data files (ETL, PDB, DLL) and providing helper methods to retrieve unique functions and paths for test cases.

SDK version update

  • Added or updated global.json to specify .NET SDK version 8.0.421 with rollForward set to latestMinor for consistent build environments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the profiling model and related tooling toward a TraceEvent/IR-decoupled library (ProfileExplorer.Profiling), centered on a neutral function identity (ProfileFunctionId) and resolver-based navigation back to IRTextFunction. It updates the UI, MCP server, and tests to use the new identity and call-tree APIs, and introduces a new profiling/test suite project.

Changes:

  • Introduces ProfileExplorer.Profiling (+ tests) with neutral ProfileFunctionId, sample/counter aggregation, call-tree building, disassembly annotation, and symbol/binary abstractions.
  • Re-keys core profiling data structures from IRTextFunction to ProfileFunctionId, adding a FunctionResolver map for UI/document navigation.
  • Updates UI/MCP server/test code to use new call-tree update signature (UpdateCallTree(weight, stack)) and to resolve functions via ProfileData.ResolveFunction(...).

Reviewed changes

Copilot reviewed 94 out of 101 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ProfileExplorerUITests/SyntheticProfileTests.cs Updates call-tree update invocation to the new weight-based API.
src/ProfileExplorerUI/ProfileStyles.xaml Points CallTree XAML namespace to ProfileExplorer.Profiling assembly.
src/ProfileExplorerUI/Profile/ProfileListView.xaml.cs Uses ProfileCallTreeNode.ResolveFunction(session) and FunctionName string properties.
src/ProfileExplorerUI/Profile/FlameGraph/FlameGraphPanel.xaml.cs Uses resolved function when opening sections.
src/ProfileExplorerUI/Profile/FlameGraph/FlameGraphHost.xaml.cs Switches display/mark/preview actions to use FunctionName and resolved function.
src/ProfileExplorerUI/Profile/FlameGraph/FlameGraph.cs Re-keys flame graph nodes/stack matching to ProfileFunctionId.
src/ProfileExplorerUI/Profile/Document/ProfilingUtils.cs Re-keys marked-function collection from IRTextFunction to ProfileFunctionId.
src/ProfileExplorerUI/Profile/Document/ProfileDocumentMarker.cs Uses FunctionProfileDataProcessing helper for offset-to-element mapping.
src/ProfileExplorerUI/Profile/CallTreePanel.xaml.cs Uses FunctionId for combined-node lookup and resolves IRTextFunction for UI items.
src/ProfileExplorerUI/Profile/CallTreeNodePanel.xaml.cs Re-keys instance enumeration/combining logic to ProfileFunctionId.
src/ProfileExplorerUI/Mcp/McpActionExecutor.cs Resolves functions through ProfileData.ResolveFunction before querying extensions.
src/ProfileExplorerUI/MainWindowProfiling.cs Routes profile navigation through ResolveFunction(this) from neutral call-tree nodes.
src/ProfileExplorerCoreTests/ETWUnmappedFrameResolutionTests.cs Updates tests to use ProfileData.GetFunctionProfile(...) helper.
src/ProfileExplorerCoreTests/EndToEndWorkflowTests.cs Groups/prints function baselines by ProfileFunctionId.
src/ProfileExplorerCoreTests/ASMIRSectionReaderTests.cs Stabilizes test inputs by enforcing explicit CRLF newlines.
src/ProfileExplorerCore/Utilities/ExtensionMethods.cs Adds ProfileCallTreeNode.ResolveFunction(ISession) helper.
src/ProfileExplorerCore/Providers/INameProvider.cs Removes FunctionNameFormatter delegate (moved to profiling library).
src/ProfileExplorerCore/ProfileExplorerCore.csproj Adds project reference to ProfileExplorer.Profiling.
src/ProfileExplorerCore/Profile/ProfileFunctionIdExtensions.cs Adds IRTextFunction.ToProfileId() helper.
src/ProfileExplorerCore/Profile/Processing/ProfileSampleFilter.cs Uses ProfileFunctionId-based child lookup.
src/ProfileExplorerCore/Profile/Processing/FunctionSamplesProcessor.cs Compares stack frames via ProfileFunctionId.
src/ProfileExplorerCore/Profile/Processing/FunctionProfileProcessor.cs Re-keys function profiles and tracks FunctionResolver for navigation.
src/ProfileExplorerCore/Profile/Processing/CallTreeProcessor.cs Uses the new UpdateCallTree(weight, stack) API.
src/ProfileExplorerCore/Profile/ETW/ETWProfileDataProvider.cs Registers created/synthetic functions into ProfileData resolver for navigation.
src/ProfileExplorerCore/Profile/Data/ResolvedProfileStack.cs Implements IResolvedCallStack and precomputes ProfileFunctionId per frame.
src/ProfileExplorerCore/Profile/Data/RawProfileData.cs Uses extracted MethodCode/AddressNamePair types.
src/ProfileExplorerCore/Profile/Data/ProfileModuleBuilder.cs Registers module-created functions into ProfileData resolver.
src/ProfileExplorerCore/Profile/Data/ProfileData.cs Re-keys profiles to ProfileFunctionId + adds FunctionResolver + resolve/register APIs.
src/ProfileExplorerCore/Profile/Data/ManagedRawProfileData.cs Updates managed method code map to new MethodCode type.
src/ProfileExplorerCore/Profile/CallTree/ProfileCallTreeExtensions.cs Adds IRTextFunction convenience overloads mapping to ProfileFunctionId.
src/ProfileExplorerCore/IR/Tags/SourceStackTrace.cs Removes SourceStackFrame (moved into profiling library).
src/ProfileExplorerCore/Compilers/ASM/ASMBinaryFileFinder.cs Switches to BinaryFileLocator for binary location.
src/ProfileExplorerCore/Binary/SymbolFileCache.cs Removes old symbol cache implementation (moved/refactored).
src/ProfileExplorerCore/Binary/IDisassembler.cs Extracts disassembler-related interfaces/options into a dedicated file.
src/ProfileExplorerCore/Binary/IDebugInfoProvider.cs Refactors debug-info interface to derive from ISymbolDebugInfo.
src/ProfileExplorerCore/Binary/DotNetDebugInfoProvider.cs Splits TraceEvent-free managed debug core into library base + PE-specific extensions.
src/ProfileExplorer.sln Adds new profiling library and profiling test projects to the solution.
src/ProfileExplorer.Profiling/Symbols/SymbolFileCache.cs Adds new gzip-based symbol cache in the profiling library.
src/ProfileExplorer.Profiling/Symbols/ISymbolFileResolver.cs Introduces symbol/binary resolver abstraction for library consumers.
src/ProfileExplorer.Profiling/Providers/FunctionNameFormatter.cs Restores FunctionNameFormatter delegate in profiling library.
src/ProfileExplorer.Profiling/Profiling/SampleAggregator.cs Adds concurrent per-function sample aggregation keyed by ProfileFunctionId.
src/ProfileExplorer.Profiling/Profiling/ProfileFunctionId.cs Introduces neutral (module, function-name) function identity.
src/ProfileExplorer.Profiling/Profiling/ManagedMethodResolver.cs Adds managed-method IP resolution via binary search over JIT mappings.
src/ProfileExplorer.Profiling/Profiling/IpResolver.cs Adds IP→(module,function,RVA) resolver with optional managed support.
src/ProfileExplorer.Profiling/Profiling/InstructionOffsetConfig.cs Adds architecture-specific IP-skid correction helper.
src/ProfileExplorer.Profiling/Profiling/CounterAggregator.cs Adds per-function per-instruction performance counter aggregation.
src/ProfileExplorer.Profiling/Profiling/CallTreeBuilder.cs Adds call-tree builder over neutral resolved stacks.
src/ProfileExplorer.Profiling/ProfilerOptions.cs Adds configurable profiling options + validation.
src/ProfileExplorer.Profiling/ProfileExplorer.Profiling.csproj Adds new library project packaging native deps and targets file.
src/ProfileExplorer.Profiling/Profile/Data/ModuleProfileInfo.cs Adds module-level profile grouping model.
src/ProfileExplorer.Profiling/Profile/Data/FunctionProfileData.cs Adds function profile payload (weights, per-instruction weights/counters).
src/ProfileExplorer.Profiling/Profile/CallTree/ProfileCallTreeNode.cs Refactors call-tree nodes to be IRTextFunction-free (uses ProfileFunctionId).
src/ProfileExplorer.Profiling/Profile/CallTree/ProfileCallSite.cs Updates callsite target matching to ProfileFunctionId.
src/ProfileExplorer.Profiling/Profile/CallTree/IResolvedCallStack.cs Adds neutral resolved stack interface/value frame type.
src/ProfileExplorer.Profiling/Models/ProfileReport.cs Adds public library result model (functions map + call tree + total weight).
src/ProfileExplorer.Profiling/Models/CounterDescriptions.cs Adds public performance counter/metric description models.
src/ProfileExplorer.Profiling/Models/AnnotatedAssembly.cs Adds public annotated-assembly output models.
src/ProfileExplorer.Profiling/Managed/MethodCode.cs Adds extracted managed method-code model + call target lookup.
src/ProfileExplorer.Profiling/Managed/ManagedDebugInfoProvider.cs Adds TraceEvent-free managed debug-info core implementing ISymbolDebugInfo.
src/ProfileExplorer.Profiling/IR/SourceStackFrame.cs Moves SourceStackFrame into the profiling library.
src/ProfileExplorer.Profiling/Disassembly/AssemblyAnnotator.cs Adds disassembly annotation logic incl. skid correction + source lines.
src/ProfileExplorer.Profiling/Counters/PerformanceCounters.cs Moves performance counter models/serialization helpers into the library.
src/ProfileExplorer.Profiling/Collections/TinyList.cs Adds TinyList collection to support allocation-reduced call tree node storage.
src/ProfileExplorer.Profiling/build/net8.0/ProfileExplorer.Profiling.targets Adds MSBuild targets for copying native runtime deps to consumer outputs.
src/ProfileExplorer.Profiling/Binary/SymbolFileDescriptor.cs Adds symbol file descriptor model (PDB identity).
src/ProfileExplorer.Profiling/Binary/SourceLineDebugInfo.cs Adds source-line debug info model used by symbol readers/annotation.
src/ProfileExplorer.Profiling/Binary/SourceFileDebugInfo.cs Adds source-file debug info model used by symbol readers/annotation.
src/ProfileExplorer.Profiling/Binary/ISymbolDebugInfo.cs Adds decoupled debug-info interface used by library disassembly/symbol logic.
src/ProfileExplorer.Profiling/Binary/IBinaryInfoProvider.cs Adds binary identity model and provider interface.
src/ProfileExplorer.Profiling/Binary/FunctionDebugInfo.cs Adds function debug info model (RVA/size/name + source lines).
src/ProfileExplorer.Profiling/Binary/Disassembler.cs Refactors disassembler to depend on ISymbolDebugInfo and adds instruction-list API.
src/ProfileExplorer.Profiling/Abstractions/IProfileSample.cs Adds consumer-facing sample abstraction.
src/ProfileExplorer.Profiling/Abstractions/IProfileImage.cs Adds consumer-facing image/module abstraction.
src/ProfileExplorer.Profiling/Abstractions/IPerformanceCounterEvent.cs Adds consumer-facing counter-event abstraction.
src/ProfileExplorer.Profiling/Abstractions/IManagedMethodMapping.cs Adds consumer-facing managed mapping abstraction (+ IL mapping record).
src/ProfileExplorer.Profiling.Tests/Unit/SymbolServerClientTests.cs Adds unit tests for symbol-path parsing and server config.
src/ProfileExplorer.Profiling.Tests/Unit/SampleAggregatorTests.cs Adds unit tests for sample aggregation behavior.
src/ProfileExplorer.Profiling.Tests/Unit/ProfilerOptionsValidationTests.cs Adds unit tests for options validation/clamping.
src/ProfileExplorer.Profiling.Tests/Unit/ManagedMethodResolverTests.cs Adds unit tests for managed method binary search behavior.
src/ProfileExplorer.Profiling.Tests/Unit/IpSkidCorrectionTests.cs Adds unit tests for skid correction behavior.
src/ProfileExplorer.Profiling.Tests/Unit/CounterAggregatorTests.cs Adds unit tests for counter aggregation and derived metrics.
src/ProfileExplorer.Profiling.Tests/Unit/CallTreeBuilderTests.cs Adds unit tests for call tree build + inclusive/exclusive weight behavior.
src/ProfileExplorer.Profiling.Tests/Unit/AssemblyAnnotatorTests.cs Adds unit tests for annotated assembly output and hot-line extraction.
src/ProfileExplorer.Profiling.Tests/ProfileExplorer.Profiling.Tests.csproj Adds profiling tests project configuration.
src/ProfileExplorer.Profiling.Tests/Integration/PdbSymbolProviderTests.cs Adds integration tests for DIA-based PDB symbol loading.
src/ProfileExplorer.Profiling.Tests/Integration/PdbDiagnosticTests.cs Adds optional diagnostic integration test controlled by env var.
src/ProfileExplorer.Profiling.Tests/Integration/FunctionProfilerEndToEndTests.cs Adds end-to-end synthetic profiling → disassembly → annotation integration test.
src/ProfileExplorer.Profiling.Tests/Integration/DisassemblerTests.cs Adds integration tests for disassembly correctness/robustness.
src/ProfileExplorer.Profiling.Tests/Helpers/TestDataHelper.cs Adds shared helper for locating test data (Traces/Symbols/Binaries).
src/ProfileExplorer.Profiling.Tests/Helpers/SyntheticSampleBuilder.cs Adds shared synthetic sample/image builders used by unit tests.
src/ProfileExplorer.McpServer/Program.cs Updates MCP server profiling function lookup/formatting to use ProfileFunctionId.
global.json Pins .NET SDK version for consistent builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ProfileExplorer.Profiling/Binary/SymbolFileDescriptor.cs
Comment thread src/ProfileExplorer.Profiling/Binary/SymbolFileDescriptor.cs
Comment thread src/ProfileExplorer.Profiling/Managed/MethodCode.cs Outdated
@trgibeau
trgibeau marked this pull request as ready for review June 24, 2026 22:53
@trgibeau
trgibeau requested a review from bgn64 June 24, 2026 22:57
trgibeau added 2 commits June 24, 2026 16:12
Resolve FindFunction conflict in McpServer by adapting main's demangled-name lookup feature to the branch's ProfileFunctionId model. Auto-merge keeps main's Managed Identity symbol auth (#58) alongside the PdbSymbolProvider refactor.
Comment thread src/ProfileExplorer.McpServer/Program.cs
Comment thread src/ProfileExplorer.McpServer/Program.cs
Comment thread src/ProfileExplorer.Profiling/Profile/CallTree/ProfileCallTreeNode.cs Outdated
Comment thread src/ProfileExplorer.Profiling/Symbols/ISymbolFileResolver.cs Outdated
Comment thread src/ProfileExplorerCore/Profile/ProfileFunctionIdExtensions.cs
Comment thread src/ProfileExplorer.Profiling/FunctionProfiler.cs
Comment thread src/ProfileExplorer.Profiling.Tests/Integration/DisassemblerTests.cs Outdated
Comment thread src/ProfileExplorer.Profiling.Tests/Integration/PdbDiagnosticTests.cs Outdated
Comment thread src/ProfileExplorer.Profiling.Tests/Unit/CounterAggregatorTests.cs
Comment thread src/ProfileExplorer.Profiling/Binary/Disassembler.cs
Comment thread src/ProfileExplorer.Profiling/Managed/ManagedDebugInfoProvider.cs
Comment thread src/ProfileExplorer.Profiling/Profile/CallTree/ProfileCallTree.cs Outdated
@trgibeau
trgibeau force-pushed the user/trgibeau/profilingLib branch from 06e470c to b8a4fd0 Compare July 2, 2026 16:18
Comment thread src/ProfileExplorer.Profiling/Symbols/SymbolServerClient.cs Outdated
@trgibeau
trgibeau merged commit e09d432 into main Jul 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants