added classes for events

This commit is contained in:
2020-02-28 09:59:00 +01:00
parent 32003a5990
commit d61b808f79
7 changed files with 104 additions and 7 deletions
+1
View File
@@ -37,6 +37,7 @@ dependencies {
implementation 'org.apache.logging.log4j:log4j-iostreams:2.13.0'
implementation 'org.bytedeco:javacv-platform:1.5.2'
implementation 'org.bytedeco:opencv-platform-gpu:4.1.2-1.5.2'
implementation 'com.google.guava:guava:28.2-jre'
testImplementation "junit:junit:${versionJunit}"
testImplementation 'org.assertj:assertj-core:3.6.2'
@@ -9,6 +9,8 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import de.unidue.nes.gpu.events.ApplicationFinishedEvent;
import de.unidue.nes.gpu.events.GpuEventBus;
import de.unidue.nes.gpu.initialization.Initializer;
import de.unidue.nes.gpu.tasks.Task;
import de.unidue.nes.gpu.tasks.taskdefinitions.ThresholdingTask;
@@ -31,14 +33,17 @@ public class GpuTestSystem {
new GpuTestSystem().run();
}
private LoggerContext ctx;
private Configuration config;
private Level originalLevel;
public void run() {
List<Task> tasks = getTasks();
GpuEventBus.INSTANCE.post(() -> tasks);
LOG.info("Running tasks so dlls get loaded");
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final Level originalLevel = config.getRootLogger().getLevel();
config.getRootLogger().setLevel(Level.OFF);
ctx.updateLoggers();
muteLogger();
// run tasks for the first time if some dlls are loaded lazily
tasks.forEach(Task::runTask);
@@ -46,11 +51,26 @@ public class GpuTestSystem {
// run again to be sure that nothing is loaded anymore
tasks.forEach(Task::runTask);// I'm not sure if this is necessary
config.getRootLogger().setLevel(originalLevel);
ctx.updateLoggers();
resetLogger();
LOG.info("Now starting tasks to measure performance");
// now run tasks to get the runtime performance
tasks.forEach(Task::runTask);
GpuEventBus.INSTANCE.post(ApplicationFinishedEvent.EVENT);
}
private void resetLogger() {
this.config.getRootLogger().setLevel(this.originalLevel);
this.ctx.updateLoggers();
}
private void muteLogger() {
this.ctx = (LoggerContext) LogManager.getContext(false);
this.config = this.ctx.getConfiguration();
this.originalLevel = this.config.getRootLogger().getLevel();
this.config.getRootLogger().setLevel(Level.OFF);
this.ctx.updateLoggers();
}
private List<Task> getTasks() {
@@ -0,0 +1,9 @@
package de.unidue.nes.gpu.events;
/**
* @author Roch P., Shahbaz Nejad B.
*
*/
public enum ApplicationFinishedEvent {
EVENT
}
@@ -0,0 +1,13 @@
package de.unidue.nes.gpu.events;
import java.util.List;
import de.unidue.nes.gpu.tasks.Task;
/**
* @author Roch P., Shahbaz Nejad B.
*/
public interface ApplicationStartupEvent {
List<Task> getTasks();
}
@@ -0,0 +1,38 @@
package de.unidue.nes.gpu.events;
import com.google.common.eventbus.EventBus;
/**
* @author Roch P., Shahbaz Nejad B.
*
*/
public class GpuEventBus {
public static final GpuEventBus INSTANCE;
static {
INSTANCE = new GpuEventBus();
}
private EventBus eventBus;
private GpuEventBus() {
this.eventBus = new EventBus();
}
public void register(Object subscriber) {
this.eventBus.register(subscriber);
}
public void post(Object event) {
this.eventBus.post(event);
}
public void post(ApplicationStartupEvent event) {
this.eventBus.post(event);
}
public void post(ApplicationFinishedEvent event) {
this.eventBus.post(event);
}
}
@@ -0,0 +1,8 @@
package de.unidue.nes.gpu.events;
/**
* @author Roch P., Shahbaz Nejad B.
*/
public class TaskFinishedEvent {
}
@@ -0,0 +1,8 @@
package de.unidue.nes.gpu.events;
/**
* @author Roch P., Shahbaz Nejad B.
*/
public class TaskStartedEvent {
}