bug fix: mac address check error, sslogger /proc/pid/stat file not exist err
This commit is contained in:
parent
08e2d60cad
commit
24997a7b27
|
|
@ -28,22 +28,14 @@ import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
class MainActivity extends Activity {
|
class MainActivity extends Activity {
|
||||||
// tmp fixed
|
|
||||||
// protected static final String remoteIP = "128.111.68.220";
|
|
||||||
// protected static final String remoteMAC = "18:03:73:c8:86:52";
|
|
||||||
protected static final String udpserver_pathport = "~/mobileRDMABeach/UDPServer 32000 ";
|
|
||||||
// unchanged stuff
|
// unchanged stuff
|
||||||
protected static final String binaryFolderPath = "/data/local/tmp/";
|
protected static final String binaryFolderPath = "/data/local/tmp/";
|
||||||
protected static final String binary_tcpdump = "tcpdump";
|
protected static final String binary_tcpdump = "tcpdump";
|
||||||
private static final String TAG = "MainActivity";
|
private static final String TAG = "MainActivity";
|
||||||
private static final int mVersion = Build.VERSION.SDK_INT;
|
private static final int mVersion = Build.VERSION.SDK_INT;
|
||||||
// the configs
|
// the configs
|
||||||
protected static String remoteIP = "192.168.10.1";
|
protected static String remoteIP = "192.168.2.1";
|
||||||
protected static String remoteMAC = "f0:de:f1:0b:45:4a";
|
protected static String remoteMAC = "4e:32:75:f8:7e:64";
|
||||||
protected static String sshlinklab = "ssh linklab@hotcrp.cs.ucsb.edu"
|
|
||||||
+ " -i /data/.ssh/id_rsa -o StrictHostKeyChecking=no";
|
|
||||||
protected static String sshlinklablocal = "ssh linklab@" + remoteIP
|
|
||||||
+ " -i /data/.ssh/id_rsa -o StrictHostKeyChecking=no";
|
|
||||||
// default variables
|
// default variables
|
||||||
protected static boolean isForcingCPU0 = false;
|
protected static boolean isForcingCPU0 = false;
|
||||||
protected static boolean isVerbose = true;
|
protected static boolean isVerbose = true;
|
||||||
|
|
@ -215,15 +207,27 @@ class MainActivity extends Activity {
|
||||||
if (Utilities.validIP(string_remote_ip)) {
|
if (Utilities.validIP(string_remote_ip)) {
|
||||||
remoteIP = string_remote_ip;
|
remoteIP = string_remote_ip;
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "Entered IP is not right, will use " + remoteIP + "instead",
|
Log.d(TAG, string_remote_ip);
|
||||||
Toast.LENGTH_SHORT);
|
myHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainActivity.txt_results.append(
|
||||||
|
"Entered IP is not right, will use " + remoteIP + " instead");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// check if mac is in valid format
|
// check if mac is in valid format
|
||||||
if (Utilities.validMAC(string_remote_mac)) {
|
if (Utilities.validMAC(string_remote_mac)) {
|
||||||
remoteMAC = string_remote_mac;
|
remoteMAC = string_remote_mac;
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "Entered MAC is not right, will use " + remoteMAC + "instead",
|
Log.d(TAG, string_remote_mac);
|
||||||
Toast.LENGTH_SHORT);
|
myHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainActivity.txt_results.append(
|
||||||
|
"Entered MAC is not right, will use " + remoteMAC + " instead");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Log.d(TAG, "remote IP is set to " + remoteIP);
|
Log.d(TAG, "remote IP is set to " + remoteIP);
|
||||||
Log.d(TAG, "remote MAC is set to " + remoteMAC);
|
Log.d(TAG, "remote MAC is set to " + remoteMAC);
|
||||||
|
|
@ -347,11 +351,9 @@ class MainActivity extends Activity {
|
||||||
int myI = selectedItemsThrpt.get(k);
|
int myI = selectedItemsThrpt.get(k);
|
||||||
currentBandwidth = Utilities.findCorrespondingThrpt(myI);
|
currentBandwidth = Utilities.findCorrespondingThrpt(myI);
|
||||||
|
|
||||||
if (isVerbose) {
|
|
||||||
Log.d(TAG, "bandwidth is set to " + currentBandwidth
|
Log.d(TAG, "bandwidth is set to " + currentBandwidth
|
||||||
+ "\nTCP_port is set to " + Utilities.TCP_port
|
+ "\nTCP_port is set to " + Utilities.TCP_port
|
||||||
+ "\nUDP_port is set to " + Utilities.UDP_port);
|
+ "\nUDP_port is set to " + Utilities.UDP_port);
|
||||||
}
|
|
||||||
|
|
||||||
// start
|
// start
|
||||||
try {
|
try {
|
||||||
|
|
@ -368,48 +370,51 @@ class MainActivity extends Activity {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
// start repeating
|
// start repeating
|
||||||
int waitTimeSec = 0;
|
int wait_time_sec = 0;
|
||||||
for (int i = 0; i < repeatCounts; ++i) {
|
for (int i = 0; i < repeatCounts; ++i) {
|
||||||
for (int j = 0; j < selectedItems.size(); ++j) {
|
for (int j = 0; j < selectedItems.size(); ++j) {
|
||||||
int whichItem = selectedItems.get(j);
|
int whichItem = selectedItems.get(j);
|
||||||
if (flagRecv &&
|
if (flagRecv) {
|
||||||
(whichItem == 1 || whichItem == 4)) {
|
|
||||||
// 1 is udp, 4 is raw normal
|
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
// waitTimeSec = (Math.max(bytes2send / currentBandwidth + 20, 20));
|
wait_time_sec = Math.max(
|
||||||
|
bytes2send / currentBandwidth + 20,
|
||||||
|
20);
|
||||||
// Runtime.getRuntime().exec("su -c /data/local/tmp/UDPServer_mobile 32000 "
|
// Runtime.getRuntime().exec("su -c /data/local/tmp/UDPServer_mobile 32000 "
|
||||||
// + currentBandwidth + " " + waitTimeSec + " &").waitFor();
|
// + currentBandwidth + " " + waitTimeSec + " &").waitFor();
|
||||||
} else {
|
} else {
|
||||||
waitTimeSec = Math.max(
|
wait_time_sec = Math.max(
|
||||||
bytes2send / currentBandwidth + 20,
|
bytes2send / currentBandwidth + 20,
|
||||||
60);
|
60);
|
||||||
Process proc = Runtime.getRuntime().exec(
|
Process proc = Runtime.getRuntime().exec(
|
||||||
"su");
|
"su");
|
||||||
DataOutputStream os = new DataOutputStream(
|
DataOutputStream os = new DataOutputStream(
|
||||||
proc.getOutputStream());
|
proc.getOutputStream());
|
||||||
if (isUsingWifi) {
|
os.writeBytes("ssh root@" +
|
||||||
os.writeBytes(sshlinklablocal + "\n");
|
remoteIP + "\n");
|
||||||
os.flush();
|
os.flush();
|
||||||
Thread.sleep(5001);
|
Thread.sleep(1000);
|
||||||
} else {
|
os.writeBytes("x\n");
|
||||||
os.writeBytes(sshlinklab + "\n");
|
|
||||||
os.flush();
|
os.flush();
|
||||||
Thread.sleep(10001);
|
Thread.sleep(1000);
|
||||||
}
|
if (whichItem == 1 || whichItem == 4) {
|
||||||
os.writeBytes(
|
os.writeBytes(
|
||||||
udpserver_pathport +
|
"" +
|
||||||
currentBandwidth + " " +
|
"\n");
|
||||||
waitTimeSec + " &\n");
|
} else {
|
||||||
|
os.writeBytes(
|
||||||
|
"" +
|
||||||
|
"\n");
|
||||||
|
}
|
||||||
os.flush();
|
os.flush();
|
||||||
Thread.sleep(1001);
|
Thread.sleep(1000);
|
||||||
os.writeBytes("exit\n");
|
os.writeBytes("exit\n");
|
||||||
os.flush();
|
os.flush();
|
||||||
os.writeBytes("exit\n");
|
os.writeBytes("exit\n");
|
||||||
os.flush();
|
os.flush();
|
||||||
Thread.sleep(501);
|
Thread.sleep(500);
|
||||||
os.close();
|
os.close();
|
||||||
proc.destroy();
|
proc.destroy();
|
||||||
Thread.sleep(805);
|
Thread.sleep(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
@ -507,7 +512,7 @@ class MainActivity extends Activity {
|
||||||
Runtime.getRuntime().gc();
|
Runtime.getRuntime().gc();
|
||||||
System.gc();
|
System.gc();
|
||||||
if (flagRecv && (selectedItems.get(j) == 1 || selectedItems.get(j) == 4)) {
|
if (flagRecv && (selectedItems.get(j) == 1 || selectedItems.get(j) == 4)) {
|
||||||
Thread.sleep(Math.abs(waitTimeSec*1000 - UDPfinishTime));
|
Thread.sleep(Math.abs(wait_time_sec*1000 - UDPfinishTime));
|
||||||
}
|
}
|
||||||
commd[2] = "cd " + outFolderPath + " && mv *" + btn_click_time
|
commd[2] = "cd " + outFolderPath + " && mv *" + btn_click_time
|
||||||
+ "* " + Utilities.existedItems[selectedItems.get(j)] + "/";
|
+ "* " + Utilities.existedItems[selectedItems.get(j)] + "/";
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,12 @@ import android.os.Environment;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
@ -207,7 +209,7 @@ class SSLogger extends Service {
|
||||||
|
|
||||||
// file handler for cpu usage of wifi driver
|
// file handler for cpu usage of wifi driver
|
||||||
if (MainActivity.wifiDriverPID != -1)
|
if (MainActivity.wifiDriverPID != -1)
|
||||||
cpuWiFiDriverPIDFileName = MainActivity.btn_click_time.concat(".cpuPID");
|
cpuWiFiDriverPIDFileName = MainActivity.btn_click_time.concat(".cpuDriver");
|
||||||
|
|
||||||
// file string for cpu usage of my process
|
// file string for cpu usage of my process
|
||||||
if (MainActivity.isLoggingPerProcPID)
|
if (MainActivity.isLoggingPerProcPID)
|
||||||
|
|
@ -345,7 +347,7 @@ class SSLogger extends Service {
|
||||||
* @return string that's been parsed
|
* @return string that's been parsed
|
||||||
*/
|
*/
|
||||||
private static String parseProcPIDStat(String line) {
|
private static String parseProcPIDStat(String line) {
|
||||||
if (line == null) return "nan nan nan"; // -1 means it does not exist
|
if (line == null) return "-1 -1 -1"; // -1 means it does not exist
|
||||||
String[] toks = line.split("\\s+");
|
String[] toks = line.split("\\s+");
|
||||||
long idle = Long.parseLong(toks[15]) + Long.parseLong(toks[16]);
|
long idle = Long.parseLong(toks[15]) + Long.parseLong(toks[16]);
|
||||||
long cpu = Long.parseLong(toks[13]) + Long.parseLong(toks[14]);
|
long cpu = Long.parseLong(toks[13]) + Long.parseLong(toks[14]);
|
||||||
|
|
@ -372,12 +374,24 @@ class SSLogger extends Service {
|
||||||
private static String readUsagePID(int currentPID) {
|
private static String readUsagePID(int currentPID) {
|
||||||
if (currentPID == -1) return null;
|
if (currentPID == -1) return null;
|
||||||
// changed by Yanzi
|
// changed by Yanzi
|
||||||
|
|
||||||
|
Process proc;
|
||||||
|
BufferedReader stdout_buf;
|
||||||
|
String load;
|
||||||
try {
|
try {
|
||||||
RandomAccessFile reader = new RandomAccessFile("/proc/" + currentPID +"/stat", "r");
|
proc = Runtime.getRuntime().exec("su -c cat /proc/" + currentPID + "/stat");
|
||||||
String load = reader.readLine();
|
proc.waitFor();
|
||||||
reader.close();
|
|
||||||
|
// read std out
|
||||||
|
stdout_buf = new BufferedReader(new InputStreamReader(
|
||||||
|
proc.getInputStream()));
|
||||||
|
|
||||||
|
load = stdout_buf.readLine();
|
||||||
|
// RandomAccessFile reader = new RandomAccessFile("/proc/" + currentPID +"/stat", "r");
|
||||||
|
// String load = reader.readLine();
|
||||||
|
// reader.close();
|
||||||
return load;
|
return load;
|
||||||
} catch (IOException unimportant) {
|
} catch (IOException | InterruptedException unimportant) {
|
||||||
Log.w(TAG, "exception on readUsagePID on pid: " + currentPID);
|
Log.w(TAG, "exception on readUsagePID on pid: " + currentPID);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class Thread_TX_CNormal implements Runnable {
|
||||||
|
|
||||||
// if config to log per process
|
// if config to log per process
|
||||||
while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
||||||
MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_Normal, false);
|
MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_Normal, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
proc.waitFor();
|
proc.waitFor();
|
||||||
|
|
@ -92,9 +92,13 @@ class Thread_TX_CNormal implements Runnable {
|
||||||
MainActivity.myHandler.post(new Runnable() {
|
MainActivity.myHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainActivity.txt_results.append("Sent " + sentBytes +
|
MainActivity.txt_results.append("Sent " +
|
||||||
"bytes in " + duration +
|
String.format("%.4f", sentBytes/Utilities.oneMB) +
|
||||||
"s (" +throughput/Utilities.oneMB +"Mbps)\n");
|
" MB in " +
|
||||||
|
String.format("%.4f", duration) +
|
||||||
|
"s (" +
|
||||||
|
String.format("%.4f", throughput/Utilities.oneMB) +
|
||||||
|
"Mbps)\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,13 @@ class Thread_TX_CNormalUDP implements Runnable {
|
||||||
MainActivity.myHandler.post(new Runnable() {
|
MainActivity.myHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainActivity.txt_results.append("Sent " + sentBytes +
|
MainActivity.txt_results.append("Sent " +
|
||||||
"bytes in " + duration +
|
String.format("%.4f", sentBytes/Utilities.oneMB) +
|
||||||
"s (" +throughput/Utilities.oneMB +"Mbps)\n");
|
" MB in " +
|
||||||
|
String.format("%.4f", duration) +
|
||||||
|
"s (" +
|
||||||
|
String.format("%.4f", throughput/Utilities.oneMB) +
|
||||||
|
"Mbps)\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,13 @@ class Thread_TX_CRawNormal implements Runnable {
|
||||||
MainActivity.myHandler.post(new Runnable() {
|
MainActivity.myHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainActivity.txt_results.append("Sent " + sentBytes +
|
MainActivity.txt_results.append("Sent " +
|
||||||
"bytes in " + duration +
|
String.format("%.4f", sentBytes/Utilities.oneMB) +
|
||||||
"s (" +throughput/Utilities.oneMB +"Mbps)\n");
|
" MB in " +
|
||||||
|
String.format("%.4f", duration) +
|
||||||
|
"s (" +
|
||||||
|
String.format("%.4f", throughput/Utilities.oneMB) +
|
||||||
|
"Mbps)\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,13 @@ class Thread_TX_CRawSplice implements Runnable {
|
||||||
MainActivity.myHandler.post(new Runnable() {
|
MainActivity.myHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainActivity.txt_results.append("Sent " + sentBytes +
|
MainActivity.txt_results.append("Sent " +
|
||||||
"bytes in " + duration +
|
String.format("%.4f", sentBytes/Utilities.oneMB) +
|
||||||
"s (" +throughput/Utilities.oneMB +"Mbps)\n");
|
" MB in " +
|
||||||
|
String.format("%.4f", duration) +
|
||||||
|
"s (" +
|
||||||
|
String.format("%.4f", throughput/Utilities.oneMB) +
|
||||||
|
"Mbps)\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,13 @@ class Thread_TX_CSendfile implements Runnable {
|
||||||
MainActivity.myHandler.post(new Runnable() {
|
MainActivity.myHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainActivity.txt_results.append("Sent " + sentBytes +
|
MainActivity.txt_results.append("Sent " +
|
||||||
"bytes in " + duration +
|
String.format("%.4f", sentBytes/Utilities.oneMB) +
|
||||||
"s (" +throughput/Utilities.oneMB +"Mbps)\n");
|
" MB in " +
|
||||||
|
String.format("%.4f", duration) +
|
||||||
|
"s (" +
|
||||||
|
String.format("%.4f", throughput/Utilities.oneMB) +
|
||||||
|
"Mbps)\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,9 +89,13 @@ class Thread_TX_CSplice implements Runnable {
|
||||||
MainActivity.myHandler.post(new Runnable() {
|
MainActivity.myHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainActivity.txt_results.append("Sent " + sentBytes +
|
MainActivity.txt_results.append("Sent " +
|
||||||
"bytes in " + duration +
|
String.format("%.4f", sentBytes/Utilities.oneMB) +
|
||||||
"s (" +throughput/Utilities.oneMB +"Mbps)\n");
|
" MB in " +
|
||||||
|
String.format("%.4f", duration) +
|
||||||
|
"s (" +
|
||||||
|
String.format("%.4f", throughput/Utilities.oneMB) +
|
||||||
|
"Mbps)\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,13 @@ class Thread_TX_CUDPSendfile implements Runnable {
|
||||||
MainActivity.myHandler.post(new Runnable() {
|
MainActivity.myHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainActivity.txt_results.append("Sent " + sentBytes +
|
MainActivity.txt_results.append("Sent " +
|
||||||
"bytes in " + duration +
|
String.format("%.4f", sentBytes/Utilities.oneMB) +
|
||||||
"s (" +throughput/Utilities.oneMB +"Mbps)\n");
|
" MB in " +
|
||||||
|
String.format("%.4f", duration) +
|
||||||
|
"s (" +
|
||||||
|
String.format("%.4f", throughput/Utilities.oneMB) +
|
||||||
|
"Mbps)\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -588,8 +588,8 @@ class Utilities {
|
||||||
static boolean validMAC(String mac) {
|
static boolean validMAC(String mac) {
|
||||||
// use regular expression to validate a mac address
|
// use regular expression to validate a mac address
|
||||||
// the only valid format is xx:xx:xx:xx:xx:xx
|
// the only valid format is xx:xx:xx:xx:xx:xx
|
||||||
Pattern p = Pattern.compile("/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/");
|
Pattern p = Pattern.compile("^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$");
|
||||||
Matcher m = p.matcher(mac);
|
Matcher m = p.matcher(mac);
|
||||||
return m.find();
|
return m.matches();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue