做一个Android的FPS计数器 [英] Doing an Android FPS counter

查看:263
本文介绍了做一个Android的FPS计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做任何Android应用程序的FPS计数器。这意味着我没有源$ C ​​$ C为该应用程序(我不能修改或类似的东西,我只是有.apk文件)。

I'm trying to do an FPS counter for any Android app. That means I don't have the source code for that app (I can't modify it or anything like that, I just have the .apk).

我已经研究了很多这个,我发现只有有一个应用做这个(这就是所谓的游戏台,你可以找到它在谷歌播放),因此有可能以某种方式。当应用程序启动时,它已与所有手机上的游戏列表,你选择一个,游戏台自动启动并计算FPS。我需要一个类似的行为。

I've researched a lot into this and I've found only one app that does this (it's called Game Bench, you can find it on Google Play), so it is possible somehow. When the app starts, it has a list with all the games on your phone, you choose one and Game Bench automatically starts it and calculates the FPS. I need a similar behaviour.

现在,我所问的是,如果你们有至少我怎么能计算出一个应用程序的FPS(无需将其写入code)的想法。做研究,我发现了几个含糊不清的,如记录屏幕,并与systrace收集的数据计算FPS的视频,或以某种方式计算FPS。但在这两个点子有在互联网上很少的信息。

Now, what I am asking is, if any of you has at least an idea of how I could calculate the FPS of an app (without writing code in it). Doing research I found a few vague ones, like record the screen and calculate FPS of the video, or somehow calculate the FPS using data collected with systrace. But on both these "ideas" there is very few info on the internet.

所以,请,如果你们有这件事/创意/意见的任何信息,我会很高兴听到他们的声音。谢谢!

So please, if you guys have any information about this matter/ ideas/ opinions, I'll be happy to hear them. Thanks!

推荐答案

这是我会怎么板凳FPS使用表面观的一个例子。
看看Run方法来看看FPS如何工作的。

This is an example of how I would bench FPS using a Surface View. Look at the Run method to see how the FPS works.

1:我们得到时间更新前和渲染到屏幕上。

1: We get the time before update and render to the screen.

2,一切准备工作完成后,我们再次获取时间。

2: After all work is done we get the time again.

3:1000毫秒是第二个和40 FPS是常态。

3: 1000 milliseconds is a second and 40 FPS is the norm.

4:elaspedTime =的startTime - 结束时间;

4: elaspedTime = startTime - endTime;

5:所以,如果elaspedTime是25岁以下则其在-至少做40 FPS。

5: So if elaspedTime is under 25 then its at-least doing 40 FPS.

6:如果elaspedTime = 5毫秒,然后它做五分之千= 200 FPS

6: If elaspedTime = 5 milliseconds then its doing 1000 / 5 = 200 FPS

7:你可以睡上几毫秒线程,如果你正在运行在同一线程上的更新和渲染。你不更新很多次这样的话。

7: You can sleep the thread for a couple milliseconds if you are running the updater and renderer on the same thread. That way you're not updating to many times.

8:希望它可以帮助这个类是基本的游戏类,保持了游戏的运行和40 fps的,即使他们是在一个星系运行它那6.你想使自己的必要的修改,以更多的调整它

8: Hope it helps this class is a basic game class that keeps the game running and 40 fps even if they are running it on a Galaxy S 6. You would want to make your own necessary changes to tweak it more.

public class MySurfaceView extends SurfaceView implements Runnable {
    long time = 0, nextGameTick = 0;
    SurfaceHolder myHolder;
    Thread myThread = null;
    boolean myRunning = false;

    public MySurfaceView(Context context) {
        super(context);
        myHolder = getHolder();
    }

    @Override
    public void run() {
        while (myRunning) {
            nextGameTick = System.currentTimeMillis();
            if (!myHolder.getSurface().isValid())
                continue;
            Update();
            Render();
            time = nextGameTick - System.currentTimeMillis();
            time = (time <= 0) ? 1 : time;
            if (time <= 25)
                sleepThread(25 - time);
            Log.d("FrameRate", String.valueOf(1000 / time));
        }
    }

    public void pause() {
        myRunning = false;
        while (true) {
            try {
                myThread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            break;
        }
        myThread = null;
    }

    public void resume() {
        myRunning = true;
        myThread = new Thread(this);
        myThread.start();
    }

    public void sleepThread(long time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private void Render() {
        // TODO Render to Screen
    }

    private void Update() {
        // TODO Update
    }
}

这篇关于做一个Android的FPS计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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