安卓:getElapsedCpuTime返回较小毫秒 [英] Android: getElapsedCpuTime returns lesser milliseconds

查看:944
本文介绍了安卓:getElapsedCpuTime返回较小毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关getElapsedCpuTime()的Andr​​oid文档状态


  

返回经过这个过程已经运行的时间毫秒。


我()尝试使用getElapsedCpuTime,以毫秒为单位的时间是相当混乱。许多(4至5)秒后,返回的经过时间是只是2000的东西。无论它比原来的毫秒(1000 1秒),或者我在正确的理解有问题,慢?

我只是测试,以获得当前的CPU运行时间上的每个按钮的点击,这里的code:

 公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.build_data_view);    按钮BTN =(按钮)findViewById(R.id.refresh);
    btn.setOnClickListener(新OnClickListener(){        @覆盖
        公共无效的onClick(视图v){
            字符串elapsedCpuTime = android.os.Process.getElapsedCpuTime()
                    +;
            ((的TextView)findViewById(R.id.build_data))
                    .setText(elapsedCpuTime);        }
    });}


它sugest计算的时间的名称

解决方案

是CPU时间为止进程已经度过。如果......你半小时前开始的过程中,它可能只是花费的CPU时间三秒钟。在API http://developer.android.com/reference/android/os/ Process.html 的,他们说,这是该进程beeing运行时间,有效时间必须。因此,只有时间花费在了CPU和自实例化的过程没有时间ellapsed。

添加的AsyncTask 在做什么,但,而(真)键,系统就会显示所花的时间线性增长,但不是的ellapsed时间的100%,因为你的PROC只会有其市场份额。

Android documentation states about getElapsedCpuTime() that

Returns elapsed milliseconds of the time this process has run.

I tried using getElapsedCpuTime(), the time in milliseconds is quite confusing. After many (4 to 5) seconds, the elapsed time returned is just 2000 something. Either it is slower than original milliseconds (1000 in 1 sec) or I am having issue in proper understanding?

I'm simply testing to get current cpu elapsed time on each button click, here's the code:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.build_data_view);

    Button btn = (Button) findViewById(R.id.refresh);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String elapsedCpuTime = android.os.Process.getElapsedCpuTime()
                    + "";
            ((TextView) findViewById(R.id.build_data))
                    .setText(elapsedCpuTime);

        }
    });

}

解决方案

in the name it sugest the time counted is the CPU time the process has spent so far. If you´ve started the process half an hour ago it may have just spent three seconds of CPU time. In the API http://developer.android.com/reference/android/os/Process.html they say it is the time the process is beeing running, effective time must be. So only the time spent in CPU and not the time ellapsed since process instantiation.

Add an Asynctask doing nothing but while(true) and you´ll see the time spent growing linearly but not as 100% of the ellapsed time because your proc will only have its share.

这篇关于安卓:getElapsedCpuTime返回较小毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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