Im Unify wird nur noch bei SUBST deepCopy angewendet. Timer implementiert zum ermitteln der Zeitaufwendungen der einzelnen Schritte im Algorithmus

This commit is contained in:
JanUlrich 2015-07-14 18:43:54 +02:00
parent e891551b4e
commit c7ffabe0f0
5 changed files with 186 additions and 14 deletions

View File

@ -0,0 +1,50 @@
package de.dhbwstuttgart.logger;
import java.util.Stack;
public class Timestamp{
String name;
Stack<Long> timestamps = new Stack<>();
Long accumulatedTime = 0L;
Timestamp(String name){
this.name = name;
}
public void start(){
timestamps.push(System.currentTimeMillis());
}
public Long stop(){
if(timestamps.isEmpty())return 0L;
Long timeStart = timestamps.pop();
Long currentTime = getTime();
Long difference = currentTime-timeStart;
accumulatedTime += difference;
return difference;
}
public Long currentTime(){
if(timestamps.isEmpty())return 0L;
Long timeStart = timestamps.peek();
Long currentTime = getTime();
return currentTime-timeStart;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Timestamp))return false;
return this.name.equals(((Timestamp)obj).name);
}
public String toString(){
String ret = "Zeit für Aktivität "+this.name+": "+this.accumulatedTime;
return ret;
}
private Long getTime(){
return System.currentTimeMillis();
}
}

View File

@ -0,0 +1,74 @@
package de.dhbwstuttgart.logger;
import java.util.HashMap;
import java.util.Stack;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
public class Timewatch {
private static final Timewatch time = new Timewatch();
private final Timestamp startTime;
private Timers timers = new Timers();
private Timewatch(){
//Privater Konstruktor
startTime = new Timestamp("Timewatch Global");
startTime.start();
}
public static Timewatch getTimewatch() {
return time;
}
public String dumpTimeData(){
String ret = "Momentan insgesamt verstrichene Zeit: "+this.startTime.currentTime() +"\n";
ret += timers.toString();
return ret;
}
public Timestamp start(String name){
if(!timers.contains(name)){
Timestamp ret = new Timestamp(name);
timers.add(ret);
ret.start();
return ret;
}else{
//Timer läuft noch... einfach neue Instanz starten:
Timestamp ret = timers.get(name);
ret.start();
return ret;
}
}
}
class Timers{
private Menge<Timestamp> timers = new Menge<>();
public Timestamp get(String name) {
for(Timestamp timer:timers){
if(timer.name.equals(name))return timer;
}
throw new DebugException("Fehler in Timewatch: Der gesuchte Timer "+name+" ist nicht vorhanden.");
}
public void add(Timestamp timer) {
timers.add(timer);
}
public boolean contains(String name) {
return timers.contains(new Timestamp(name));
}
public String toString(){
String ret ="";
for(Timestamp timer : timers){
ret += timer.toString() + "\n";
}
return ret;
}
}

View File

@ -2,7 +2,14 @@
package de.dhbwstuttgart.typeinference;
// ino.end
// ino.module.Pair.8673.import
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Hashtable;
import de.dhbwstuttgart.typeinference.Menge;
// ino.end
@ -24,7 +31,7 @@ import de.dhbwstuttgart.syntaxtree.type.WildcardType;
// Klasse, die ein Paar in der Menge Eq speichern kann
// ino.end
// ino.class.Pair.26540.declaration
public class Pair
public class Pair implements Serializable
// ino.end
// ino.class.Pair.26540.body
{
@ -405,5 +412,21 @@ public class Pair
ret.add(this.TA2);
return ret;
}
public Pair deepClone() {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(this);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
return (Pair) ois.readObject();
} catch (IOException e) {
return null;
} catch (ClassNotFoundException e) {
return null;
}
}
}
// ino.end

View File

@ -20,6 +20,7 @@ import com.rits.cloning.Cloner;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.logger.SectionLogger;
import de.dhbwstuttgart.logger.Timewatch;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.MatchException;
@ -664,14 +665,16 @@ public class Unify
SectionLogger log = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY);
if(filter){
Cloner cloner = new Cloner();
//Cloner cloner = new Cloner();
Menge<Menge<Menge<Pair>>> temp = new Menge<>(); //hier werden gefilterte Constraints gesammelt
Menge<Pair> undMenge = new Menge<Pair>(); //Die Menge von Pairs, welche in jedem Kartesischen Produkt enthalten sind.
undMenge.addAll(cloner.deepClone(Eq1));
//undMenge.addAll(cloner.deepClone(Eq1));
undMenge.addAll(Eq1);
Menge<Menge<Menge<Pair>>> oderConstraints = new Menge<>();//Die zu filternden Constraints
for (Menge<Menge<Pair>> vecvecpair : cartProduktSets){
if(vecvecpair.size() == 1){//gibt es nur eine UndMenge in diesem Set, dann kommt diese in jedem Karthesischen Produkt vor:
undMenge.addAll(cloner.deepClone(vecvecpair.firstElement()));
//undMenge.addAll(cloner.deepClone(vecvecpair.firstElement()));
undMenge.addAll(vecvecpair.firstElement());
temp.add(vecvecpair);
}else{//gibt es mehrere Mengen, kann gefiltert werden:
oderConstraints.add(vecvecpair); //die Menge zu den zu filternden OderConstraints anfügen
@ -682,8 +685,10 @@ public class Unify
Menge<Menge<Pair>> filteredOCons = new Menge<>(); //diese Menge sammelt nur Cons
for(Menge<Pair> pairs : oderConstraint){
Menge<Pair> testMenge = new Menge<Pair>();
testMenge.addAll(cloner.deepClone(undMenge));
testMenge.addAll(cloner.deepClone(pairs));
//testMenge.addAll(cloner.deepClone(undMenge));
//testMenge.addAll(cloner.deepClone(pairs));
testMenge.addAll(undMenge);
testMenge.addAll(pairs);
Menge<Menge<Pair>> test = Unify.unifyFiltered(testMenge, fc_tto, false);
if(test.size()>0){
filteredOCons.add(pairs);
@ -696,7 +701,7 @@ public class Unify
}
SetView<Menge<Menge<Pair>>> difference = Sets.difference(cartProduktSets, temp);
log.debug("Ausgelöschte Constraints: "+difference.toString());
//cartProduktSets = temp;
cartProduktSets = temp;
/*
Unifier filterUnify = (pairs)->{
String pairsString = pairs.toString();
@ -2462,6 +2467,18 @@ throws MatchException
inferencelog.debug("TV: " + a.getName());
inferencelog.debug("Bedingung: " + bMitVorbedingung);
Cloner cloner = new Cloner();
cloner.setDumpClonedClasses(true);
SectionLogger log = Logger.getSectionLogger("Subst-Methode", Section.UNIFY);
Timewatch timer = Timewatch.getTimewatch();
de.dhbwstuttgart.logger.Timestamp timestamp = timer.start("Unify-Subst");
P = cloner.deepClone(P);
a = cloner.deepClone(a);
o = cloner.deepClone(o);
long time = timestamp.stop();
log.debug("Benötigte Zeit für DeepClone: "+time);
// richtiger Typ aus Pair raussuchen
Type T = null;
if( nTypnrInPair == 1 )
@ -2483,7 +2500,7 @@ throws MatchException
{
// Parameterliste durchgehen
Menge vTemp = ((RefType)T).get_ParaList();
Boolean ret = true; //EINGEFUEGT PL 14-01-16: Return darf erst am Ende zurückgegeben werden und nicht in den ifs
boolean ret = true; //EINGEFUEGT PL 14-01-16: Return darf erst am Ende zurückgegeben werden und nicht in den ifs
//sonst werden nicht alle Elemente der Forschleife durchlaufen
for( int i = 0; i < vTemp.size(); i++ )
{

View File

@ -12,6 +12,7 @@ import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.logger.SectionLogger;
import de.dhbwstuttgart.logger.Timewatch;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
@ -69,12 +70,7 @@ public class MultipleTypesInsertTester extends TypeInsertTester{
for(String containString : mustContain){
TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString));
}
try {
Files.write(Logger.getWholeLog().getBytes(),new File(rootDirectory+sourceFileToInfere+".log"));
} catch (IOException e) {
e.printStackTrace();
TestCase.fail();
}
writeLog(sourceFileToInfere+".log");
}
public static void testSingleInsert(String sourceFileToInfere, Menge<String> mustContain){
@ -106,5 +102,17 @@ public class MultipleTypesInsertTester extends TypeInsertTester{
for(String containString : mustContain){
TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString));
}
writeLog(sourceFileToInfere+".log");
}
private static void writeLog(String toFile){
String log = Logger.getWholeLog()+"\n";
log+=Timewatch.getTimewatch().dumpTimeData();
try {
Files.write(log.getBytes(),new File(rootDirectory+toFile));
} catch (IOException e) {
e.printStackTrace();
TestCase.fail();
}
}
}