correct threads for all TX java
This commit is contained in:
parent
d18c91e2db
commit
b9744e8caa
|
|
@ -31,6 +31,7 @@ import java.util.Date;
|
|||
public class MainActivity extends Activity {
|
||||
// unchanged stuff
|
||||
protected static final String remoteIP = "128.111.68.220";
|
||||
protected static final String remoteMAC = "18:03:73:c8:86:52";
|
||||
protected static final String sshlinklab = "ssh linklab@hotcrp.cs.ucsb.edu"
|
||||
+ " -i /data/.ssh/id_rsa -o StrictHostKeyChecking=no";
|
||||
protected static final String sshlinklablocal = "ssh linklab@" + remoteIP
|
||||
|
|
@ -64,11 +65,12 @@ public class MainActivity extends Activity {
|
|||
protected static int UDPfinishTime = 0;
|
||||
protected static double reportedFinishTime = 0.0;
|
||||
protected static int repeatCounts = 3;
|
||||
protected static int bytes2send = 10*oneMB; // default 10MB
|
||||
protected static int bytes2send = 10 * oneMB; // default 10MB
|
||||
protected static int currentBandwidth = -1; // bps, default is -1, indicating unlimited
|
||||
protected static TextView txt_results;
|
||||
protected static Handler myHandler;
|
||||
protected static String myInetIP = "";
|
||||
protected static String myMAC = "";
|
||||
protected static String RXportNum = "4444";
|
||||
protected static String outFolderPath;
|
||||
protected static String btn_click_time;
|
||||
|
|
@ -469,7 +471,7 @@ public class MainActivity extends Activity {
|
|||
commd[2] = "cd " + outFolderPath + " && mv *" + btn_click_time
|
||||
+ "* " + existedItems[selectedItems.get(j)] + "/";
|
||||
Runtime.getRuntime().exec(commd).waitFor();
|
||||
Log.d(TAG, "Finished " + (currentBandwidth / 1000000.0) + "MBps, "
|
||||
Log.d(TAG, "Finished " + (currentBandwidth / 1000000.0) + "Mbps, "
|
||||
+ i + "th repeat on " + existedItems[selectedItems.get(j)]
|
||||
+ ", t="+reportedFinishTime+"ms");
|
||||
Thread.sleep(5000);
|
||||
|
|
@ -569,23 +571,22 @@ public class MainActivity extends Activity {
|
|||
// grab WiFi service and check if wifi is enabled
|
||||
wm = (WifiManager) this.getSystemService(WIFI_SERVICE);
|
||||
isUsingWifi = (wm.isWifiEnabled()) ? true : false;
|
||||
if (isUsingWifi) {
|
||||
myInetIP = Utilities.getInetIP(true);
|
||||
}
|
||||
Utilities.getSelfIdentity(tcpdumpInterface, true);
|
||||
// predefined selections
|
||||
existedItems = new CharSequence[] {
|
||||
"Socket_Normal", "Socket_NormalUDP", "Socket_Sendfile",
|
||||
"Socket_Splice", "RawSocket_Normal"
|
||||
};
|
||||
existedItemsThrpt = new CharSequence[]{
|
||||
"50KB", "100KB", "250KB", "0.5MB", "0.75MB", "1MB", "1.5MB", "2MB", // 0-7
|
||||
"2.5MB", "3MB", "3.5MB", "4MB", "4.5MB", "5MB", "5.5MB", "6MB", // 8-15
|
||||
"6.5MB", "7MB", "7.5MB", "8MB", "8.5MB", "9MB", "9.5MB", "10MB", // 16-23
|
||||
"Unlimited", // 24
|
||||
"15MB", "20MB", "25MB", "30MB", "35MB", "40MB", "45MB", "50MB", // 25-32
|
||||
"55MB", "60MB", "65MB", "70MB", "75MB", "80MB", "85MB", "90MB", // 33-40
|
||||
"95MB", "100MB", // 41-42
|
||||
"11MB", "13MB" // 43-44
|
||||
"800Mbps", "760Mbps", "720Mbps", "680Mbps", "640Mbps", "600Mbps", "560Mbps",// 0-6
|
||||
"520Mbps", "480Mbps", "440Mbps", "400Mbps", "360Mbps", "320Mbps", "280Mbps",// 7-13
|
||||
"240Mbps", "200Mbps", "160Mbps", "120Mbps", "80Mbps", // 14-18
|
||||
"76Mbps", "72Mbps", "68Mbps", "64Mbps", "60Mbps", "56Mbps", "52Mbps", // 19-25
|
||||
"48Mbps", "44Mbps", "40Mbps", "36Mbps", "32Mbps", "28Mbps", "24Mbps", // 26-32
|
||||
"20Mbps", "16Mbps", "12Mbps", "8Mbps", // 33-36
|
||||
"6Mbps", "5Mbps", "4Mbps", "3Mbps", "2Mbps", "1Mbps", // 37-42
|
||||
"800Kbps", "600Kbps", "400Kbps", "200Kbps", // 43-46
|
||||
"Unlimited", // 47
|
||||
};
|
||||
// binary executables to run
|
||||
binary_TX_Normal = "client_send_normaltcp";
|
||||
|
|
@ -750,6 +751,8 @@ public class MainActivity extends Activity {
|
|||
if (isVerbose) {
|
||||
Log.d(TAG, "TCPDump interface is set to " + tcpdumpInterface);
|
||||
}
|
||||
// based on the selected interface, get corresponding IP and MAC address
|
||||
Utilities.getSelfIdentity(tcpdumpInterface, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -779,21 +782,10 @@ public class MainActivity extends Activity {
|
|||
break;
|
||||
case 1:
|
||||
isLocal = isChecked;
|
||||
// binary_TX_Normal = isLocal ? "normal_lo" : "normal";
|
||||
// binary_TX_NormalUDP = isLocal ? "normal_udp_lo" : "normal_udp";
|
||||
// binary_TX_Sendfile = isLocal ? "sendfile_lo" : "sendfile";
|
||||
// binary_TX_Splice = isLocal ? "splice_lo" : "splice";
|
||||
// binary_TX_RawNormal = isLocal ? "bypassl3_lo" : "bypassl3";
|
||||
// binary_RX_Normal = isLocal ? "normal_recv_lo" : "normal_recv";
|
||||
// binary_RX_NormalUDP =
|
||||
// isLocal ? "normal_udp_recv_lo" : "normal_udp_recv";
|
||||
// binary_RX_Splice = isLocal ? "splice_recv_lo" : "splice_recv";
|
||||
// binary_RX_RawNormal =
|
||||
// isLocal ? "bypassl3_recv_lo" : "bypassl3_recv";
|
||||
if (isLocal) {
|
||||
isUsingTCPDump = false;
|
||||
Toast.makeText(MainActivity.this,
|
||||
"Remember to set IP to 192.168.1.15\n"
|
||||
Toast.makeText(MainActivity.this, ""
|
||||
// "Remember to set IP to 192.168.1.15\n"
|
||||
+ "Will start locally\n"
|
||||
+ "tcpdump disabled", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -48,10 +48,11 @@ public class SSLogger extends Service {
|
|||
// read current cpu usage
|
||||
readUsage(raws);
|
||||
String myTmp = mTime + " " + raws[0] + " ";
|
||||
for (int i = 0; i < MainActivity.coreNum-1; ++i) {
|
||||
for (int i = 0; i < MainActivity.coreNum - 1; ++i) {
|
||||
myTmp += raws[i+1] + " " + cpuFrequency(i) + " ";
|
||||
}
|
||||
myTmp += raws[MainActivity.coreNum] + " " + cpuFrequency(MainActivity.coreNum-1) + "\n";
|
||||
myTmp += raws[MainActivity.coreNum] + " "
|
||||
+ cpuFrequency(MainActivity.coreNum - 1) + "\n";
|
||||
// // cpuTotal
|
||||
// String[] cpuTotal = raws[0].split("\\s+");
|
||||
// String cpuTotalsum = parseProcStat(cpuTotal);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.io.InputStreamReader;
|
|||
* Created by yanzi on 9/18/15.
|
||||
* Updated on 01/25/17
|
||||
*/
|
||||
|
||||
public class Thread_TX_CNormal implements Runnable {
|
||||
private double sentBytes = 0.0;
|
||||
private double duration = 0.0;
|
||||
|
|
|
|||
|
|
@ -2,13 +2,21 @@ package edu.ucsb.cs.sandlab.offloadingdemo;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Created by yanzi on 9/18/15.
|
||||
* Updated on 01/25/17
|
||||
*/
|
||||
|
||||
public class Thread_TX_CNormalUDP implements Runnable {
|
||||
private double sentBytes = 0.0;
|
||||
private double duration = 0.0;
|
||||
private double throughput = 0.0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (MainActivity.isRunning_TX_NormalUDP)
|
||||
|
|
@ -18,48 +26,103 @@ public class Thread_TX_CNormalUDP implements Runnable {
|
|||
MainActivity.isRunning_TX_NormalUDP = true;
|
||||
Process proc;
|
||||
String[] commd = new String[3];
|
||||
|
||||
// get the right command
|
||||
commd[0] = "su";
|
||||
commd[1] = "-c";
|
||||
// ./client_send_normaludp <bytes2send/file2send> <ip> <port>
|
||||
// <[optional] bandwidth (bps)> <[optional] sendsize (bytes)>
|
||||
commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
||||
+ MainActivity.binaryFolderPath + MainActivity.binary_TX_NormalUDP + " "
|
||||
+ MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
||||
+ MainActivity.bytes2send + " "
|
||||
+ (MainActivity.isLocal ? MainActivity.myInetIP : MainActivity.remoteIP) + " "
|
||||
+ MainActivity.RXportNum + " "
|
||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||
MainActivity.currentBandwidth));
|
||||
|
||||
try {
|
||||
// run process
|
||||
proc = Runtime.getRuntime().exec(commd);
|
||||
|
||||
// if config to log per process
|
||||
while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||
// Log.d("Thread_TX_CNormalUDP", "per proc: " + MainActivity.perProcPID);
|
||||
MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_NormalUDP, false);
|
||||
}
|
||||
proc.waitFor();
|
||||
InputStream stdout = proc.getInputStream();
|
||||
byte[] buffer = new byte[20];
|
||||
int read;
|
||||
StringBuilder out = new StringBuilder();
|
||||
while(true){
|
||||
read = stdout.read(buffer);
|
||||
if(read<0){
|
||||
|
||||
|
||||
// read error
|
||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getErrorStream()));
|
||||
final String error = error_buf.readLine(); // only one line error
|
||||
|
||||
// read std out
|
||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getInputStream()));
|
||||
String stdout;
|
||||
|
||||
// get sent bytes
|
||||
stdout = stdout_buf.readLine();
|
||||
if (stdout == null) {
|
||||
// error happens
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Failed in TX_NormalUDP\n");
|
||||
MainActivity.txt_results.append("Err in TX_NormalUDP: " + error + "\n");
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
out.append(new String(buffer, 0, read));
|
||||
if(read<20){
|
||||
break;
|
||||
}
|
||||
}
|
||||
final String mOut = out.toString().trim();
|
||||
MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
} else {
|
||||
// sent bytes
|
||||
sentBytes = Utilities.parseBinOutput(stdout);
|
||||
|
||||
// duration
|
||||
stdout = stdout_buf.readLine();
|
||||
duration = Utilities.parseBinOutput(stdout);
|
||||
MainActivity.reportedFinishTime = duration;
|
||||
if (MainActivity.isVerbose) {
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
MainActivity.txt_results.append("Time: " + duration + "ms\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// throughput
|
||||
stdout = stdout_buf.readLine();
|
||||
throughput = Utilities.parseBinOutput(stdout);
|
||||
}
|
||||
//
|
||||
// InputStream stdout = proc.getInputStream();
|
||||
// byte[] buffer = new byte[20];
|
||||
// int read;
|
||||
// StringBuilder out = new StringBuilder();
|
||||
// while(true){
|
||||
// read = stdout.read(buffer);
|
||||
// if(read<0){
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Failed in TX_NormalUDP\n");
|
||||
// }
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// out.append(new String(buffer, 0, read));
|
||||
// if(read<20){
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// final String mOut = out.toString().trim();
|
||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
// if (MainActivity.isVerbose) {
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,20 @@ package edu.ucsb.cs.sandlab.offloadingdemo;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Created by yanzi on 9/19/15.
|
||||
*/
|
||||
|
||||
public class Thread_TX_CRawNormal implements Runnable {
|
||||
private double sentBytes = 0.0;
|
||||
private double duration = 0.0;
|
||||
private double throughput = 0.0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (MainActivity.isRunning_TX_RawNormal)
|
||||
|
|
@ -18,47 +25,101 @@ public class Thread_TX_CRawNormal implements Runnable {
|
|||
MainActivity.isRunning_TX_RawNormal = true;
|
||||
Process proc;
|
||||
String[] commd = new String[3];
|
||||
|
||||
// get the right command
|
||||
commd[0] = "su";
|
||||
commd[1] = "-c";
|
||||
// ./client_send_bypassl3 <bytes2send/file2send> <dest MAC address>
|
||||
// <[optional] bandwidth (bps)> <[optional] sendsize (bytes)> <[optional] interface>
|
||||
commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
||||
+ MainActivity.binaryFolderPath + MainActivity.binary_TX_RawNormal + " "
|
||||
+ MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
||||
+ MainActivity.bytes2send + " "
|
||||
+ (MainActivity.isLocal ? MainActivity.myMAC : MainActivity.remoteMAC) + " "
|
||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||
MainActivity.currentBandwidth));
|
||||
|
||||
try {
|
||||
// run process
|
||||
proc = Runtime.getRuntime().exec(commd);
|
||||
|
||||
// if config to log per process
|
||||
while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||
MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_RawNormal, false);
|
||||
}
|
||||
proc.waitFor();
|
||||
InputStream stdout = proc.getInputStream();
|
||||
byte[] buffer = new byte[20];
|
||||
int read;
|
||||
StringBuilder out = new StringBuilder();
|
||||
while(true){
|
||||
read = stdout.read(buffer);
|
||||
if(read<0){
|
||||
|
||||
// read error
|
||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getErrorStream()));
|
||||
final String error = error_buf.readLine(); // only one line error
|
||||
|
||||
// read std out
|
||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getInputStream()));
|
||||
String stdout;
|
||||
|
||||
// get sent bytes
|
||||
stdout = stdout_buf.readLine();
|
||||
if (stdout == null) {
|
||||
// error happens
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Failed in TX_RawNormal\n");
|
||||
MainActivity.txt_results.append("Err in TX_RawNormal: " + error + "\n");
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
out.append(new String(buffer, 0, read));
|
||||
if(read<20){
|
||||
break;
|
||||
}
|
||||
}
|
||||
final String mOut = out.toString().trim();
|
||||
MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
} else {
|
||||
// sent bytes
|
||||
sentBytes = Utilities.parseBinOutput(stdout);
|
||||
|
||||
// duration
|
||||
stdout = stdout_buf.readLine();
|
||||
duration = Utilities.parseBinOutput(stdout);
|
||||
MainActivity.reportedFinishTime = duration;
|
||||
if (MainActivity.isVerbose) {
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
MainActivity.txt_results.append("Time: " + duration + "ms\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// throughput
|
||||
stdout = stdout_buf.readLine();
|
||||
throughput = Utilities.parseBinOutput(stdout);
|
||||
}
|
||||
|
||||
// InputStream stdout = proc.getInputStream();
|
||||
// byte[] buffer = new byte[20];
|
||||
// int read;
|
||||
// StringBuilder out = new StringBuilder();
|
||||
// while(true){
|
||||
// read = stdout.read(buffer);
|
||||
// if(read<0){
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Failed in TX_RawNormal\n");
|
||||
// }
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// out.append(new String(buffer, 0, read));
|
||||
// if(read<20){
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// final String mOut = out.toString().trim();
|
||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
// if (MainActivity.isVerbose) {
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,21 @@ package edu.ucsb.cs.sandlab.offloadingdemo;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Created by yanzi on 9/18/15.
|
||||
* Updated on 01/25/17
|
||||
*/
|
||||
|
||||
public class Thread_TX_CRawSplice implements Runnable {
|
||||
private double sentBytes = 0.0;
|
||||
private double duration = 0.0;
|
||||
private double throughput = 0.0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (MainActivity.isRunning_TX_RawSplice)
|
||||
|
|
@ -18,47 +26,107 @@ public class Thread_TX_CRawSplice implements Runnable {
|
|||
MainActivity.isRunning_TX_RawSplice = true;
|
||||
Process proc;
|
||||
String[] commd = new String[3];
|
||||
|
||||
// get the right command
|
||||
commd[0] = "su";
|
||||
commd[1] = "-c";
|
||||
// ./client_send_bypassl3_splice <bytes2send/file2send> <ip> <port>
|
||||
// <[optional] bandwidth (bps)> <[optional] sendsize (bytes)>
|
||||
commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
||||
+ MainActivity.binaryFolderPath + MainActivity.binary_TX_RawSplice + " "
|
||||
+ MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
||||
+ MainActivity.bytes2send + " "
|
||||
+ (MainActivity.isLocal ? MainActivity.myInetIP : MainActivity.remoteIP) + " "
|
||||
+ MainActivity.RXportNum + " "
|
||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||
MainActivity.currentBandwidth));
|
||||
|
||||
try {
|
||||
// run process
|
||||
proc = Runtime.getRuntime().exec(commd);
|
||||
|
||||
// if config to log per process
|
||||
while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||
MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_RawSplice, false);
|
||||
}
|
||||
proc.waitFor();
|
||||
InputStream stdout = proc.getInputStream();
|
||||
byte[] buffer = new byte[20];
|
||||
int read;
|
||||
StringBuilder out = new StringBuilder();
|
||||
while(true){
|
||||
read = stdout.read(buffer);
|
||||
if(read<0){
|
||||
|
||||
// read error
|
||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getErrorStream()));
|
||||
final String error = error_buf.readLine(); // only one line error
|
||||
|
||||
// read std out
|
||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getInputStream()));
|
||||
String stdout;
|
||||
|
||||
// get sent bytes
|
||||
stdout = stdout_buf.readLine();
|
||||
if (stdout == null) {
|
||||
// error happens
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Failed in TX_RawSplice\n");
|
||||
MainActivity.txt_results.append("Err in TX_Raw_Splice: " + error + "\n");
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
out.append(new String(buffer, 0, read));
|
||||
if(read<20){
|
||||
break;
|
||||
}
|
||||
}
|
||||
final String mOut = out.toString().trim();
|
||||
MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
} else {
|
||||
// sent bytes
|
||||
sentBytes = Utilities.parseBinOutput(stdout);
|
||||
|
||||
// duration
|
||||
stdout = stdout_buf.readLine();
|
||||
duration = Utilities.parseBinOutput(stdout);
|
||||
MainActivity.reportedFinishTime = duration;
|
||||
if (MainActivity.isVerbose) {
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
MainActivity.txt_results.append("Time: " + duration + "ms\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// throughput
|
||||
stdout = stdout_buf.readLine();
|
||||
throughput = Utilities.parseBinOutput(stdout);
|
||||
}
|
||||
|
||||
// proc = Runtime.getRuntime().exec(commd);
|
||||
// while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||
// MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_RawSplice, false);
|
||||
// }
|
||||
// proc.waitFor();
|
||||
// InputStream stdout = proc.getInputStream();
|
||||
// byte[] buffer = new byte[20];
|
||||
// int read;
|
||||
// StringBuilder out = new StringBuilder();
|
||||
// while(true){
|
||||
// read = stdout.read(buffer);
|
||||
// if(read<0){
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Failed in TX_RawSplice\n");
|
||||
// }
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// out.append(new String(buffer, 0, read));
|
||||
// if(read<20){
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// final String mOut = out.toString().trim();
|
||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
// if (MainActivity.isVerbose) {
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,20 @@ package edu.ucsb.cs.sandlab.offloadingdemo;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Created by yanzi on 9/19/15.
|
||||
* Updated on 01/25/17
|
||||
*/
|
||||
public class Thread_TX_CSendfile implements Runnable {
|
||||
private double sentBytes = 0.0;
|
||||
private double duration = 0.0;
|
||||
private double throughput = 0.0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (MainActivity.isRunning_TX_Sendfile)
|
||||
|
|
@ -18,47 +25,114 @@ public class Thread_TX_CSendfile implements Runnable {
|
|||
MainActivity.isRunning_TX_Sendfile = true;
|
||||
Process proc;
|
||||
String[] commd = new String[3];
|
||||
|
||||
// get the right command
|
||||
commd[0] = "su";
|
||||
commd[1] = "-c";
|
||||
// ./client_send_normaltcp_sendfile <bytes2send/file2send> <ip> <port>
|
||||
// <[optional] bandwidth (bps)> <[optional] sendsize (bytes)>
|
||||
commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
||||
+ MainActivity.binaryFolderPath + MainActivity.binary_TX_Sendfile + " "
|
||||
+ MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
||||
+ MainActivity.bytes2send + " "
|
||||
+ (MainActivity.isLocal ? MainActivity.myInetIP : MainActivity.remoteIP) + " "
|
||||
+ MainActivity.RXportNum + " "
|
||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||
MainActivity.currentBandwidth));
|
||||
|
||||
try {
|
||||
// run process
|
||||
proc = Runtime.getRuntime().exec(commd);
|
||||
|
||||
// if config to log per process
|
||||
while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||
MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_Sendfile, false);
|
||||
MainActivity.perProcPID = Utilities.getMyPID(
|
||||
MainActivity.binary_TX_Sendfile, false);
|
||||
}
|
||||
proc.waitFor();
|
||||
InputStream stdout = proc.getInputStream();
|
||||
byte[] buffer = new byte[20];
|
||||
int read;
|
||||
StringBuilder out = new StringBuilder();
|
||||
while(true){
|
||||
read = stdout.read(buffer);
|
||||
if(read<0){
|
||||
|
||||
// read error
|
||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getErrorStream()));
|
||||
final String error = error_buf.readLine(); // only one line error
|
||||
|
||||
// read std out
|
||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getInputStream()));
|
||||
String stdout;
|
||||
|
||||
// get sent bytes
|
||||
stdout = stdout_buf.readLine();
|
||||
if (stdout == null) {
|
||||
// error happens
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Failed in TX_Sendfile\n");
|
||||
MainActivity.txt_results.append("Err in TX_Normal_Splice: " + error + "\n");
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
out.append(new String(buffer, 0, read));
|
||||
if(read<20){
|
||||
break;
|
||||
}
|
||||
}
|
||||
final String mOut = out.toString().trim();
|
||||
MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
} else {
|
||||
// sent bytes
|
||||
sentBytes = Utilities.parseBinOutput(stdout);
|
||||
|
||||
// duration
|
||||
stdout = stdout_buf.readLine();
|
||||
duration = Utilities.parseBinOutput(stdout);
|
||||
MainActivity.reportedFinishTime = duration;
|
||||
if (MainActivity.isVerbose) {
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
MainActivity.txt_results.append("Time: " + duration + "ms\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// throughput
|
||||
stdout = stdout_buf.readLine();
|
||||
throughput = Utilities.parseBinOutput(stdout);
|
||||
}
|
||||
|
||||
// commd[0] = "su";
|
||||
// commd[1] = "-c";
|
||||
// commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
||||
// + MainActivity.binaryFolderPath + MainActivity.binary_TX_Sendfile + " "
|
||||
// + MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
||||
// try {
|
||||
// proc = Runtime.getRuntime().exec(commd);
|
||||
// while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||
// MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_Sendfile, false);
|
||||
// }
|
||||
// proc.waitFor();
|
||||
// InputStream stdout = proc.getInputStream();
|
||||
// byte[] buffer = new byte[20];
|
||||
// int read;
|
||||
// StringBuilder out = new StringBuilder();
|
||||
// while(true){
|
||||
// read = stdout.read(buffer);
|
||||
// if(read<0){
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Failed in TX_Sendfile\n");
|
||||
// }
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// out.append(new String(buffer, 0, read));
|
||||
// if(read<20){
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// final String mOut = out.toString().trim();
|
||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
// if (MainActivity.isVerbose) {
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,20 @@ package edu.ucsb.cs.sandlab.offloadingdemo;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Created by yanzi on 9/18/15.
|
||||
* Updated on 01/25/17
|
||||
*/
|
||||
public class Thread_TX_CSplice implements Runnable {
|
||||
private double sentBytes = 0.0;
|
||||
private double duration = 0.0;
|
||||
private double throughput = 0.0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (MainActivity.isRunning_TX_Splice)
|
||||
|
|
@ -18,47 +25,113 @@ public class Thread_TX_CSplice implements Runnable {
|
|||
MainActivity.isRunning_TX_Splice = true;
|
||||
Process proc;
|
||||
String[] commd = new String[3];
|
||||
|
||||
// get the right command
|
||||
commd[0] = "su";
|
||||
commd[1] = "-c";
|
||||
// ./client_send_normaltcp_splice <bytes2send/file2send> <ip> <port>
|
||||
// <[optional] bandwidth (bps)> <[optional] sendsize (bytes)>
|
||||
commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
||||
+ MainActivity.binaryFolderPath + MainActivity.binary_TX_Splice + " "
|
||||
+ MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
||||
+ MainActivity.bytes2send + " "
|
||||
+ (MainActivity.isLocal ? MainActivity.myInetIP : MainActivity.remoteIP) + " "
|
||||
+ MainActivity.RXportNum + " "
|
||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||
MainActivity.currentBandwidth));
|
||||
|
||||
try {
|
||||
// run process
|
||||
proc = Runtime.getRuntime().exec(commd);
|
||||
|
||||
// if config to log per process
|
||||
while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||
MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_Splice, false);
|
||||
}
|
||||
proc.waitFor();
|
||||
InputStream stdout = proc.getInputStream();
|
||||
byte[] buffer = new byte[20];
|
||||
int read;
|
||||
StringBuilder out = new StringBuilder();
|
||||
while(true){
|
||||
read = stdout.read(buffer);
|
||||
if(read<0){
|
||||
|
||||
// read error
|
||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getErrorStream()));
|
||||
final String error = error_buf.readLine(); // only one line error
|
||||
|
||||
// read std out
|
||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
||||
proc.getInputStream()));
|
||||
String stdout;
|
||||
|
||||
// get sent bytes
|
||||
stdout = stdout_buf.readLine();
|
||||
if (stdout == null) {
|
||||
// error happens
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Failed in TX_Splice\n");
|
||||
MainActivity.txt_results.append("Err in TX_Normal_Splice: " + error + "\n");
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
out.append(new String(buffer, 0, read));
|
||||
if(read<20){
|
||||
break;
|
||||
}
|
||||
}
|
||||
final String mOut = out.toString().trim();
|
||||
MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
} else {
|
||||
// sent bytes
|
||||
sentBytes = Utilities.parseBinOutput(stdout);
|
||||
|
||||
// duration
|
||||
stdout = stdout_buf.readLine();
|
||||
duration = Utilities.parseBinOutput(stdout);
|
||||
MainActivity.reportedFinishTime = duration;
|
||||
if (MainActivity.isVerbose) {
|
||||
MainActivity.myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
MainActivity.txt_results.append("Time: " + duration + "ms\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// throughput
|
||||
stdout = stdout_buf.readLine();
|
||||
throughput = Utilities.parseBinOutput(stdout);
|
||||
}
|
||||
|
||||
// commd[0] = "su";
|
||||
// commd[1] = "-c";
|
||||
// commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
||||
// + MainActivity.binaryFolderPath + MainActivity.binary_TX_Splice + " "
|
||||
// + MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
||||
// try {
|
||||
// proc = Runtime.getRuntime().exec(commd);
|
||||
// while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||
// MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_Splice, false);
|
||||
// }
|
||||
// proc.waitFor();
|
||||
// InputStream stdout = proc.getInputStream();
|
||||
// byte[] buffer = new byte[20];
|
||||
// int read;
|
||||
// StringBuilder out = new StringBuilder();
|
||||
// while(true){
|
||||
// read = stdout.read(buffer);
|
||||
// if(read<0){
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Failed in TX_Splice\n");
|
||||
// }
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// out.append(new String(buffer, 0, read));
|
||||
// if(read<20){
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// final String mOut = out.toString().trim();
|
||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
||||
// if (MainActivity.isVerbose) {
|
||||
// MainActivity.myHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -36,10 +38,9 @@ public class Utilities {
|
|||
};
|
||||
|
||||
/**
|
||||
* Android 6.0 + required
|
||||
* Checks if the app has permission to write to device storage
|
||||
*
|
||||
* If the app does not has permission then the user will be prompted to grant permissions
|
||||
*
|
||||
* @param activity
|
||||
*/
|
||||
public static void verifyStoragePermissions(Activity activity) {
|
||||
|
|
@ -47,8 +48,8 @@ public class Utilities {
|
|||
int permission = ActivityCompat.checkSelfPermission(
|
||||
activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
// We don't have permission so prompt the user
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(
|
||||
activity,
|
||||
PERMISSIONS_STORAGE,
|
||||
|
|
@ -71,35 +72,58 @@ public class Utilities {
|
|||
}
|
||||
|
||||
/**
|
||||
* get the ip address
|
||||
* @return str
|
||||
* get the ip and mac addresses
|
||||
*/
|
||||
protected static String getInetIP(boolean useIPv4) {
|
||||
protected static void getSelfIdentity(String interface_name, boolean useIPv4) {
|
||||
try {
|
||||
List<NetworkInterface> interfaces = Collections.list(
|
||||
NetworkInterface.getNetworkInterfaces());
|
||||
for (NetworkInterface intf : interfaces) {
|
||||
List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
|
||||
for (InetAddress addr : addrs) {
|
||||
if (!addr.isLoopbackAddress()) {
|
||||
String sAddr = addr.getHostAddress();
|
||||
//boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
|
||||
boolean isIPv4 = sAddr.indexOf(':')<0;
|
||||
Enumeration<NetworkInterface> networks =
|
||||
NetworkInterface.getNetworkInterfaces();
|
||||
|
||||
while (networks.hasMoreElements()) {
|
||||
NetworkInterface network = networks.nextElement();
|
||||
|
||||
// check if the interface matches the desired one
|
||||
String name = network.getDisplayName();
|
||||
if (!name.equals(interface_name))
|
||||
continue;
|
||||
|
||||
// get the ip address
|
||||
Enumeration<InetAddress> inetAddresses = network.getInetAddresses();
|
||||
while (inetAddresses.hasMoreElements()) {
|
||||
InetAddress inetAddress = inetAddresses.nextElement();
|
||||
if (!inetAddress.isLoopbackAddress()) {
|
||||
String sAddr = inetAddress.getHostAddress();
|
||||
boolean isIPv4 = sAddr.indexOf(':') < 0;
|
||||
// check if we only want ipv4
|
||||
if (useIPv4) {
|
||||
if (isIPv4)
|
||||
return sAddr;
|
||||
MainActivity.myInetIP = sAddr;
|
||||
} else {
|
||||
if (!isIPv4) {
|
||||
int delim = sAddr.indexOf('%'); // drop ip6 zone suffix
|
||||
return delim<0 ? sAddr.toUpperCase() : sAddr.substring(0, delim).toUpperCase();
|
||||
MainActivity.myInetIP =
|
||||
(delim < 0) ? sAddr.toUpperCase() : sAddr.substring(
|
||||
0, delim).toUpperCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get the mac address
|
||||
byte[] mac = network.getHardwareAddress();
|
||||
|
||||
if (mac != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < mac.length; i++) {
|
||||
sb.append(String.format("%02X%s", mac[i],
|
||||
(i < mac.length - 1) ? ":" : ""));
|
||||
}
|
||||
MainActivity.myMAC = sb.toString();
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception ex) { } // for now eat exceptions
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -332,21 +356,20 @@ public class Utilities {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the selection index into throughput setup
|
||||
* @param myI
|
||||
* @return
|
||||
*/
|
||||
protected static int findCorrespondingThrpt(int myI) {
|
||||
if (myI == 0) {
|
||||
return 8 * 50000;
|
||||
} else if (myI == 1) {
|
||||
return 8 * 100000;
|
||||
} else if (myI < 6) {
|
||||
return 8 * 250000 * (myI - 1);
|
||||
} else if (myI < 24) {
|
||||
return 8 * (1500000 + 500000 * (myI - 6));
|
||||
} else if (myI > 24 && myI < 43) {
|
||||
return 8 * (15000000 + 5000000 * (myI - 25));
|
||||
} else if (myI == 43) {
|
||||
return 8 * 11000000;
|
||||
} else if (myI == 44){
|
||||
return 8 * 13000000;
|
||||
if (myI < 19) {
|
||||
return (800 - (myI * 40)) * 1000000;
|
||||
} else if (myI < 37) {
|
||||
return (76 - ((myI - 19) * 4)) * 1000000;
|
||||
} else if (myI < 43) {
|
||||
return (6 - ((myI - 37))) * 1000000;
|
||||
} else if (myI < 47) {
|
||||
return (800 - ((myI - 43) * 200)) * 1000;
|
||||
} else { // default unlimited
|
||||
if (MainActivity.isLocal)
|
||||
return 8 * 100000000; // for loopback, the unlimited shouldn't be really unlimited..
|
||||
|
|
|
|||
Loading…
Reference in New Issue