【问题标题】:How to profile the startup time of Powershell?如何分析 Powershell 的启动时间?
【发布时间】:2019-08-18 16:16:28
【问题描述】:

启动我的 powershell 大约需要 3 秒,所以我想减少它。 如何知道哪个进程损害了powershell的启动性能? 我想使用像vim profiling 这样的工具。

【问题讨论】:

  • 这可能是您的个人资料。尝试在您的整个个人资料上运行Measure-Command
  • @Drew 谢谢!我写了$profile.psobject.properties | where { $_ -is [psnoteproperty] } | foreach { echo $_.value; Measure-Command { . $_ .value }}
  • @Yohei 您的脚本中有一个无用的空间。也许$_ .value 应该是$_.value

标签: powershell


【解决方案1】:

Set-PSDebug 方法:要快速查看你的配置文件是否慢,可以添加

Set-PSDebug -Trace 1

到您个人资料的顶部。然后,您将能够实时查看正在执行的各个行。将Set-PSDebug -Trace 0 添加到您的个人资料底部以将其关闭。

测量您的多个 $PROFILE 文件:要测量自动包含在当前 $PROFILE 中的不同配置文件:

$PROFILE | gm -Type NoteProperty | % {($path=$PROFILE.($_.Name)); Measure-Command{&{. $path}}}

您的配置文件中的Measure-Command:您还可以通过编辑您的配置文件将单个命令或整个配置文件包装在Measure-Command 中。例如,要报告您的配置文件的执行时间:

$executionTime = Measure-Command `
{
    # Your profile commands here
}

# $PSCommandPath is an automatic variable containing the path and file name of
# the script being run.
Write-Host "$PSCommandPath execution time: $executionTime"

【讨论】:

    猜你喜欢
    • 2013-06-15
    • 2010-12-13
    • 1970-01-01
    • 2018-04-25
    • 2013-01-01
    • 2013-06-21
    • 1970-01-01
    • 2016-01-04
    相关资源
    最近更新 更多