本文介绍了如何在 powershell 中分析(时序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的powershell脚本运行缓慢,有什么办法可以分析powershell脚本吗?

My powershell script runs slowly, is there any way to profile the powershell script?

推荐答案

你可以做 随机暂停 在 Powershell 调试器中.使脚本运行,并在运行时键入 Ctrl-C.它将停止,然后您可以显示堆栈.这会告诉你它在哪里,它在做什么,以及为什么.多次执行此操作,而不仅仅是一次.

You can do random-pausing in the Powershell debugger. Get the script running, and while it's running, type Ctrl-C. It will halt and then you can display the stack. That will tell you where it is, what it's doing, and why. Do this several times, not just once.

假设它需要两倍的时间.这意味着每次你打断它,你会发现它做缓慢的事情的概率是 50%.因此,如果您中断 10 次,您应该会在大约 5 个样本上看到这一点.

Suppose it is taking twice as long as it could. That means each time you interrupt it the probability you will catch it doing the slow thing is 50%. So if you interrupt it 10 times, you should see that on about 5 samples.

假设它花费了 5 倍的时间.这意味着 4/5 的时间被浪费了,所以你应该看到它大约 10 次中有 8 次.

Suppose it is taking 5 times as long as it could. That means 4/5 of the time is being wasted, so you should see it about 8 times out of 10.

即使只有 1/5 的时间被浪费了,您也应该看到它大约 10 次中的 2 次.您在 2 个样本上看到的任何东西,如果您能找到更快的方法,会给你很好的速度提升.

Even if as little as 1/5 of the time is being wasted, you should see it about 2 times out of 10. Anything you see on as few as 2 samples, if you can find a faster way to do it, will give you a good speed improvement.

这篇关于如何在 powershell 中分析(时序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:37