阅读CPU使用多核心CPU [英] Read CPU usage for multi core cpu

查看:270
本文介绍了阅读CPU使用多核心CPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用@ SZ codeR答案如何获得内存使用情况和CPU读取我的应用程序的CPU使用率使用android系统?的在这里SOF。

I been trying to read cpu usage in my application using the @szcoder answer to How to get Memory usage and CPU usage in android? here at SOF.

他的解决方案来对我的三星Galaxy S2(双核心CPU)工作,但它不工作对我的HTC One M7是四核。

His solution used to work on my Samsung Galaxy S2 (dual-core cpu), but its not working on my HTC One M7 which is quad core.

大部分的读数(来自@ SZ codeR法* 100即百分比CPU使用率值)或者是负面的,有些不足10%,很少有超过100%。

Most of the readings (Value from @szcoder's method*100 i.e percentage cpu usage) are either negative, some less than 10% and few are more than 100%.

在这个答案<一个评论href=\"http://stackoverflow.com/questions/3118234/how-to-get-memory-usage-and-cpu-usage-in-android#comment25095165_5560634\">Dave建议我们应该使用精确的数值多个读数。

In a comment to this answer Dave suggests that we should use multiple readings for accurate value.

能否有人请提出一个可能的解决这个问题呢?

Can some one please suggest a possible solution to this problem?

编辑:

我还试图用它使用费边纳普的解决方案顶-n 1 命令来确定CPU使用率,但在我的测试分析的/ proc / STAT 顶-n 1 (0.3xx秒昏迷$ p $向PD的3.xx秒),这样的情况下,有人建议它,我不会因为使用时间消耗的top命令。

I also tried to use Fabian Knapp's solution which uses top -n 1 command to determine the CPU usage but in my testing parsing /proc/stat is much faster than top -n 1 (0.3xx seconds comapred to 3.xx seconds) so in case some one suggests it, I won't be using the top command because of time consumption.

推荐答案

如果top命令给你正确的值,那么我建议你看一下Android的的来源$ C ​​$ C顶级并拔出你需要的CPU,这需要的时间比第二位。我可以说这个工程,因为我做到了一次。

If the top command gives you the correct value, then I suggest you look at Android's source code for top and pull out the bit you need for CPU, which takes less time than a second. I can say this works because I did it once.

这篇关于阅读CPU使用多核心CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆