Added a setting to change throughput frequency.

[artf492105]
This commit is contained in:
Ziver Koc 2015-02-19 16:03:37 +01:00
parent 0300cf55c1
commit 855da2360e
7 changed files with 83 additions and 7 deletions

View file

@ -212,6 +212,9 @@ public class UeControlExecutor implements Runnable{
public void setDeviceBasedThroughput(boolean enable){ public void setDeviceBasedThroughput(boolean enable){
throughputUpdateRunnable.deviceBasedThroughput = enable; throughputUpdateRunnable.deviceBasedThroughput = enable;
} }
public void setThroughputFrequency(float throughputFrequency) {
throughputUpdateRunnable.setThroughputFrequency(throughputFrequency);
}
public static interface ExecutionListener { public static interface ExecutionListener {
@ -284,5 +287,10 @@ public class UeControlExecutor implements Runnable{
previousTxBytes = currentTxBytes; previousTxBytes = currentTxBytes;
return ret; return ret;
} }
public void setThroughputFrequency(float throughputFrequency) {
downloadSpeed.setFrequency(throughputFrequency);
uploadSpeed.setFrequency(throughputFrequency);
}
} }
} }

View file

@ -4,19 +4,20 @@ package com.ericsson.uecontrol.core.util;
* Created by ezivkoc on 2014-07-22. * Created by ezivkoc on 2014-07-22.
*/ */
public class ThroughputCalculator { public class ThroughputCalculator {
public static final int UPDATES_PER_SEC = 2; public static final float UPDATES_PER_SEC = 2;
public static final double NANOSEC_PER_SECOND = 1000000000.0; public static final double NANOSEC_PER_SECOND = 1000000000.0;
private boolean updated; private boolean updated;
private double throughput; private double throughput;
private long previousTimeStamp; private long previousTimeStamp;
private long data_amount; private long data_amount;
private float frequency = UPDATES_PER_SEC;
public void setHandledData(long bytes){ public void setHandledData(long bytes){
long currentTimeStamp = System.nanoTime(); long currentTimeStamp = System.nanoTime();
data_amount += bytes; data_amount += bytes;
if(currentTimeStamp - (NANOSEC_PER_SECOND/UPDATES_PER_SEC) > previousTimeStamp) { if(currentTimeStamp - (NANOSEC_PER_SECOND/frequency) > previousTimeStamp) {
throughput = data_amount / ((currentTimeStamp - previousTimeStamp) / NANOSEC_PER_SECOND); throughput = data_amount / ((currentTimeStamp - previousTimeStamp) / NANOSEC_PER_SECOND);
previousTimeStamp = currentTimeStamp; previousTimeStamp = currentTimeStamp;
data_amount = 0; data_amount = 0;
@ -36,4 +37,11 @@ public class ThroughputCalculator {
public boolean isUpdated(){ public boolean isUpdated(){
return updated; return updated;
} }
public void setFrequency(float frequency) {
if(frequency < 0)
this.frequency = UPDATES_PER_SEC;
else
this.frequency = frequency;
}
} }

View file

@ -21,6 +21,7 @@ import com.ericsson.uecontrol.core.UeControlExecutor;
import com.ericsson.uecontrol.core.UeControlExecutor.ExecutionListener; import com.ericsson.uecontrol.core.UeControlExecutor.ExecutionListener;
import com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep; import com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep;
import com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing; import com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing;
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
import com.ericsson.uecontrol.gui.fragments.BehaviourListFragment; import com.ericsson.uecontrol.gui.fragments.BehaviourListFragment;
import com.ericsson.uecontrol.gui.fragments.ExecNotification; import com.ericsson.uecontrol.gui.fragments.ExecNotification;
import com.ericsson.uecontrol.gui.fragments.FileBrowserDialog; import com.ericsson.uecontrol.gui.fragments.FileBrowserDialog;
@ -75,6 +76,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
log.info("Creating new instance of executor"); log.info("Creating new instance of executor");
executor = new UeControlExecutor(); executor = new UeControlExecutor();
executor.setDeviceBasedThroughput(Boolean.parseBoolean(prefs.getString("throughput_type", "false"))); executor.setDeviceBasedThroughput(Boolean.parseBoolean(prefs.getString("throughput_type", "false")));
executor.setThroughputFrequency(Float.parseFloat(prefs.getString("throughput_average_freq", "" + ThroughputCalculator.UPDATES_PER_SEC)));
File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE); File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE);
if (input.exists()) { if (input.exists()) {
try { try {
@ -142,6 +144,16 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
if(executor != null) if(executor != null)
executor.setDeviceBasedThroughput(Boolean.parseBoolean(sharedPreferences.getString("throughput_type", "false"))); executor.setDeviceBasedThroughput(Boolean.parseBoolean(sharedPreferences.getString("throughput_type", "false")));
} }
else if(key.equals("throughput_average_freq")){
float frequency = Float.parseFloat(sharedPreferences.getString("throughput_average_freq", ""+ThroughputCalculator.UPDATES_PER_SEC));
log.info("Device Throughput Frequency set to: "+frequency);
if(executor != null)
executor.setThroughputFrequency(frequency);
if(statusFragment != null) {
statusFragment.reset();
statusFragment.updateGraphLength();
}
}
} }
@ -305,7 +317,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
if(executor != null){ if(executor != null && isFinishing()){
executor.terminateNonBlock(); executor.terminateNonBlock();
executor.reset(); executor.reset();
executor = null; executor = null;

View file

@ -1,9 +1,11 @@
package com.ericsson.uecontrol.gui.fragments; package com.ericsson.uecontrol.gui.fragments;
import android.app.Fragment; import android.app.Fragment;
import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -28,15 +30,19 @@ import com.jjoe64.graphview.LineGraphView;
* Created by ezivkoc on 2014-07-15. * Created by ezivkoc on 2014-07-15.
*/ */
public class StatusFragment extends Fragment { public class StatusFragment extends Fragment {
private static final int GRAPH_TIME_LENGTH = 60; // in seconds
private ImageView down_img; private ImageView down_img;
private TextView down_speed; private TextView down_speed;
private ImageView up_img; private ImageView up_img;
private TextView up_speed; private TextView up_speed;
private TextView rat_type; private TextView rat_type;
private LineGraphView graphView;
private static GraphViewSeries downGraph; private static GraphViewSeries downGraph;
private static GraphViewSeries upGraph; private static GraphViewSeries upGraph;
private static int x = 0; private static int x = 0;
private static int length = (int) (GRAPH_TIME_LENGTH * ThroughputCalculator.UPDATES_PER_SEC);
private Handler handler; private Handler handler;
@ -62,14 +68,15 @@ public class StatusFragment extends Fragment {
upGraph = new GraphViewSeries("Upload Throughput", new GraphViewSeriesStyle(Color.RED, 3), upGraph = new GraphViewSeries("Upload Throughput", new GraphViewSeriesStyle(Color.RED, 3),
new GraphViewData[]{new GraphViewData(0, 0)}); new GraphViewData[]{new GraphViewData(0, 0)});
LineGraphView graphView = new LineGraphView(this.getActivity(), "GraphView"); graphView = new LineGraphView(this.getActivity(), "GraphView");
graphView.addSeries(downGraph); graphView.addSeries(downGraph);
graphView.addSeries(upGraph); graphView.addSeries(upGraph);
graphView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); graphView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
graphView.getGraphViewStyle().setGridStyle(GraphViewStyle.GridStyle.BOTH); graphView.getGraphViewStyle().setGridStyle(GraphViewStyle.GridStyle.BOTH);
graphView.setShowVerticalLabels(false); graphView.setShowVerticalLabels(false);
//graphView.setDrawDataPoints(true); //graphView.setDrawDataPoints(true);
graphView.setViewPort(0, 120); updateGraphLength();
graphView.setViewPort(0, length);
graphView.setScrollable(true); graphView.setScrollable(true);
graphView.setDisableTouch(true); graphView.setDisableTouch(true);
graphView.scrollToEnd(); graphView.scrollToEnd();
@ -92,8 +99,9 @@ public class StatusFragment extends Fragment {
up_speed.setText(StringUtil.getBitThroughputString(upThroughput)); up_speed.setText(StringUtil.getBitThroughputString(upThroughput));
rat_type.setText(CSVWriter.getRat()); rat_type.setText(CSVWriter.getRat());
downGraph.appendData(new GraphViewData(x, downThroughput), true, 120); graphView.setViewPort(0, length);
upGraph.appendData(new GraphViewData(x, upThroughput), true, 120); downGraph.appendData(new GraphViewData(x, downThroughput), true, length);
upGraph.appendData(new GraphViewData(x, upThroughput), true, length);
x++; x++;
ExecNotification.update(downThroughput, upThroughput); ExecNotification.update(downThroughput, upThroughput);
@ -143,4 +151,11 @@ public class StatusFragment extends Fragment {
}); });
} }
public void updateGraphLength(){
if(this.getActivity() != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
length = (int) (GRAPH_TIME_LENGTH * Float.parseFloat(prefs.getString("throughput_average_freq", "" + ThroughputCalculator.UPDATES_PER_SEC)));
}
}
} }

View file

@ -25,4 +25,28 @@
<item>false</item> <item>false</item>
<item>true</item> <item>true</item>
</string-array> </string-array>
<string-array name="throughput_frequency">
<item>Every 10 sec</item>
<item>Every 5 sec</item>
<item>Every 3 sec</item>
<item>Every 2 sec</item>
<item>Every second</item>
<item>2 times a sec</item>
<item>3 times a sec</item>
<item>5 times a sec</item>
<item>10 times a sec</item>
</string-array>
<string-array name="throughput_frequency_values">
<item>0.1</item>
<item>0.2</item>
<item>0.33</item>
<item>0.5</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>5</item>
<item>10</item>
</string-array>
</resources> </resources>

View file

@ -38,6 +38,8 @@
<string name="action_clear">Clear</string> <string name="action_clear">Clear</string>
<string name="pref_join_beta">Join Beta Program</string> <string name="pref_join_beta">Join Beta Program</string>
<string name="pref_join_beta_summ">Join the Google+ group to get access to the beta releases of the app.</string> <string name="pref_join_beta_summ">Join the Google+ group to get access to the beta releases of the app.</string>
<string name="pref_throughput_average_freq">Throughput Averaging Frequency</string>
<string name="pref_throughput_average_freq_summ">Frequency per second(Will also impact csv logging frequency)</string>
</resources> </resources>

View file

@ -22,6 +22,13 @@
android:entries="@array/throughput_types" android:entries="@array/throughput_types"
android:entryValues="@array/throughput_type_values" android:entryValues="@array/throughput_type_values"
android:defaultValue="false" /> android:defaultValue="false" />
<ListPreference
android:key="throughput_average_freq"
android:title="@string/pref_throughput_average_freq"
android:summary="@string/pref_throughput_average_freq_summ"
android:entries="@array/throughput_frequency"
android:entryValues="@array/throughput_frequency_values"
android:defaultValue="2" />
<CheckBoxPreference <CheckBoxPreference
android:key="screen_on" android:key="screen_on"