Added CSV logging
This commit is contained in:
parent
319f6023e9
commit
d9fac2807a
25 changed files with 200 additions and 144 deletions
|
|
@ -81,14 +81,14 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
public void handledIncomingData(long size) {
|
||||
downloadSpeed.setHandledData(size);
|
||||
if(throughputListener != null && downloadSpeed.isUpdated())
|
||||
throughputListener.throughputUpdate(downloadSpeed.getThroughput(), uploadSpeed.getThroughput());
|
||||
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handledOutgoingData(long size) {
|
||||
uploadSpeed.setHandledData(size);
|
||||
if(throughputListener != null && uploadSpeed.isUpdated())
|
||||
throughputListener.throughputUpdate(downloadSpeed.getThroughput(), uploadSpeed.getThroughput());
|
||||
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
|
||||
}
|
||||
|
||||
public void setThroughputListener(ThroughputListener listener){
|
||||
|
|
@ -99,6 +99,9 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
return behaviours;
|
||||
}
|
||||
|
||||
public UeBehaviour getRunningBehaviour(){
|
||||
return currentlyActive;
|
||||
}
|
||||
|
||||
public static interface ThroughputListener{
|
||||
public void throughputUpdate(double downThroughput, double upThroughput);
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
package com.ericsson.uecontrol.core.behaviour;
|
||||
|
||||
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||
|
||||
/**
|
||||
* This behaviour simulates streaming data.
|
||||
* E.g: video, music etc...
|
||||
*
|
||||
* Created by ezivkoc on 2014-07-15.
|
||||
*/
|
||||
public class UeBehaviourDownload extends UeBehaviour {
|
||||
private long data_size;
|
||||
|
||||
public UeBehaviourDownload(long byte_amount){
|
||||
data_size = byte_amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Download";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Will download "+ data_size/1000 +"kB";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package com.ericsson.uecontrol.core.behaviour;
|
||||
|
||||
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||
|
||||
/**
|
||||
* This behaviour simulates streaming data.
|
||||
* E.g: video, music etc...
|
||||
*
|
||||
* Created by ezivkoc on 2014-07-15.
|
||||
*/
|
||||
public class UeBehaviourUpload extends UeBehaviour {
|
||||
private long data_size;
|
||||
|
||||
public UeBehaviourUpload(long byte_amount){
|
||||
data_size = byte_amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Upload";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Will Upload "+ data_size/1000 +"kB";
|
||||
}
|
||||
}
|
||||
|
|
@ -24,11 +24,14 @@ public class ThroughputCalculator {
|
|||
}
|
||||
}
|
||||
|
||||
public double getThroughput(){
|
||||
public double getByeThroughput(){
|
||||
setHandledData(0); // Update throughput
|
||||
updated = false;
|
||||
return throughput;
|
||||
}
|
||||
public double getBitThroughput(){
|
||||
return getByeThroughput()*8;
|
||||
}
|
||||
|
||||
public boolean isUpdated(){
|
||||
return updated;
|
||||
|
|
@ -36,12 +39,12 @@ public class ThroughputCalculator {
|
|||
|
||||
|
||||
private static final String[] DATA_SIZE = new String[]{"b/s", "kbit/s", "Mbit/s", "Gbit/s"};
|
||||
public static String getThroughputString(double bits){
|
||||
public static String getBitThroughputString(double bitsPerSec){
|
||||
int index = 0;
|
||||
double value = bits;
|
||||
double value = bitsPerSec;
|
||||
|
||||
for(; value > 1024 && index < DATA_SIZE.length ;index++) {
|
||||
value /= 1024;
|
||||
for(; value > 1000 && index < DATA_SIZE.length ;index++) {
|
||||
value /= 1000;
|
||||
}
|
||||
|
||||
value = (int)(value*10) / 10.0;
|
||||
|
|
|
|||
|
|
@ -30,14 +30,8 @@ public class EditActivity extends ListActivity implements AdapterView.OnItemClic
|
|||
setContentView(R.layout.activity_edit);
|
||||
|
||||
final List<UeBehaviour> list;
|
||||
if(getIntent().hasExtra("executor")) {
|
||||
int executorIndex = getIntent().getExtras().getInt("executor_index");
|
||||
executor = MainActivity.getExecutor(executorIndex);
|
||||
|
||||
list = executor.getBehaviourList();
|
||||
}
|
||||
else
|
||||
list = new ArrayList<UeBehaviour>();
|
||||
executor = MainActivity.getExecutor();
|
||||
list = executor.getBehaviourList();
|
||||
|
||||
adapter = new BehaviourListAdapter(this, list);
|
||||
adapter.setEditable(true);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ package com.ericsson.uecontrol.gui;
|
|||
import android.app.ActionBar;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
|
|
@ -16,8 +17,7 @@ import com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing;
|
|||
import com.ericsson.uecontrol.gui.fragments.BehaviourListFragment;
|
||||
import com.ericsson.uecontrol.gui.fragments.NavigationDrawerFragment;
|
||||
import com.ericsson.uecontrol.gui.fragments.StatusFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.ericsson.uecontrol.gui.util.CSVWriter;
|
||||
|
||||
|
||||
public class MainActivity extends FragmentActivity
|
||||
|
|
@ -29,34 +29,31 @@ public class MainActivity extends FragmentActivity
|
|||
private NavigationDrawerFragment navigationDrawerFragment;
|
||||
private StatusFragment statusFragment;
|
||||
|
||||
private int currentExecutor;
|
||||
private static UeControlExecutor currentExecutor;
|
||||
private static CSVWriter logger;
|
||||
|
||||
private static ArrayList<UeControlExecutor> executors;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
navigationDrawerFragment = (NavigationDrawerFragment)
|
||||
getFragmentManager().findFragmentById(R.id.navigation_drawer);
|
||||
//navigationDrawerFragment = (NavigationDrawerFragment)
|
||||
// getFragmentManager().findFragmentById(R.id.navigation_drawer);
|
||||
statusFragment = (StatusFragment)
|
||||
getFragmentManager().findFragmentById(R.id.status_fragment);
|
||||
|
||||
// Set up the drawer.
|
||||
navigationDrawerFragment.setUp(
|
||||
R.id.navigation_drawer,
|
||||
(DrawerLayout) findViewById(R.id.drawer_layout));
|
||||
//navigationDrawerFragment.setUp(
|
||||
// R.id.navigation_drawer,
|
||||
// (DrawerLayout) findViewById(R.id.drawer_layout));
|
||||
|
||||
executors = new ArrayList<UeControlExecutor>();
|
||||
currentExecutor = 0;
|
||||
|
||||
UeControlExecutor exec = new UeControlExecutor();
|
||||
exec.addBehaviour(new UeBehaviourSleep());
|
||||
exec.addBehaviour(new UeBehaviourSurfing());
|
||||
exec.addBehaviour(new UeBehaviourSleep(4000));
|
||||
exec.setThroughputListener(statusFragment.getThroughputListener());
|
||||
executors.add(exec);
|
||||
currentExecutor = new UeControlExecutor();
|
||||
currentExecutor.addBehaviour(new UeBehaviourSleep());
|
||||
currentExecutor.addBehaviour(new UeBehaviourSurfing());
|
||||
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
|
||||
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
||||
onNavigationDrawerItemSelected(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -64,13 +61,12 @@ public class MainActivity extends FragmentActivity
|
|||
// update the main content by replacing fragments
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.container, BehaviourListFragment.newInstance(position)).commit();
|
||||
currentExecutor = position;
|
||||
.replace(R.id.container, BehaviourListFragment.newInstance()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
if (navigationDrawerFragment != null && !navigationDrawerFragment.isDrawerOpen()) {
|
||||
if (navigationDrawerFragment == null || !navigationDrawerFragment.isDrawerOpen()) {
|
||||
// Only show items in the action bar relevant to this screen
|
||||
// if the drawer is not showing. Otherwise, let the drawer
|
||||
// decide what to show in the action bar.
|
||||
|
|
@ -93,20 +89,23 @@ public class MainActivity extends FragmentActivity
|
|||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_execute) {
|
||||
UeControlExecutor exec = executors.get(currentExecutor);
|
||||
if(exec.isRunning()){
|
||||
exec.terminate();
|
||||
if(currentExecutor.isRunning()){
|
||||
currentExecutor.terminate();
|
||||
item.setTitle(R.string.action_run);
|
||||
}
|
||||
else {
|
||||
exec.execute();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if(prefs.getBoolean("logging", false))
|
||||
logger = new CSVWriter(this);
|
||||
else
|
||||
logger = null;
|
||||
currentExecutor.execute();
|
||||
item.setTitle(R.string.action_stop);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (id == R.id.action_edit) {
|
||||
Intent intent = new Intent(this, EditActivity.class);
|
||||
intent.putExtra("executor", currentExecutor);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -117,9 +116,14 @@ public class MainActivity extends FragmentActivity
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public static UeControlExecutor getExecutor(int index) {
|
||||
if(index >= executors.size())
|
||||
return null;
|
||||
return executors.get(index);
|
||||
public static UeControlExecutor getExecutor() {
|
||||
return currentExecutor;
|
||||
}
|
||||
|
||||
public static void logThroughput(double downThroughput, double upThroughput) {
|
||||
if(logger == null || currentExecutor == null || currentExecutor.getRunningBehaviour() == null)
|
||||
return;
|
||||
|
||||
logger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ public class BehaviourListFragment extends Fragment {
|
|||
private BehaviourListAdapter adapter;
|
||||
private UeControlExecutor executor;
|
||||
|
||||
public static BehaviourListFragment newInstance(int index) {
|
||||
public static BehaviourListFragment newInstance() {
|
||||
BehaviourListFragment f = new BehaviourListFragment();
|
||||
// Supply index input as an argument.
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("executor", index);
|
||||
f.setArguments(args);
|
||||
//Bundle args = new Bundle();
|
||||
//args.putInt("executor", index);
|
||||
//f.setArguments(args);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
|
@ -46,11 +46,8 @@ public class BehaviourListFragment extends Fragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle args = getArguments();
|
||||
int index = args.getInt("executor", 0);
|
||||
|
||||
if(MainActivity.getExecutor(index) != null) {
|
||||
UeControlExecutor executor = MainActivity.getExecutor(index);
|
||||
if(MainActivity.getExecutor() != null) {
|
||||
UeControlExecutor executor = MainActivity.getExecutor();
|
||||
adapter = new BehaviourListAdapter(getActivity(), executor.getBehaviourList());
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -60,8 +60,7 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
private boolean mFromSavedInstanceState;
|
||||
private boolean mUserLearnedDrawer;
|
||||
|
||||
public NavigationDrawerFragment() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
package com.ericsson.uecontrol.gui.fragments;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -13,6 +19,8 @@ import android.widget.TextView;
|
|||
import com.ericsson.uecontrol.R;
|
||||
import com.ericsson.uecontrol.core.UeControlExecutor;
|
||||
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
|
||||
import com.ericsson.uecontrol.gui.MainActivity;
|
||||
import com.ericsson.uecontrol.gui.util.CSVWriter;
|
||||
import com.jjoe64.graphview.GraphView.GraphViewData;
|
||||
import com.jjoe64.graphview.GraphViewSeries;
|
||||
import com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle;
|
||||
|
|
@ -67,11 +75,13 @@ public class StatusFragment extends Fragment {
|
|||
down_speed.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
down_speed.setText(ThroughputCalculator.getThroughputString(downThroughput));
|
||||
up_speed.setText(ThroughputCalculator.getThroughputString(upThroughput));
|
||||
down_speed.setText(ThroughputCalculator.getBitThroughputString(downThroughput));
|
||||
up_speed.setText(ThroughputCalculator.getBitThroughputString(upThroughput));
|
||||
downGraph.appendData(new GraphViewData(x, downThroughput), true, 120);
|
||||
upGraph.appendData(new GraphViewData(x, upThroughput), true, 120);
|
||||
x++;
|
||||
|
||||
MainActivity.logThroughput(downThroughput, upThroughput);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
108
app/src/main/java/com/ericsson/uecontrol/gui/util/CSVWriter.java
Executable file
108
app/src/main/java/com/ericsson/uecontrol/gui/util/CSVWriter.java
Executable file
|
|
@ -0,0 +1,108 @@
|
|||
package com.ericsson.uecontrol.gui.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* Created by ezivkoc on 2014-07-30.
|
||||
*/
|
||||
public class CSVWriter {
|
||||
public static final String[] HEADINGS = new String[]{
|
||||
"Timestamp", "Behaviour", "RX Throughput(b/s)", "TX Throughput(b/s)", "RAT"
|
||||
};
|
||||
public static final String DELIMITER = ",";
|
||||
protected static final SimpleDateFormat fileDateFormater = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
|
||||
protected static final SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
|
||||
|
||||
|
||||
private File file;
|
||||
|
||||
private NetworkInfo netInfo;
|
||||
private WifiInfo wifiInfo;
|
||||
private TelephonyManager telMan;
|
||||
|
||||
public CSVWriter(Context context){
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
file = new File(
|
||||
prefs.getString("logging_path", "/sdcard/uecontrol/"),
|
||||
"log_"+fileDateFormater.format(System.currentTimeMillis())+".log");
|
||||
|
||||
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
netInfo = cm.getActiveNetworkInfo();
|
||||
|
||||
WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
|
||||
wifiInfo = wm.getConnectionInfo();
|
||||
|
||||
telMan = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
|
||||
// Write Headings
|
||||
StringBuilder line = new StringBuilder();
|
||||
for(String header : HEADINGS){
|
||||
line.append(header).append(DELIMITER);
|
||||
}
|
||||
|
||||
file.delete();
|
||||
file.getParentFile().mkdirs();
|
||||
writeLine(line.toString());
|
||||
}
|
||||
|
||||
|
||||
public void write(String behaviour){
|
||||
StringBuilder line = new StringBuilder();
|
||||
line.append(getTime()).append(DELIMITER);
|
||||
line.append(behaviour).append(DELIMITER);
|
||||
line.append(DELIMITER);
|
||||
line.append(DELIMITER);
|
||||
line.append(getRat()).append(DELIMITER);
|
||||
writeLine(line.toString());
|
||||
}
|
||||
|
||||
public void write(String behaviour, double down, double up){
|
||||
StringBuilder line = new StringBuilder();
|
||||
line.append(getTime()).append(DELIMITER);
|
||||
line.append(behaviour).append(DELIMITER);
|
||||
line.append(down).append(DELIMITER);
|
||||
line.append(up).append(DELIMITER);
|
||||
line.append(getRat()).append(DELIMITER);
|
||||
writeLine(line.toString());
|
||||
}
|
||||
|
||||
protected void writeLine(String line){
|
||||
try{
|
||||
PrintWriter out = new PrintWriter(new FileOutputStream(file, true));
|
||||
out.println(line);
|
||||
out.close();
|
||||
} catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected String getRat(){
|
||||
if(netInfo.getType() == ConnectivityManager.TYPE_MOBILE){
|
||||
switch(telMan.getNetworkType()){
|
||||
case TelephonyManager.NETWORK_TYPE_GPRS: return "GPRS";
|
||||
case TelephonyManager.NETWORK_TYPE_EDGE: return "EDGE";
|
||||
case TelephonyManager.NETWORK_TYPE_UMTS: return "UMTS";
|
||||
case TelephonyManager.NETWORK_TYPE_HSPA: return "HSPA";
|
||||
case TelephonyManager.NETWORK_TYPE_LTE: return "LTE";
|
||||
}
|
||||
}
|
||||
return netInfo.getTypeName();
|
||||
}
|
||||
|
||||
protected String getTime(){
|
||||
return dateFormater.format(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue