Skip to content

Commit

Permalink
#9 benchmark code
Browse files Browse the repository at this point in the history
  • Loading branch information
markhalonen committed Aug 14, 2018
1 parent 70b60d0 commit 4d18ca8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
28 changes: 12 additions & 16 deletions Libraries/src/net/relinc/libraries/dev/TaskMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,27 @@
import java.util.stream.Collectors;

public class TaskMonitor {

private static List<Task> tasks = new ArrayList<Task>();
private static int taskCount = 0;
public static void start(String taskName) {
// If any task with taskName is started but not ended, add error
if(tasks.stream().anyMatch(t -> t.getName().equals(taskName) && t.getStartTime().isPresent() && !t.getEndTime().isPresent())) {
throw new RuntimeException(taskName + " is cannot be started if it's already started!");
}
tasks.add(new Task(taskName, taskCount));
public static int start(String taskName) {
tasks.add(new Task(taskName, ++taskCount));
return taskCount;
}

public static void end(String taskName) {
List<Task> endTasks = tasks.stream()
.filter(t -> t.getName().equals(taskName) && !t.getEndTime().isPresent())
.collect(Collectors.toList());
if(endTasks.size() != 1) {
throw new RuntimeException(taskName + " does not have 1 task to end!");
}
endTasks.get(0).end();
public static void end(int taskId) {
Task endTask = tasks.stream().filter(t -> t.getId() == taskId).findFirst().get();
endTask.end();
}

public static void printTasks() {
System.out.println("==================================================================");
System.out.println("Tasks: " + taskCount);
List<Task> sortedTasks = tasks.stream().sorted((a, b) -> a.getDuration().compareTo(b.getDuration())).collect(Collectors.toList());
sortedTasks.stream().forEach(task -> {
System.out.println(String.format("Task #%d", task.getId()));
System.out.println(task);
});
System.out.println("==================================================================");
}
}

Expand Down Expand Up @@ -99,7 +95,7 @@ public String toString() {
boolean startPresent = this.getStartTime().isPresent();
boolean endPresent = this.getEndTime().isPresent();
if(startPresent && endPresent)
res += String.format("duration (s)=%d\n", this.getDuration().getSeconds());
res += String.format("duration (s)=%.1f\n", this.getDuration().toMillis() * .001);
if(startPresent)
res += String.format("start=%s\n", this.getStartTime().get().toEpochMilli());
if(endPresent)
Expand Down
8 changes: 8 additions & 0 deletions Viewer/src/net/relinc/viewer/GUI/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.relinc.libraries.data.TransmissionPulse;
import net.relinc.libraries.data.ModifierFolder.LowPass;
import net.relinc.libraries.data.ModifierFolder.Modifier;
import net.relinc.libraries.dev.TaskMonitor;
import net.relinc.libraries.fxControls.NumberTextField;
import net.relinc.libraries.sample.CompressionSample;
import net.relinc.libraries.sample.HopkinsonBarSample;
Expand Down Expand Up @@ -996,7 +997,9 @@ public List<String> getCheckedCharts()
return displayedChartListView.getCheckModel().getCheckedItems();
}


public void renderCharts(){
int taskId = TaskMonitor.start("renderCharts");
if(loadDisplacementOnlySampleExists(getCheckedSamples())){
loadDisplacementCB.setSelected(true);
loadDisplacementCB.setDisable(true);
Expand Down Expand Up @@ -1151,6 +1154,8 @@ else if(displayedChartListView.getCheckModel().getCheckedItems().size() == 4){
System.out.println("NONE OF THE CHARTING OPTIONS WERE VALID");
}
charts.stream().forEach(c -> c.setAxisSortingPolicy(LineChart.SortingPolicy.NONE));
TaskMonitor.end(taskId);
TaskMonitor.printTasks();
}


Expand Down Expand Up @@ -1792,11 +1797,14 @@ private LineChartWithMarkers<Number, Number> getStrainTimeChart() {
}

private void renderSampleResults(){
int taskId = TaskMonitor.start("renderSampleResults");
//renders the result object for each sample
for(Sample sample : getCheckedSamples()){
sample.results.render();
}
setROITimeValuesToMaxRange();
TaskMonitor.end(taskId);
TaskMonitor.printTasks();
}

private LineChartWithMarkers<Number, Number> getStressTimeChart() {
Expand Down

0 comments on commit 4d18ca8

Please sign in to comment.