-
-
Notifications
You must be signed in to change notification settings - Fork 6
start #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
start #440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
|
|
||
| { | ||
| "$schema": "https://aka.ms/codetour-schema", | ||
| "title": "Silhouette", | ||
| "steps": | ||
| [ | ||
| { | ||
| "file": "rscg_examples/Silhouette/src/ProfilerDemo/ProfilerDemo.csproj", | ||
| "description": "First, we add Nuget [Silhouette](https://www.nuget.org/packages/Silhouette/) in csproj ", | ||
| "pattern": "Silhouette" | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "rscg_examples/Silhouette/src/ProfilerDemo/Program.cs", | ||
| "description": "File Program.cs \r\n>> dotnet run --project rscg_examples/Silhouette/src/ProfilerDemo/ProfilerDemo.csproj ", | ||
| "pattern": "this is the code" | ||
| } | ||
|
|
||
|
|
||
| ,{ | ||
| "file": "rscg_examples/Silhouette/src/ProfilerDemo/obj/GX/Silhouette.SourceGenerator/Silhouette.SourceGenerator.ProfilerAttributeSourceGenerator/silhouette.dllmain.g.cs", | ||
| "description": "Generated File 1 from 1 : silhouette.dllmain.g.cs ", | ||
| "line": 1 | ||
| } | ||
|
|
||
| ], | ||
|
|
||
| "ref": "main" | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ public enum Category | |
| Validator=40, | ||
| Decorator= 41, | ||
| MCP= 42, | ||
| Bool=43 | ||
| Bool=43, | ||
| Profiler=44, | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
|
|
||
| <h1>RSCG nr 249 : Silhouette</h1> | ||
|
|
||
| <h2>Info</h2> | ||
| Nuget : <a href="https://www.nuget.org/packages/Silhouette/" target="_blank">https://www.nuget.org/packages/Silhouette/</a> | ||
|
|
||
| <p>You can find more details at : <a href="https://github.com/kevingosse/Silhouette" target="_blank"> https://github.com/kevingosse/Silhouette</a></p> | ||
|
|
||
| <p>Author :Kevin Gosse</p> | ||
|
|
||
| <p>Source: <a href="https://github.com/kevingosse/Silhouette" target="_blank">https://github.com/kevingosse/Silhouette</a> </p> | ||
|
|
||
| <h2>About</h2> | ||
|
|
||
| Profiling .net applicationsMeasuring performance improvements | ||
|
|
||
| <h2> | ||
| How to use | ||
| </h2> | ||
| <h3> | ||
| Add reference to the <a href="https://www.nuget.org/packages/Silhouette/" target="_blank">Silhouette</a> in the csproj | ||
| </h3> | ||
| <img src="images/Silhouette/ProfilerDemo.csproj.png" width="580" height="580" /> | ||
|
|
||
| <h3>This was for me the <b>starting</b> code</h3> | ||
|
|
||
| <br /> | ||
| I have <b>coded</b> the file Program.cs | ||
| <br /> | ||
| <img src="images/Silhouette/csFiles/Program.cs.png" width="580" height="580" /> | ||
| <hr /> | ||
| <h3>And here are the <i>generated</i> files</h3> | ||
|
|
||
| <br /> | ||
| The file <i>generated</i> is silhouette.dllmain.g.cs | ||
| <br /> | ||
| <img src="images/Silhouette/generated/silhouette.dllmain.g.cs.png" width="580" height="580" /> | ||
|
|
||
| <p> | ||
| You can download the code and this page as pdf from | ||
| <a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/Silhouette'> | ||
| https://ignatandrei.github.io/RSCG_Examples/v2/docs/Silhouette | ||
| </a> | ||
| </p> | ||
|
|
||
|
|
||
| <p> | ||
| You can see the whole list at | ||
| <a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG'> | ||
| https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG | ||
| </a> | ||
| </p> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||
| { | ||||||
| "generator":{ | ||||||
| "name":"Silhouette", | ||||||
| "nuget":[ | ||||||
| "https://www.nuget.org/packages/Silhouette/" | ||||||
| ], | ||||||
| "link":"https://github.com/kevingosse/Silhouette", | ||||||
| "author":"Kevin Gosse", | ||||||
| "source":"https://github.com/kevingosse/Silhouette" | ||||||
| }, | ||||||
| "data":{ | ||||||
| "goodFor":["Profiling .net applications","Measuring performance improvements"], | ||||||
| "csprojDemo":"ProfilerDemo.csproj", | ||||||
| "csFiles":["Program.cs"], | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add MyProfiler.cs to the csFiles array. The 🔎 Proposed fix- "csFiles":["Program.cs"],
+ "csFiles":["Program.cs","MyProfiler.cs"],📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| "excludeDirectoryGenerated":["NativeObjects"], | ||||||
| "includeAdditionalFiles":[""] | ||||||
| }, | ||||||
| "links":{ | ||||||
| "blog":"", | ||||||
| "video":"" | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| A library to build .NET profilers in .NET. No need for C++ anymore, just C#. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| Silhouette - A library to build .NET profilers in .NET | ||
| ======================= | ||
|
|
||
| # Quick start | ||
|
|
||
| Create a new C# NativeAOT project. Reference the Silhouette nuget package and add a class inheriting from `Silhouette.CorProfilerCallback11Base` (you can use a different version of `CorProfilerCallbackBase` depending on the version of .NET you're targeting). Override the `Initialize` method. It will be called with the highest version number of `ICorProfilerInfo` supported by the target runtime. | ||
|
|
||
| ```csharp | ||
|
|
||
| using Silhouette; | ||
|
|
||
| [Profiler("0A96F866-D763-4099-8E4E-ED1801BE9FBC")] // Use your own profiler GUID here | ||
| internal partial class CorProfilerCallback : CorProfilerCallback11Base | ||
| { | ||
| protected override HResult Initialize(int iCorProfilerInfoVersion) | ||
| { | ||
| if (iCorProfilerInfoVersion < 11) | ||
| { | ||
| return HResult.E_FAIL; | ||
| } | ||
|
|
||
| var result = ICorProfilerInfo11.SetEventMask(COR_PRF_MONITOR.COR_PRF_ENABLE_STACK_SNAPSHOT | COR_PRF_MONITOR.COR_PRF_MONITOR_THREADS); | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The `Profiler` attribute triggers a source-generator that emits the proper `DllGetClassObject` function and validates that the user is using the matching guid for the profiler. Alternatively, you can manually implement a `DllGetClassObject` method that will be called by the .NET runtime when initializing the profiler. Use the built-in `ClassFactory` implementation and give it an instance of your `CorProfiler` class. | ||
|
|
||
| ```csharp | ||
| using Silhouette; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal class DllMain | ||
| { | ||
| // This code is automatically generated when using the `[Profiler]` attribute on `CorProfilerCallback` | ||
| [UnmanagedCallersOnly(EntryPoint = "DllGetClassObject")] | ||
| public static unsafe HResult DllGetClassObject(Guid* rclsid, Guid* riid, nint* ppv) | ||
| { | ||
| // Use your own profiler GUID here | ||
| if (*rclsid != new Guid("0A96F866-D763-4099-8E4E-ED1801BE9FBC")) | ||
| { | ||
| return HResult.CORPROF_E_PROFILER_CANCEL_ACTIVATION; | ||
| } | ||
|
|
||
| *ppv = ClassFactory.For(new CorProfilerBase()); | ||
|
|
||
| return HResult.S_OK; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| `CorProfilerXxBase` offers base virtual methods for all `ICorProfilerCallback` methods, so override the ones you're interested in: | ||
|
|
||
| ```csharp | ||
| protected override HResult ThreadCreated(ThreadId threadId) | ||
| { | ||
| Console.WriteLine($"Thread created: {threadId.Value}"); | ||
| return HResult.S_OK; | ||
| } | ||
| ``` | ||
|
|
||
| Use the `ICorProfilerInfoXx` fields to access the `ICorProfilerInfo` APIs: | ||
|
|
||
| ```csharp | ||
| private unsafe string ResolveMethodName(nint ip) | ||
| { | ||
| try | ||
| { | ||
| var functionId = ICorProfilerInfo11.GetFunctionFromIP(ip).ThrowIfFailed(); | ||
| var functionInfo = ICorProfilerInfo2.GetFunctionInfo(functionId).ThrowIfFailed(); | ||
| using var metaDataImport = ICorProfilerInfo2.GetModuleMetaDataImport(functionInfo.ModuleId, CorOpenFlags.ofRead).ThrowIfFailed().Wrap(); | ||
| var methodProperties = metaDataImport.Value.GetMethodProps(new MdMethodDef(functionInfo.Token)).ThrowIfFailed(); | ||
| var typeDefProps = metaDataImport.Value.GetTypeDefProps(methodProperties.Class).ThrowIfFailed(); | ||
|
|
||
| return $"{typeDefProps.TypeName}.{methodProperties.Name}"; | ||
| } | ||
| catch (Win32Exception) | ||
| { | ||
| return "<unknown>"; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Most methods return an instance of `HResult<T>`. You can deconstruct it into a `(HResult error, T result)` and manually check the error code. You can also use the `ThrowIfFailed()` method that will return only the result and throw a `Win32Exception` if the error code is not `S_OK`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <Solution> | ||
| <Project Path="ProfilerDemo/ProfilerDemo.csproj" /> | ||
| </Solution> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spacing/punctuation between sentences.
The description text is missing proper spacing or punctuation between "applications" and "Measuring".
🔎 Proposed fix
Note: Also consider capitalizing ".NET" for consistency with official branding.
📝 Committable suggestion
🤖 Prompt for AI Agents