From 7b3c865381a25e07fadf6e328226e94ae2ac9f5b Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Sat, 18 May 2013 18:38:32 +0200 Subject: [PATCH] added logging to scheduler --- .../tuwien/lsdc/sched/AbstractScheduler.java | 32 +++++++++++++++---- src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 3 +- src/at/ac/tuwien/lsdc/sched/SchedulerB.java | 3 +- src/at/ac/tuwien/lsdc/sched/SchedulerC.java | 3 +- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index 53261cf..1de5046 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -1,14 +1,19 @@ package at.ac.tuwien.lsdc.sched; import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import at.ac.tuwien.lsdc.types.Application; import at.ac.tuwien.lsdc.types.ScenarioData; import at.ac.tuwien.lsdc.types.ScenarioType; +import at.ac.tuwien.lsdc.types.SchedulerData; import at.ac.tuwien.lsdc.types.SchedulerEvent; import at.ac.tuwien.lsdc.types.SchedulerType; +import at.ac.tuwien.lsdc.util.CSVLogger; public abstract class AbstractScheduler { @@ -18,13 +23,16 @@ public abstract class AbstractScheduler { protected ScenarioType scenario; protected int numInSourced; protected int numOutSourced; + protected int numCurrInSourced; + protected int numCurrOutSourced; - File logFile; + File schedulerLog; + CSVLogger logger; // this map saves the following Type of Events: // start of an Application, end of an Application // (start outSourced, end outSourced, start inSourced, end inSourced) - protected Map> eventMap; + protected HashMap> eventMap; // Scheduler has an internal Time "Abstraction" // at every point in time it checks for Events in his "EventList" @@ -35,10 +43,12 @@ public abstract class AbstractScheduler { // it is updated with every added "EndEvent" protected long endTime; - public AbstractScheduler(File logFile, SchedulerType schedulerType, ScenarioType scenario) { - this.logFile = logFile; + public AbstractScheduler(File schedulerLog, SchedulerType schedulerType, ScenarioType scenario) throws IOException { + this.schedulerLog = schedulerLog; this.schedulerType = schedulerType; this.scenario = scenario; + this.eventMap = new HashMap>(); + this.logger = new CSVLogger(schedulerLog); } // Initialize Scheduler with Data from CSV @@ -49,7 +59,12 @@ public abstract class AbstractScheduler { // read start timestamp // save event in map } - //startScheduling(); + startScheduling(); + try { + logger.close(); + } catch (IOException e) { + System.err.println("couldn't close logger"); + } return doEndLogging(); } @@ -71,7 +86,12 @@ public abstract class AbstractScheduler { protected abstract void handleEvents(LinkedList events); protected void doStateLogging() { - // at every timestamp (after handle Event) + SchedulerData data = new SchedulerData(currTime,1,1,1,1,1,1,numCurrInSourced,numCurrOutSourced); + try { + logger.logSchedulerData(data); + } catch (IOException e) { + System.err.println("error logging data"); + } } // this creates the total summary which should be written to a CSV at the diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index 17d991d..91588d2 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -1,6 +1,7 @@ package at.ac.tuwien.lsdc.sched; import java.io.File; +import java.io.IOException; import java.util.LinkedList; import at.ac.tuwien.lsdc.types.ScenarioType; @@ -10,7 +11,7 @@ import at.ac.tuwien.lsdc.types.SchedulerType; public class SchedulerA extends AbstractScheduler { - public SchedulerA(File logFile, SchedulerType schedulerType, ScenarioType scenario) { + public SchedulerA(File logFile, SchedulerType schedulerType, ScenarioType scenario) throws IOException { super(logFile, schedulerType, scenario); } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java index 2784bad..4e54be1 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java @@ -1,6 +1,7 @@ package at.ac.tuwien.lsdc.sched; import java.io.File; +import java.io.IOException; import java.util.LinkedList; import at.ac.tuwien.lsdc.types.ScenarioType; @@ -10,7 +11,7 @@ import at.ac.tuwien.lsdc.types.SchedulerType; public class SchedulerB extends AbstractScheduler { - public SchedulerB(File logFile, SchedulerType schedulerType, ScenarioType scenario) { + public SchedulerB(File logFile, SchedulerType schedulerType, ScenarioType scenario) throws IOException { super(logFile, schedulerType, scenario); } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java index bafd084..cc21496 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java @@ -1,6 +1,7 @@ package at.ac.tuwien.lsdc.sched; import java.io.File; +import java.io.IOException; import java.util.LinkedList; import at.ac.tuwien.lsdc.types.ScenarioType; @@ -10,7 +11,7 @@ import at.ac.tuwien.lsdc.types.SchedulerType; public class SchedulerC extends AbstractScheduler { - public SchedulerC(File logFile, SchedulerType schedulerType, ScenarioType scenario) { + public SchedulerC(File logFile, SchedulerType schedulerType, ScenarioType scenario) throws IOException { super(logFile,schedulerType,scenario); } -- 2.43.0