RLPark 1.0.0
Reinforcement Learning Framework in Java

ServerLog.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.experiments.scheduling.internal.serverlog;
00002 
00003 import java.io.IOException;
00004 import java.util.Set;
00005 
00006 import rlpark.plugin.rltoys.experiments.scheduling.interfaces.TimedJob;
00007 import rlpark.plugin.rltoys.experiments.scheduling.internal.messages.Messages;
00008 import rlpark.plugin.rltoys.experiments.scheduling.internal.network.SocketClient;
00009 import zephyr.plugin.core.api.internal.monitoring.fileloggers.LoggerRow;
00010 import zephyr.plugin.core.api.synchronization.Chrono;
00011 
00012 @SuppressWarnings("restriction")
00013 public class ServerLog {
00014   private final LoggerRow clientsLog;
00015   private final LoggerRow jobsLog;
00016   private final Chrono chrono = new Chrono();
00017   private long cumulatedTime = 0;
00018 
00019   public ServerLog() {
00020     try {
00021       clientsLog = new LoggerRow("./clients.logtxt");
00022       jobsLog = new LoggerRow("./jobs.logtxt");
00023     } catch (IOException e) {
00024       throw new RuntimeException(e);
00025     }
00026     clientsLog.writeLegend("RealTime", "Clients", "Threads", "Cores");
00027     jobsLog.writeLegend("RealTime", "CumulatedTime", "Ratio");
00028   }
00029 
00030   public void clientEvent(Set<SocketClient> clients, String message) {
00031     int nbCores = 0;
00032     int nbThreads = 0;
00033     for (SocketClient client : clients) {
00034       nbCores += client.clientInfo().nbCores;
00035       nbThreads += client.clientInfo().nbThreads;
00036     }
00037     clientsLog.writeRow(chrono.getCurrentMillis(), clients.size(), nbThreads, nbCores);
00038     Messages.println(String.format("%s %d[%d] client%s", message, clients.size(), nbThreads, clients.size() > 1 ? "s"
00039         : ""));
00040   }
00041 
00042   public void jobEvent(Runnable done) {
00043     if (!(done instanceof TimedJob))
00044       return;
00045     cumulatedTime += ((TimedJob) done).getComputationTimeMillis();
00046     double ratio = cumulatedTime / (double) chrono.getCurrentMillis();
00047     jobsLog.writeRow(chrono.getCurrentMillis(), cumulatedTime, ratio);
00048   }
00049 
00050   public void close() {
00051     clientsLog.close();
00052     jobsLog.close();
00053   }
00054 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark