简体   繁体   English

确定高处理器使用率的来源

[英]Determining source of high processor usage

I've added ICQ# library (it's open source) to my application. 我已将ICQ#库(它是开源的)添加到我的应用程序中。 But if I connect to ICQ server though it, it will increase usage of CPU (up to 30%). 但是,即使我连接到ICQ服务器,也会增加CPU使用率(最多30%)。 So something in ICQ# library is using CPU so much. 因此,ICQ#库中的某些东西正在大量使用CPU。 But I don't know how to determinate what is it and reduce the usage of CPU. 但是我不知道如何确定它是什么,并减少CPU的使用。

If it's open source and you've added the code to your project; 如果它是开源的,并且您已将代码添加到您的项目中; run it with a profiler attached. 使用附加的探查器运行它。

The very simplest approach is this: 最简单的方法是:

  1. Run your program in the debugger. 在调试器中运行程序。
  2. And break into the debugger at some point. 并在某个时候进入调试器。
  3. Look at the call stack wherever you are 无论您身在何处,都可以查看调用堆栈
  4. repeat steps 2-3 重复步骤2-3

Doing this just two or three times gives you a very good idea of where most of your execution time is being spent. 只需执行两次或三次,就可以很好地了解大部分执行时间都花在了哪里。 If most of the execution time is spent in one function, then that function will be on the call stack nearly every time you break into the debugger. 如果大部分执行时间都花在一个函数上,那么几乎在您每次进入调试器时,该函数都将位于调用堆栈中。

I find it in 'icq_sharp\\IcqSharp.Util\\Timer.cs' file. 我在“ icq_sharp \\ IcqSharp.Util \\ Timer.cs”文件中找到它。 See function: private void DoWorker() . 参见函数: private void DoWorker() There is a loop without delay. 有一个没有延迟的循环。 Just add Thread.Sleep(10); 只需添加Thread.Sleep(10);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM