如何衡量网络性能?

时间:2017-02-13 13:41:16

标签: android performance networking connection

我正在尝试创建一个在网络接口(wifi,3G)之间切换的应用程序。通过点击按钮来测量延迟,带宽等...

  • 测量连接质量(借记卡,带宽,延迟,抖动,丢失率......)

我已经启动了该应用:

public class myapp extends AppCompatActivity {
TextView TR; //latency text view 
Button ID_Collect;   //button 
long starttime, endtime;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_myapp);

    ID_Collect = (Button) findViewById(R.id.ID_Collect);
    TR = (TextView) findViewById(R.id.ID_TR);

    ID_Collect.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (executeCommand()) {

                TR.setText(String.valueOf(endtime-starttime));

               //TR.setText("success");

            } else {
                TR.setText(" Failure");
            }
        }
    });
}

private boolean executeCommand() {
    System.out.println("executeCommand");
    Runtime runtime = Runtime.getRuntime();
    try {
       starttime = System.currentTimeMillis();
        Process mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
        int mExitValue = mIpAddrProcess.waitFor();
       endtime = System.currentTimeMillis();

        //Debit=(8)/(endtime-starttime);
        //System.out.println(" mExitValue "+mExitValue);
        if (mExitValue == 0) {
            return true;

        } else {
            return false;
        }
    } catch (InterruptedException ignore) {
        ignore.printStackTrace();
        System.out.println(" Exception:" + ignore);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println(" Exception:" + e);
    }
    return false;
}
}

也许你有相关的经验,你想分享它?

0 个答案:

没有答案