1.7 KiB
Windows PowerShell Script Line Profiler Sample
This sample shows how to create a script line profiler using the new Windows PowerShell 3.0 AST (Abstract Syntax Tree) support.
The sample defines the InstrumentAst class (derived from the ICustomAstVisitor interface) that builds an AST object. The AST object inserts a Profile object callback that measures the execution time of each script statement. The profiler can be run on script files using the provided Measure-Script cmdlet.
Sample Objectives
- Creating a script line profiler using Windows PowerShell
- AST support.
- Running the provided
Measure-Scriptcmdlet to profile a script file.
Related topics
Operating system requirements
Client
Windows 8.1
Server
Windows Server 2012 R2
Build the sample
-
Start Microsoft Visual Studio and select File > Open > Project/Solution.
-
Go to the directory named for the sample, and double-click the Visual Studio Solution (.sln) file.
-
Make sure the PSProfiler project references the System.Management.Automation.dll assembly.
-
Press F7 or use Build > Build Solution to build the sample.
The executable will be built in the default \bin or \bin\Debug directory.
Run the sample
- Run
Import-Modulewith the full path to the sample DLL. - Run the
Measure-Scriptcmdlet on a script file.