Skip to content

Commit c2395c1

Browse files
authored
Update readme with export (#52)
1 parent 72df120 commit c2395c1

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

Profiler/Profiler.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ PrivateData = @{
111111
# ReleaseNotes = ''
112112

113113
# Prerelease string of this module
114-
Prerelease = ''
114+
Prerelease = 'beta1'
115115

116116
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
117117
# RequireLicenseAcceptance = $false

README.MD

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@ Install-Module Profiler
1111
```
1212

1313
```powershell
14-
$trace = Trace-Script -ScriptBlock { & "demo-scripts/MyScript.ps1" }
15-
$trace.Top50Duration | Format-Table
14+
$trace = Trace-Script -ScriptBlock { & "demo-scripts/Get-Icons.ps1" } -ExportPath icons
15+
$trace.Top50SelfDuration | Format-Table
1616
```
1717

1818
![](images/Profile.jpg)
1919

20+
Inspect the output, SelfPercent, and SelfDuration represent time that is spent only in the function, excluding all the code it calls.
21+
22+
Percent and Duration represent time that is takes by the function an all the code it calls.
23+
24+
In our screenshot 98.6% of the execution time is taken by `Invoke-WebRequest`, which runs inside of `Get-EmojiInternal` function inside of `Avocado` module.
25+
26+
You also specified export path which exports the results in https://speedscope.app format. Importing the file will show this result:
27+
28+
![](images/speedscope-time-order.jpg)
29+
30+
Which shows us graphical representation of the run. We can see that two paths, `Get-Avocado` and `Get-Unicorn` both end up calling `Get-EmojiInternal` where most of the time in the script is spent.
31+
2032
## More Features
2133

2234
- Profile module functions, or any scriptblock.

csharp/Profiler/Profiler.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
in unbound scriptblocks, but if we just skip them we don't need it.-->
66
<PropertyGroup Condition=" '$(PowerShellVersion)' == '' ">
77
<TargetFrameworks>netstandard2.0;net452;net451</TargetFrameworks>
8+
<LangVersion>Latest</LangVersion>
89
</PropertyGroup>
910

1011
<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">

csharp/Profiler/Tracer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Management.Automation.Host;
44
using System.Management.Automation.Language;
55
using System.Reflection;
6-
using System.Threading;
76
using NonGeneric = System.Collections;
87

98
namespace Profiler
@@ -34,7 +33,8 @@ public static void Register(object tracer)
3433
if (HasTracer2)
3534
throw new InvalidOperationException("Tracer2 is already present.");
3635

37-
_tracer2 = new ExternalTracerAdapter(tracer) ?? throw new ArgumentNullException(nameof(tracer));
36+
// use tracer directly if it implements our interface, or wrap it in adapter, and call it's methods by reflection, to accomodate tracers that only match our signature but not type.
37+
_tracer2 = tracer is ITracer ourTracerType ? ourTracerType : new ExternalTracerAdapter(tracer) ?? throw new ArgumentNullException(nameof(tracer));
3838
TraceLine(justTracer2: true);
3939
}
4040

images/Profile.jpg

71.3 KB
Loading

images/speedscope-time-order.jpg

123 KB
Loading

0 commit comments

Comments
 (0)