Added execution time for behaviours.
[artf472315]
This commit is contained in:
parent
8a00a547cf
commit
2ebda08b5d
9 changed files with 78 additions and 36 deletions
|
|
@ -24,7 +24,9 @@ public abstract class UeBehaviour implements Serializable{
|
|||
* Starts to run the behaviour, this method will block until the execution is done
|
||||
*/
|
||||
public void run(){
|
||||
if(execListener != null) execListener.executionStarted();
|
||||
long startTime = System.currentTimeMillis();
|
||||
if(execListener != null)
|
||||
execListener.executionStarted();
|
||||
try {
|
||||
setProgress(0);
|
||||
execute();
|
||||
|
|
@ -32,7 +34,9 @@ public abstract class UeBehaviour implements Serializable{
|
|||
if(execListener != null) execListener.exception(e);
|
||||
log.warn(null, e);
|
||||
}
|
||||
if(execListener != null) execListener.executionStopped();
|
||||
long execTime = System.currentTimeMillis() - startTime;
|
||||
if(execListener != null)
|
||||
execListener.executionStopped(execTime);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,7 +87,7 @@ public abstract class UeBehaviour implements Serializable{
|
|||
public static interface BehaviourExecutionListener {
|
||||
public void executionStarted();
|
||||
public void progressChanged(float progress);
|
||||
public void executionStopped();
|
||||
public void executionStopped(long executionTime);
|
||||
public void exception(Exception e);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.ericsson.uecontrol.core.behaviour;
|
||||
|
||||
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
|
||||
import com.ericsson.uecontrol.core.util.Configurator.Configurable;
|
||||
|
||||
import com.ericsson.uecontrol.core.util.StringUtil;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ public class UeBehaviourFtpUpload extends UeBehaviourFtp {
|
|||
public String toString() {
|
||||
if(sizeOrFile != null && Pattern.matches("\\d*", sizeOrFile)){
|
||||
int size = Integer.parseInt(sizeOrFile);
|
||||
return "Will upload "+ ThroughputCalculator.getByteString(size) +" of random data.";
|
||||
return "Will upload "+ StringUtil.getByteString(size) +" of random data.";
|
||||
}
|
||||
return "Will upload local file "+ sizeOrFile;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class CSVWriter {
|
|||
line.append(header).append(DELIMITER);
|
||||
}
|
||||
writeLine(line.toString());
|
||||
flush();
|
||||
//flush();
|
||||
}
|
||||
|
||||
public void addComment(String str){
|
||||
|
|
|
|||
41
app/src/main/java/com/ericsson/uecontrol/core/util/StringUtil.java
Executable file
41
app/src/main/java/com/ericsson/uecontrol/core/util/StringUtil.java
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
package com.ericsson.uecontrol.core.util;
|
||||
|
||||
/**
|
||||
* Created by ezivkoc on 2015-01-16.
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
private static final String[] BIT_DATA_SIZE = new String[]{"b", "kbit", "Mbit", "Gbit", "Tbit"};
|
||||
public static String getBitThroughputString(double bitsPerSec){
|
||||
return getSizeString(bitsPerSec, 1000, BIT_DATA_SIZE) +"/s";
|
||||
}
|
||||
|
||||
private static final String[] BYTE_DATA_SIZE = new String[]{"B", "KB", "MB", "GB", "TB"};
|
||||
public static String getByteString(double value){
|
||||
return getSizeString(value, 1024, BYTE_DATA_SIZE);
|
||||
}
|
||||
|
||||
private static String getSizeString(double value, int division, String[] sizeList){
|
||||
int index = 0;
|
||||
for(; value > division && index < sizeList.length-1 ;index++) {
|
||||
value /= division;
|
||||
}
|
||||
|
||||
value = (int)(value*10) / 10.0;
|
||||
return value+" "+ sizeList[index];
|
||||
}
|
||||
|
||||
|
||||
public static String getTimeString(long time){
|
||||
int timeSec = (int)(time / 1000);
|
||||
int hours = timeSec / (60*60);
|
||||
int minutes = (timeSec-(hours*60*60)) / 60;
|
||||
int seconds = timeSec-(hours*60*60)-(minutes*60);
|
||||
|
||||
String ret = "";
|
||||
if(hours > 0) ret += hours+"h ";
|
||||
if(minutes > 0) ret += minutes+"m ";
|
||||
if(seconds > 0) ret += seconds+"s ";
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -36,26 +36,4 @@ public class ThroughputCalculator {
|
|||
public boolean isUpdated(){
|
||||
return updated;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static final String[] BIT_DATA_SIZE = new String[]{"b", "kbit", "Mbit", "Gbit", "Tbit"};
|
||||
public static String getBitThroughputString(double bitsPerSec){
|
||||
return getSizeString(bitsPerSec, 1000, BIT_DATA_SIZE) +"/s";
|
||||
}
|
||||
|
||||
private static final String[] BYTE_DATA_SIZE = new String[]{"B", "KB", "MB", "GB", "TB"};
|
||||
public static String getByteString(double value){
|
||||
return getSizeString(value, 1024, BYTE_DATA_SIZE);
|
||||
}
|
||||
|
||||
private static String getSizeString(double value, int division, String[] sizeList){
|
||||
int index = 0;
|
||||
for(; value > division && index < sizeList.length-1 ;index++) {
|
||||
value /= division;
|
||||
}
|
||||
|
||||
value = (int)(value*10) / 10.0;
|
||||
return value+" "+ sizeList[index];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.support.v4.app.NotificationCompat;
|
|||
import android.support.v4.app.TaskStackBuilder;
|
||||
|
||||
import com.ericsson.uecontrol.R;
|
||||
import com.ericsson.uecontrol.core.util.StringUtil;
|
||||
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
|
||||
import com.ericsson.uecontrol.gui.MainActivity;
|
||||
|
||||
|
|
@ -26,8 +27,8 @@ public class ExecNotification {
|
|||
public static void update(double downThroughput, double upThroughput){
|
||||
if(mBuilder != null) {
|
||||
mBuilder.setContentTitle("Exec Behaviour: " + MainActivity.getExecutor().getRunningBehaviour().getName());
|
||||
mBuilder.setContentText(" Down: " + ThroughputCalculator.getBitThroughputString(downThroughput)
|
||||
+ " Up: " + ThroughputCalculator.getBitThroughputString(upThroughput));
|
||||
mBuilder.setContentText(" Down: " + StringUtil.getBitThroughputString(downThroughput)
|
||||
+ " Up: " + StringUtil.getBitThroughputString(upThroughput));
|
||||
setNotification(mBuilder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,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.core.util.CSVWriter;
|
||||
import com.ericsson.uecontrol.core.util.StringUtil;
|
||||
import com.jjoe64.graphview.GraphView.GraphViewData;
|
||||
import com.jjoe64.graphview.GraphViewSeries;
|
||||
import com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle;
|
||||
|
|
@ -88,8 +88,8 @@ public class StatusFragment extends Fragment {
|
|||
down_speed.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
down_speed.setText(ThroughputCalculator.getBitThroughputString(downThroughput));
|
||||
up_speed.setText(ThroughputCalculator.getBitThroughputString(upThroughput));
|
||||
down_speed.setText(StringUtil.getBitThroughputString(downThroughput));
|
||||
up_speed.setText(StringUtil.getBitThroughputString(upThroughput));
|
||||
rat_type.setText(CSVWriter.getRat());
|
||||
|
||||
downGraph.appendData(new GraphViewData(x, downThroughput), true, 120);
|
||||
|
|
@ -137,8 +137,8 @@ public class StatusFragment extends Fragment {
|
|||
down_speed.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
down_speed.setText(ThroughputCalculator.getBitThroughputString(0));
|
||||
up_speed.setText(ThroughputCalculator.getBitThroughputString(0));
|
||||
down_speed.setText(StringUtil.getBitThroughputString(0));
|
||||
up_speed.setText(StringUtil.getBitThroughputString(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.ericsson.uecontrol.R;
|
||||
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||
import com.ericsson.uecontrol.core.util.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -41,6 +42,7 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
|
|||
final ImageView warning = (ImageView) vi.findViewById(R.id.warning);
|
||||
final ProgressBar active = (ProgressBar)vi.findViewById(R.id.active);
|
||||
final ProgressBar progress = (ProgressBar) vi.findViewById(R.id.progress);
|
||||
final TextView time = (TextView) vi.findViewById(R.id.time);
|
||||
|
||||
UeBehaviour behaviour = super.getItem(position);
|
||||
|
||||
|
|
@ -55,6 +57,7 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
|
|||
public void executionStarted() {
|
||||
progress.post(new Runnable() {
|
||||
public void run() {
|
||||
time.setVisibility(View.INVISIBLE);
|
||||
active.setVisibility(View.VISIBLE);
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
warning.setVisibility(View.INVISIBLE);
|
||||
|
|
@ -67,11 +70,13 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
|
|||
executionStarted();
|
||||
progress.setProgress((int) (p * 100));
|
||||
}
|
||||
public void executionStopped() {
|
||||
public void executionStopped(final long execTime) {
|
||||
progress.post(new Runnable() {
|
||||
public void run() {
|
||||
active.setVisibility(View.INVISIBLE);
|
||||
progress.setVisibility(View.INVISIBLE);
|
||||
time.setText(StringUtil.getTimeString(execTime));
|
||||
time.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,5 +76,18 @@
|
|||
android:layout_below="@+id/description"
|
||||
android:visibility="invisible" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="2m 30s"
|
||||
android:id="@+id/time"
|
||||
android:singleLine="true"
|
||||
android:textColor="#46000000"
|
||||
android:textSize="12dp"
|
||||
android:layout_alignBottom="@+id/title"
|
||||
android:layout_alignRight="@+id/progress"
|
||||
android:visibility="invisible" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue