获取帧率

    //获取帧率
    public static String getgfx(String packagename) throws IOException
    {
        Process process=Runtime.getRuntime().exec("adb shell dumpsys gfxinfo "+packagename);
        BufferedReader br=new BufferedReader(new InputStreamReader(process.getInputStream()));
        String str;
        int dropf=0;
        int allgfx=0;

        while((str=br.readLine())!=null)
        {  
            Pattern p=Pattern.compile("^[^a-zA-Z]\\d+\\.\\d+");
            Matcher m=p.matcher(str);
           
            float total1=0;
            int mult;
                if(m.find())
                {   
                    allgfx++;
                    System.out.println(str);
                    for(int i=0;i<4;i++)
                    {              
                    total1+=Float.parseFloat(str.trim().split("    ")[i]);
    
                    }

                    if((mult=(int) (total1/16.67))>0)
                    {   
                        for(int i=mult;i>0;i--)
                        {
                            dropf++;
                        }
                        
                    }
                        
                }
                

        }
        //计算帆帧率
        float percent1;
        percent1=(float)allgfx/(allgfx+dropf);
        System.out.println("总共执行了"+allgfx+"帧,掉了"+dropf+"帧");
        System.out.println("帧率百分比为:"+percent1);
        DecimalFormat df = new DecimalFormat("0.0");
        String s=df.format(percent1*60);
                
        return s;
        
       
    
        
    }

 

posted @ 2016-08-29 15:05  红红的测试之路  阅读(383)  评论(0编辑  收藏  举报