Profiler: Trace is null or empty (PS 5.1 and 7) on Windows Server 2016

Windows Server 2016 v1607 build 14393.4283.

Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.14393.3866                                                                          
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.14393.3866                                                                         
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 

and

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Installed the module (3.0.0) from PSGallery, cloned this repo and ran the example from README.md.

$trace = Trace-Script -ScriptBlock { & "demo-scripts/MyScript.ps1" }

PS5.1:

Running in PowerShell 5.1.14393.3866.
Tracing...
Trace is null or empty.
At C:\Program Files\WindowsPowerShell\Modules\Profiler\3.0.0\Trace-ScriptInternal.ps1:137 char:9
+         throw "Trace is null or empty."
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Trace is null or empty.:String) [], RuntimeException
    + FullyQualifiedErrorId : Trace is null or empty.

PS7:

Running in PowerShell 7.1.3.
Tracing...
Exception: C:\Program Files\WindowsPowerShell\Modules\Profiler\3.0.0\Trace-ScriptInternal.ps1:137
Line |
 137 |          throw "Trace is null or empty."
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Trace is null or empty.

Same for SleepyScript.ps1.

I tried 3.0.0 rc2 (via Install-Module -Name Profiler -RequiredVersion 3.0.0-rc2 -AllowPrerelease) (which took an age to install due to AV pricking it’s ears up). Same result unfortunately.

I feel as though perhaps I’m missing some pre-requisite, but unsure. Any ideas? Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 36 (20 by maintainers)

Most upvoted comments

Works on Windows Server 2012 R2.

@robinmalik, it is a PC with i7. With my Vm, the duration is 20 seconds.

Lol that is some slow execution. But to be honest, on my ryzen 5 based computer with ton of ram I don’t get faster execution than @LaurentDardenne either, but it is still under 400ms.

Re: ./demo.ps1 - I’d noticed that, but hadn’t realised it was making any difference. Should have known (been a while since I dotsourced files and thought about the scope impact) 🤦‍♂️ No rush on my part by the way - thanks for everything you’ve done so far.

So yeah, it looks like our code works all correctly, you don’t get any output on the Top50 because each one of the filter to >0, and you have non of those, except for hit counts. I don’t think we even calculate the start time, and the timestamps are negative so weird. Need to have a look at this later.

Ah that is probably because you are running the demo like ./demo.ps1, but you need to dotsource it to keep $trace variable in scope: . ./demo.ps1. Posted it above, but it’s easy to miss. Should have pointed that out, sorry.

In the following script : https://github.com/nohwnd/Profiler/blob/main/Profiler/Trace-ScriptInternal.ps1#L107

I added this:

$trace |% {Write-warning ("{0}: {1} - {2}" -F $_.Extent.Text, $_.StartTime, $_.SelfDuration)}

I have run the test file, 3 tests fail. Unless I’m mistaken, I see that StartTime always has the same value and Duration is always zero: image

Note that StartTime always has the same value after several test executions or after relaunching the powershell session. Same thing in Windows 10.

With the version 2.0.2 :
image

Correct (working on W10 and 2019). Tested on a second 2016 server just to be sure and got the same error.

Fixed in #28

Mkay so I do the math correctly, just assuming incorrectly that the number will be a whole number. It needs to use double/decimal instead of long:

[timespan]::fromticks((9714185883-9711765734)/(2343750/10000000))
-> 1s

And we can get the max precision like this [int] (1e9/2343750) -> 427ns