add size limit to energy analysis, output sent bytes in app
This commit is contained in:
parent
49f6250de9
commit
a085cf3daa
|
|
@ -162,9 +162,7 @@ class SSLogger extends Service {
|
||||||
+ " -w " + MainActivity.outFolderPath + "/tcpdump_wifionly_"
|
+ " -w " + MainActivity.outFolderPath + "/tcpdump_wifionly_"
|
||||||
+ MainActivity.btn_click_time + " &"
|
+ MainActivity.btn_click_time + " &"
|
||||||
).waitFor();
|
).waitFor();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException | IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,8 @@ class Thread_RX_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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Received " + recvBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,8 @@ class Thread_RX_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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Received " + recvBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,8 @@ class Thread_RX_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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Received " + recvBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,8 @@ class Thread_RX_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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Received " + recvBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,8 @@ class Thread_RX_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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Received " + recvBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,8 @@ 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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Sent " + sentBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,8 @@ 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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Sent " + sentBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,8 @@ 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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Sent " + sentBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,8 @@ 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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Sent " + sentBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,8 @@ 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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Sent " + sentBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,8 @@ 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("Time: " + duration + "s\n");
|
MainActivity.txt_results.append(
|
||||||
|
"Sent " + sentBytes + "bytes in " + duration + "s\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ class EnergyAnalyzer():
|
||||||
# net_state: 'i': 'idle', 'a': 'active', 't': 'tail'
|
# net_state: 'i': 'idle', 'a': 'active', 't': 'tail'
|
||||||
self.net_start_time = -1
|
self.net_start_time = -1
|
||||||
self.net_end_time = -1
|
self.net_end_time = -1
|
||||||
|
self.data_size = 0
|
||||||
# WiFi
|
# WiFi
|
||||||
self.wifi_rssi = []
|
self.wifi_rssi = []
|
||||||
# LTE
|
# LTE
|
||||||
|
|
@ -239,6 +240,7 @@ class EnergyAnalyzer():
|
||||||
self.logger.debug(self.wifi_rssi)
|
self.logger.debug(self.wifi_rssi)
|
||||||
|
|
||||||
def read_tcpdump_file(self, fp_tcpdump,
|
def read_tcpdump_file(self, fp_tcpdump,
|
||||||
|
size_limit=None,
|
||||||
isWiFi=False, isLTE=False, is3G=False):
|
isWiFi=False, isLTE=False, is3G=False):
|
||||||
# TODO: currently WIFi only
|
# TODO: currently WIFi only
|
||||||
if not os.path.isfile(fp_tcpdump):
|
if not os.path.isfile(fp_tcpdump):
|
||||||
|
|
@ -257,12 +259,13 @@ class EnergyAnalyzer():
|
||||||
with open(fp_tcpdump, 'rU') as f:
|
with open(fp_tcpdump, 'rU') as f:
|
||||||
content = f.readlines()
|
content = f.readlines()
|
||||||
firstLine = True
|
firstLine = True
|
||||||
|
total_bytes = 0
|
||||||
# check the network status: idle, active, or tail
|
# check the network status: idle, active, or tail
|
||||||
net_state = 'a' # active
|
net_state = 'a' # active
|
||||||
for line in content:
|
for line in content:
|
||||||
tmp = None
|
tmp = None
|
||||||
for pattern in myPatterns:
|
for pattern_i in xrange(len(myPatterns)):
|
||||||
myMatch = re.search(pattern, line)
|
myMatch = re.search(myPatterns[pattern_i], line)
|
||||||
if myMatch is not None:
|
if myMatch is not None:
|
||||||
# [timestamp (s), src_ip, dst_ip, flag, seq_start, seq_end]
|
# [timestamp (s), src_ip, dst_ip, flag, seq_start, seq_end]
|
||||||
# or
|
# or
|
||||||
|
|
@ -273,9 +276,17 @@ class EnergyAnalyzer():
|
||||||
if tmp is None:
|
if tmp is None:
|
||||||
self.logger.debug("nothing found in {0}".format(line.rstrip()))
|
self.logger.debug("nothing found in {0}".format(line.rstrip()))
|
||||||
continue
|
continue
|
||||||
|
# if pattern_i == 1:
|
||||||
|
# data_type = 'ack'
|
||||||
|
# else:
|
||||||
|
# data_type = 'seq'
|
||||||
data_len = 0
|
data_len = 0
|
||||||
if len(tmp) > 5:
|
if len(tmp) > 5:
|
||||||
data_len = int(tmp[5]) - int(tmp[4])
|
data_len = int(tmp[5]) - int(tmp[4])
|
||||||
|
total_bytes += data_len
|
||||||
|
self.logger.debug("{0}".format(total_bytes))
|
||||||
|
if size_limit is not None and total_bytes > size_limit:
|
||||||
|
break
|
||||||
if firstLine:
|
if firstLine:
|
||||||
firstLine = False
|
firstLine = False
|
||||||
elif self.data_tcpdump[-1][1] == 'i' \
|
elif self.data_tcpdump[-1][1] == 'i' \
|
||||||
|
|
@ -307,8 +318,10 @@ class EnergyAnalyzer():
|
||||||
# get the start and end time of network
|
# get the start and end time of network
|
||||||
self.net_start_time = self.data_tcpdump[0][0]
|
self.net_start_time = self.data_tcpdump[0][0]
|
||||||
self.net_end_time = self.data_tcpdump[-2][0] # true net end time
|
self.net_end_time = self.data_tcpdump[-2][0] # true net end time
|
||||||
|
self.data_size = total_bytes
|
||||||
|
|
||||||
def read_wifi_log(self, fp_tcpdump, tcpdump_filter="",
|
def read_wifi_log(self, fp_tcpdump, tcpdump_filter="",
|
||||||
|
size_limit=None,
|
||||||
fp_sslogger=None, delete_ori_tcpdump=True):
|
fp_sslogger=None, delete_ori_tcpdump=True):
|
||||||
self.logger.debug("clean up network data")
|
self.logger.debug("clean up network data")
|
||||||
self.clean_up_net_data()
|
self.clean_up_net_data()
|
||||||
|
|
@ -332,7 +345,7 @@ class EnergyAnalyzer():
|
||||||
subprocess.call("rm {0}".format(fp_tcpdump), shell=True)
|
subprocess.call("rm {0}".format(fp_tcpdump), shell=True)
|
||||||
fp_tcpdump += '.tcpdump'
|
fp_tcpdump += '.tcpdump'
|
||||||
# read the file
|
# read the file
|
||||||
self.read_tcpdump_file(fp_tcpdump, isWiFi=True)
|
self.read_tcpdump_file(fp_tcpdump, size_limit=size_limit, isWiFi=True)
|
||||||
# parse sslogger
|
# parse sslogger
|
||||||
self.logger.debug("parse sslogger file")
|
self.logger.debug("parse sslogger file")
|
||||||
if fp_sslogger is None:
|
if fp_sslogger is None:
|
||||||
|
|
@ -434,9 +447,14 @@ class EnergyAnalyzer():
|
||||||
# if write to file, first generate overview
|
# if write to file, first generate overview
|
||||||
f = None
|
f = None
|
||||||
if self.output_path is not None:
|
if self.output_path is not None:
|
||||||
f = open("{0}/result_overview.csv".format(self.output_path), 'wb')
|
overview_fp = "{0}/result_overview.csv".format(self.output_path)
|
||||||
|
if os.path.isfile(overview_fp):
|
||||||
|
f = open(overview_fp, 'ab')
|
||||||
|
else:
|
||||||
|
f = open(overview_fp, 'wb')
|
||||||
# first line description
|
# first line description
|
||||||
f.write('#total_energy(mJ),total_time(s),avg_total_pwr(mW),' +
|
f.write('#data_size(MB),' +
|
||||||
|
'total_energy(mJ),total_time(s),avg_total_pwr(mW),' +
|
||||||
'avg_logging_freq(s/record)')
|
'avg_logging_freq(s/record)')
|
||||||
if cpu:
|
if cpu:
|
||||||
f.write(',cpu_energy(mJ),' +
|
f.write(',cpu_energy(mJ),' +
|
||||||
|
|
@ -450,6 +468,7 @@ class EnergyAnalyzer():
|
||||||
f.write(',wifi_energy(mJ),wifi_time(s),avg_wifi_pwr(mW),' +
|
f.write(',wifi_energy(mJ),wifi_time(s),avg_wifi_pwr(mW),' +
|
||||||
'wifi_active_energy(mJ),wifi_idel_energy(mJ)')
|
'wifi_active_energy(mJ),wifi_idel_energy(mJ)')
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
|
f.write('{0:.2f},'.format(self.data_size / 1048576.0))
|
||||||
f.write('{0:.8f},{1:.8f},{2:.8f},'.format(
|
f.write('{0:.8f},{1:.8f},{2:.8f},'.format(
|
||||||
total_energy, total_time, avg_power))
|
total_energy, total_time, avg_power))
|
||||||
f.write('{0:.8f}'.format(self.avg_log_freq))
|
f.write('{0:.8f}'.format(self.avg_log_freq))
|
||||||
|
|
@ -498,8 +517,8 @@ class EnergyAnalyzer():
|
||||||
|
|
||||||
# now generate instant cpu
|
# now generate instant cpu
|
||||||
if cpu and self.output_path is not None:
|
if cpu and self.output_path is not None:
|
||||||
f = open("{0}/result_cpu_instant.csv".format(
|
f = open("{0}/result_cpu_instant_{1:.2f}MB.csv".format(
|
||||||
self.output_path), 'wb')
|
self.output_path, self.data_size / 1048576.0), 'wb')
|
||||||
# description
|
# description
|
||||||
num_of_cores = len(self.instant_freqs[0])
|
num_of_cores = len(self.instant_freqs[0])
|
||||||
f.write('#time(s),time_delta(s),' +
|
f.write('#time(s),time_delta(s),' +
|
||||||
|
|
@ -537,6 +556,7 @@ if __name__ == "__main__":
|
||||||
output_path="./models/test/")
|
output_path="./models/test/")
|
||||||
myObj.read_wifi_log(
|
myObj.read_wifi_log(
|
||||||
tcpdumpFile,
|
tcpdumpFile,
|
||||||
|
size_limit=1024*1024*20,
|
||||||
fp_sslogger=ssFile, tcpdump_filter="host 128.111.68.220")
|
fp_sslogger=ssFile, tcpdump_filter="host 128.111.68.220")
|
||||||
myObj.parse_wifi_energy()
|
myObj.parse_wifi_energy()
|
||||||
myObj.read_cpu_log(
|
myObj.read_cpu_log(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue