Skip to content
Snippets Groups Projects
Commit 9179c6d8 authored by Tobias Oestreicher's avatar Tobias Oestreicher
Browse files

Bugfixing: unvollständiges Logging behoben; verbesserte Trace-Verfolgung im Logging durch Map

parent 95c0524c
No related branches found
No related tags found
No related merge requests found
package de.tud.cs.simqpn.kernel.entities;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.log4j.Logger;
......@@ -13,9 +14,9 @@ import kieker.monitoring.core.controller.MonitoringController;
public class KiekerLogger {
private static Logger log = Logger.getLogger(KiekerLogger.class);
private static final int CONFIG_SHIFT=1000000; //
private static final int IDX_LOGGING_TIMESTAMP=0;
private static final int IDX_OPERATION_SIGNATURE=1;
private static final int IDX_TRACE_ID=2;
......@@ -25,18 +26,16 @@ public class KiekerLogger {
private static final int IDX_HOSTNAME=6;
private static final int IDX_EOI=7;
private static final int IDX_ESS=8;
private static KiekerLogger instance;
private static ArrayList<Object[]> recordList;
private static HashMap<Long,ArrayList<Object[]>> traceIdToLogListMap;
private static Long currentTraceID;
private static IMonitoringController controller;
private static boolean firstRecord =true;
private static boolean initialized=false;
private KiekerLogger() {
......@@ -52,9 +51,8 @@ public class KiekerLogger {
public static void init(){
currentTraceID=-1L;
recordList = new ArrayList<Object[]>();
traceIdToLogListMap = new HashMap<Long, ArrayList<Object[]>>();
Configuration config = ConfigurationFactory.createDefaultConfiguration();
config.setProperty("kieker.monitoring.adaptiveMonitoring.updateConfigFile", "true");
config.setProperty("kieker.monitoring.writer", "kieker.monitoring.writer.filesystem.SyncFsWriter");
......@@ -66,36 +64,37 @@ public class KiekerLogger {
public static void newRecord(double loggingTimestampDouble, String operationSignature, long traceId, String sessionID,double tinDouble, double toutDouble, String hostname){
//initialize globals if not already done
if (!initialized) {
init();
initialized=true;
}
//converting timestamps
Long loggingTimestamp=(long) (loggingTimestampDouble*CONFIG_SHIFT);
Long tin= (long) (tinDouble*CONFIG_SHIFT);
Long tout=(long) (toutDouble*CONFIG_SHIFT);
//Check SessionID
if (sessionID==null || sessionID=="") {
sessionID=OperationExecutionRecord.NO_SESSION_ID;
}
//Check TraceID for changes; if so => push to controller, else keep on collecting info
if (!currentTraceID.equals(traceId)) {
if (!firstRecord) {
updateController();
reset();
} else {
firstRecord=false;
}
currentTraceID=traceId;
ArrayList<Object[]> logList;
if (traceIdToLogListMap.containsKey(traceId)) {
logList=traceIdToLogListMap.get(traceId);
} else {
logList = new ArrayList<Object[]>();
traceIdToLogListMap.put(traceId, logList);
}
//calculate EOI
int currentEOI=0;
for (Object[] dummyRecord : recordList) {
for (Object[] dummyRecord : logList) {
//set EOI
Integer eoi_other = (Integer) dummyRecord[IDX_EOI];
Long tin_other = (Long) dummyRecord[IDX_TIN];
......@@ -106,17 +105,33 @@ public class KiekerLogger {
}
}
recordList.add(new Object[]{loggingTimestamp,operationSignature,traceId,sessionID,tin,tout,hostname,currentEOI,0});
//Problem: last one is not logged
logList.add(new Object[]{loggingTimestamp,operationSignature,traceId,sessionID,tin,tout,hostname,currentEOI,0});
}
private static void reset() {
recordList = new ArrayList<Object[]>();
currentTraceID=-1L;
private static void printLogToConsole(Object[] dummyRec) {
log.info(String.format("$1;%d;%s;%s;%d;%d;%d;%s;%d;%d",
(Long) dummyRec[IDX_LOGGING_TIMESTAMP],
(String) dummyRec[IDX_OPERATION_SIGNATURE],
(String) dummyRec[IDX_SESSION_ID],
(Long) dummyRec[IDX_TRACE_ID],
(Long) dummyRec[IDX_TIN],
(Long) dummyRec[IDX_TOUT],
(String) dummyRec[IDX_HOSTNAME],
(Integer) dummyRec[IDX_EOI],
(Integer) dummyRec[IDX_ESS]));
}
private static void updateController() {
public static void flush(long transactionID) {
ArrayList<Object[]> recordList = traceIdToLogListMap.get(transactionID);
if (recordList==null) {
log.warn("No trace log to close for id: " + transactionID);
return;
}
log.info("### Writing logs for trace id: " + transactionID);
for (Object[] dummyRec : recordList) {
printLogToConsole(dummyRec);
OperationExecutionRecord record = new OperationExecutionRecord(
......@@ -128,35 +143,12 @@ public class KiekerLogger {
(String) dummyRec[IDX_HOSTNAME],
(Integer) dummyRec[IDX_EOI],
(Integer) dummyRec[IDX_ESS]);
record.setLoggingTimestamp((Long) dummyRec[IDX_LOGGING_TIMESTAMP]);
controller.newMonitoringRecord(record);
}
}
private static void printLogToConsole(Object[] dummyRec) {
log.info(String.format("$1;%d;%s;%s;%d;%d;%d;%s;%d;%d",
(Long) dummyRec[IDX_LOGGING_TIMESTAMP],
(String) dummyRec[IDX_OPERATION_SIGNATURE],
(String) dummyRec[IDX_SESSION_ID],
(Long) dummyRec[IDX_TRACE_ID],
(Long) dummyRec[IDX_TIN],
(Long) dummyRec[IDX_TOUT],
(String) dummyRec[IDX_HOSTNAME],
(Integer) dummyRec[IDX_EOI],
(Integer) dummyRec[IDX_ESS]));
traceIdToLogListMap.remove(transactionID);
}
public static void main(String[] args) {
KiekerLogger.newRecord(10, "op1", 1, "session", 1, 9, "user");
KiekerLogger.newRecord(20, "op1", 1, "session", 1, 9, "user");
KiekerLogger.newRecord(30, "op1", 1, "session", 1, 9, "user");
KiekerLogger.newRecord(40, "op1", 2, "session", 1, 9, "user");
KiekerLogger.newRecord(50, "op1", 2, "session", 1, 9, "user");
KiekerLogger.newRecord(60, "op1", 2, "session", 1, 9, "user");
KiekerLogger.newRecord(70, "op1", 3, "session", 1, 9, "user");
KiekerLogger.newRecord(80, "op1", 3, "session", 1, 9, "user");
KiekerLogger.newRecord(90, "op1", 4, "session", 1, 9, "user");
}
}
}
\ No newline at end of file
......@@ -561,16 +561,21 @@ public class Transition extends Node {
//Logging trace
//user->appserver
KiekerLogger.newRecord(
executorOut.getClock(), //logging timestamp
inPlace.name + "." + probe.colors[probeArrayIndex], //operation signature
probe.transactionID, //trace id
null, //session id - probe.startPlace.name
probe.probeStats.name, //session id - probe.startPlace.name
timestamp.timestamp, //tin
executorOut.getClock(), //tout
inPlace.name); //hostname
if (probe.endPlace.name.equals(outPlace.name)) {
KiekerLogger.flush(probe.transactionID);
}
probe.transactionID++;
break;
default:
......@@ -581,15 +586,20 @@ public class Transition extends Node {
executorOut.getClock(), //logging timestamp
inPlace.name + "." + probe.colors[probeArrayIndex], //operation signature
probe.transactionID, //trace id
null, //session id - probe.startPlace.name
probe.probeStats.name, //session id - probe.startPlace.name
timestamp.timestamp, //tin
executorOut.getClock(), //tout
inPlace.name); //hostname
if (probe.endPlace.name.equals(outPlace.name)) {
KiekerLogger.flush(probe.transactionID);
}
outData[probeArrayIndex] = timestamp;
break;
}
}
// Create tokens and put them in the token buffer
for (int i = 0; i < n; i++) {
tkCopyBuffer[i] = new Token(outPlace, c, outData);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment