Browse Source

group timer/bandwidth for outputing

Boyang Wei 6 years ago
parent
commit
335530b4b2

+ 4 - 0
src/protocols/Eviction.java

@@ -30,6 +30,10 @@ public class Eviction extends Protocol {
 
 	public Eviction(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.Eviction_on;
+		offline_band = all.Eviction_off;
+		timer = all.Eviction;
 	}
 
 	private int[] prepareEviction(int[] target, int[] ti, int W) {

+ 4 - 0
src/protocols/FlipFlag.java

@@ -15,6 +15,10 @@ public class FlipFlag extends Protocol {
 
 	public FlipFlag(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.FlipFlag_on;
+		offline_band = all.FlipFlag_off;
+		timer = all.FlipFlag;
 	}
 
 	// TODO: remove loop around setXor: use Util.setXor(byte[][], byte[][])

+ 4 - 0
src/protocols/PIRAccess.java

@@ -28,6 +28,10 @@ public class PIRAccess extends Protocol {
 
 	public PIRAccess(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.Access_on;
+		offline_band = all.Access_off;
+		timer = all.Access;
 	}
 
 	public OutPIRAccess runE(Metadata md, Tree tree_DE, Tree tree_CE, byte[] Li, TwoThreeXorByte L, TwoThreeXorByte N,

+ 6 - 0
src/protocols/PIRRetrieve.java

@@ -17,8 +17,10 @@ import struct.OutULiT;
 import struct.Party;
 import struct.TwoThreeXorByte;
 import struct.TwoThreeXorInt;
+import util.Bandwidth;
 import util.M;
 import util.StopWatch;
+import util.Timer;
 import util.Util;
 
 // TODO: really FlipFlag on path, and update path in Eviction
@@ -31,6 +33,10 @@ public class PIRRetrieve extends Protocol {
 
 	public PIRRetrieve(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = new Bandwidth();
+		offline_band = new Bandwidth();
+		timer = new Timer();
 	}
 
 	public void setCons(Communication[] a, Communication[] b) {

+ 18 - 3
src/protocols/Protocol.java

@@ -7,6 +7,7 @@ import oram.Forest;
 import oram.Global;
 import oram.Metadata;
 import struct.Party;
+import struct.TimeAndBandwidth;
 import util.Bandwidth;
 import util.Timer;
 
@@ -17,6 +18,20 @@ public abstract class Protocol {
 	public Bandwidth online_band;
 	public Bandwidth offline_band;
 
+	public static TimeAndBandwidth all;
+
+	static {
+		all = new TimeAndBandwidth();
+	}
+
+	public synchronized void addTime(Timer from, Timer to) {
+		to.add(from);
+	}
+
+	public synchronized void addBand(Bandwidth from, Bandwidth to) {
+		to.add(from);
+	}
+
 	/*
 	 * Connections are alphabetized so:
 	 * 
@@ -29,9 +44,9 @@ public abstract class Protocol {
 	public Protocol(Communication con1, Communication con2) {
 		this.con1 = con1;
 		this.con2 = con2;
-		timer = new Timer();
-		online_band = new Bandwidth("Online");
-		offline_band = new Bandwidth("Offline");
+		// timer = new Timer();
+		// online_band = new Bandwidth();
+		// offline_band = new Bandwidth();
 	}
 
 	private static final boolean ENSURE_SANITY = true;

+ 8 - 0
src/protocols/ULiT.java

@@ -24,12 +24,20 @@ public class ULiT extends Protocol {
 
 	public ULiT(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.ULiT_on;
+		offline_band = all.ULiT_off;
+		timer = all.ULiT;
 	}
 
 	public ULiT(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
 		super(con1, con2);
 		this.sr1 = sr1;
 		this.sr2 = sr2;
+
+		online_band = all.ULiT_on;
+		offline_band = all.ULiT_off;
+		timer = all.ULiT;
 	}
 
 	public void reinit(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {

+ 4 - 0
src/protocols/UpdateRoot.java

@@ -27,6 +27,10 @@ public class UpdateRoot extends Protocol {
 
 	public UpdateRoot(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.UpdateRoot_on;
+		offline_band = all.UpdateRoot_off;
+		timer = all.UpdateRoot;
 	}
 
 	public Tuple[] runE(boolean firstTree, int sw, int lBits, int[] tupleParam, byte[] Li, Tuple[] R, Tuple Ti) {

+ 121 - 0
src/struct/TimeAndBandwidth.java

@@ -0,0 +1,121 @@
+package struct;
+
+import util.Bandwidth;
+import util.Timer;
+
+public class TimeAndBandwidth {
+	public Bandwidth KSearch_on;
+	public Bandwidth KSearch_off;
+
+	public Bandwidth SSPIR_on;
+	public Bandwidth SSPIR_off;
+	public Bandwidth ShiftPIR_on;
+	public Bandwidth ShiftPIR_off;
+	public Bandwidth ThreeShiftPIR_on;
+	public Bandwidth ThreeShiftPIR_off;
+	public Bandwidth ShiftXorPIR_on;
+	public Bandwidth ShiftXorPIR_off;
+	public Bandwidth ThreeShiftXorPIR_on;
+	public Bandwidth ThreeShiftXorPIR_off;
+
+	public Bandwidth InsLbl_on;
+	public Bandwidth InsLbl_off;
+	public Bandwidth ULiT_on;
+	public Bandwidth ULiT_off;
+
+	public Bandwidth Shift_on;
+	public Bandwidth Shift_off;
+	public Bandwidth FlipFlag_on;
+	public Bandwidth FlipFlag_off;
+
+	public Bandwidth SSXOT_on;
+	public Bandwidth SSXOT_off;
+	public Bandwidth UpdateRoot_on;
+	public Bandwidth UpdateRoot_off;
+	public Bandwidth PermBucket_on;
+	public Bandwidth PermBucket_off;
+	public Bandwidth PermTuple_on;
+	public Bandwidth PermTuple_off;
+
+	public Bandwidth Access_on;
+	public Bandwidth Access_off;
+
+	public Bandwidth PostProcess_on;
+	public Bandwidth PostProcess_off;
+
+	public Bandwidth Eviction_on;
+	public Bandwidth Eviction_off;
+
+	public Timer KSearch;
+	public Timer SSPIR;
+	public Timer ShiftPIR;
+	public Timer ThreeShiftPIR;
+	public Timer ShiftXorPIR;
+	public Timer ThreeShiftXorPIR;
+	public Timer InsLbl;
+	public Timer ULiT;
+	public Timer Shift;
+	public Timer FlipFlag;
+	public Timer SSXOT;
+	public Timer UpdateRoot;
+	public Timer PermBucket;
+	public Timer PermTuple;
+	public Timer Access;
+	public Timer PostProcess;
+	public Timer Eviction;
+
+	public TimeAndBandwidth() {
+		KSearch_on = new Bandwidth();
+		KSearch_off = new Bandwidth();
+		SSPIR_on = new Bandwidth();
+		SSPIR_off = new Bandwidth();
+		ShiftPIR_on = new Bandwidth();
+		ShiftPIR_off = new Bandwidth();
+		ThreeShiftPIR_on = new Bandwidth();
+		ThreeShiftPIR_off = new Bandwidth();
+		ShiftXorPIR_on = new Bandwidth();
+		ShiftXorPIR_off = new Bandwidth();
+		ThreeShiftXorPIR_on = new Bandwidth();
+		ThreeShiftXorPIR_off = new Bandwidth();
+		InsLbl_on = new Bandwidth();
+		InsLbl_off = new Bandwidth();
+		ULiT_on = new Bandwidth();
+		ULiT_off = new Bandwidth();
+		Shift_on = new Bandwidth();
+		Shift_off = new Bandwidth();
+		FlipFlag_on = new Bandwidth();
+		FlipFlag_off = new Bandwidth();
+		SSXOT_on = new Bandwidth();
+		SSXOT_off = new Bandwidth();
+		UpdateRoot_on = new Bandwidth();
+		UpdateRoot_off = new Bandwidth();
+		PermBucket_on = new Bandwidth();
+		PermBucket_off = new Bandwidth();
+		PermTuple_on = new Bandwidth();
+		PermTuple_off = new Bandwidth();
+		Access_on = new Bandwidth();
+		Access_off = new Bandwidth();
+		PostProcess_on = new Bandwidth();
+		PostProcess_off = new Bandwidth();
+		Eviction_on = new Bandwidth();
+		Eviction_off = new Bandwidth();
+
+		KSearch = new Timer();
+		SSPIR = new Timer();
+		ShiftPIR = new Timer();
+		ThreeShiftPIR = new Timer();
+		ShiftXorPIR = new Timer();
+		ThreeShiftXorPIR = new Timer();
+		InsLbl = new Timer();
+		ULiT = new Timer();
+		Shift = new Timer();
+		FlipFlag = new Timer();
+		SSXOT = new Timer();
+		UpdateRoot = new Timer();
+		PermBucket = new Timer();
+		PermTuple = new Timer();
+		Access = new Timer();
+		PostProcess = new Timer();
+		Eviction = new Timer();
+	}
+}

+ 8 - 0
src/subprotocols/InsLbl.java

@@ -20,12 +20,20 @@ public class InsLbl extends Protocol {
 
 	public InsLbl(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.InsLbl_on;
+		offline_band = all.InsLbl_off;
+		timer = all.InsLbl;
 	}
 
 	public InsLbl(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
 		super(con1, con2);
 		this.sr1 = sr1;
 		this.sr2 = sr2;
+
+		online_band = all.InsLbl_on;
+		offline_band = all.InsLbl_off;
+		timer = all.InsLbl;
 	}
 
 	public void reinit(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {

+ 4 - 0
src/subprotocols/PIRCOT.java

@@ -18,6 +18,10 @@ public class PIRCOT extends Protocol {
 
 	public PIRCOT(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.KSearch_on;
+		offline_band = all.KSearch_off;
+		timer = all.KSearch;
 	}
 
 	public OutPIRCOT runE(byte[][] u, byte[] v) {

+ 4 - 0
src/subprotocols/PermuteIndex.java

@@ -16,6 +16,10 @@ public class PermuteIndex extends Protocol {
 
 	public PermuteIndex(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.PermTuple_on;
+		offline_band = all.PermTuple_off;
+		timer = all.PermTuple;
 	}
 
 	public void runE(int w, int[] evict_pi) {

+ 4 - 0
src/subprotocols/PermuteTarget.java

@@ -19,6 +19,10 @@ public class PermuteTarget extends Protocol {
 
 	public PermuteTarget(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.PermBucket_on;
+		offline_band = all.PermBucket_off;
+		timer = all.PermBucket;
 	}
 
 	public void runE(int d, int[] evict_pi, GCSignal[][][] evict_targetOutKeyPairs) {

+ 8 - 0
src/subprotocols/SSPIR.java

@@ -19,12 +19,20 @@ public class SSPIR extends Protocol {
 
 	public SSPIR(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.SSPIR_on;
+		offline_band = all.SSPIR_off;
+		timer = all.SSPIR;
 	}
 
 	public SSPIR(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
 		super(con1, con2);
 		this.sr1 = sr1;
 		this.sr2 = sr2;
+
+		online_band = all.SSPIR_on;
+		offline_band = all.SSPIR_off;
+		timer = all.SSPIR;
 	}
 
 	public void reinit(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {

+ 4 - 0
src/subprotocols/SSXOT.java

@@ -19,6 +19,10 @@ public class SSXOT extends Protocol {
 
 	public SSXOT(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.SSXOT_on;
+		offline_band = all.SSXOT_off;
+		timer = all.SSXOT;
 	}
 
 	public Tuple[] runE(Tuple[] m, int[] tupleParam) {

+ 4 - 0
src/subprotocols/Shift.java

@@ -14,6 +14,10 @@ public class Shift extends Protocol {
 
 	public Shift(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.Shift_on;
+		offline_band = all.Shift_off;
+		timer = all.Shift;
 	}
 
 	public byte[][] runE(byte[][] x, int s) {

+ 8 - 0
src/subprotocols/ShiftPIR.java

@@ -19,12 +19,20 @@ public class ShiftPIR extends Protocol {
 
 	public ShiftPIR(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.ShiftPIR_on;
+		offline_band = all.ShiftPIR_off;
+		timer = all.ShiftPIR;
 	}
 
 	public ShiftPIR(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
 		super(con1, con2);
 		this.sr1 = sr1;
 		this.sr2 = sr2;
+
+		online_band = all.ShiftPIR_on;
+		offline_band = all.ShiftPIR_off;
+		timer = all.ShiftPIR;
 	}
 
 	public void reinit(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {

+ 8 - 0
src/subprotocols/ShiftXorPIR.java

@@ -20,12 +20,20 @@ public class ShiftXorPIR extends Protocol {
 
 	public ShiftXorPIR(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.ShiftXorPIR_on;
+		offline_band = all.ShiftXorPIR_off;
+		timer = all.ShiftXorPIR;
 	}
 
 	public ShiftXorPIR(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
 		super(con1, con2);
 		this.sr1 = sr1;
 		this.sr2 = sr2;
+
+		online_band = all.ShiftXorPIR_on;
+		offline_band = all.ShiftXorPIR_off;
+		timer = all.ShiftXorPIR;
 	}
 
 	public void reinit(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {

+ 8 - 0
src/subprotocols/ThreeShiftPIR.java

@@ -21,12 +21,20 @@ public class ThreeShiftPIR extends Protocol {
 
 	public ThreeShiftPIR(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.ThreeShiftPIR_on;
+		offline_band = all.ThreeShiftPIR_off;
+		timer = all.ThreeShiftPIR;
 	}
 
 	public ThreeShiftPIR(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
 		super(con1, con2);
 		this.sr1 = sr1;
 		this.sr2 = sr2;
+
+		online_band = all.ThreeShiftPIR_on;
+		offline_band = all.ThreeShiftPIR_off;
+		timer = all.ThreeShiftPIR;
 	}
 
 	public void reinit(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {

+ 8 - 0
src/subprotocols/ThreeShiftXorPIR.java

@@ -23,12 +23,20 @@ public class ThreeShiftXorPIR extends Protocol {
 
 	public ThreeShiftXorPIR(Communication con1, Communication con2) {
 		super(con1, con2);
+
+		online_band = all.ThreeShiftXorPIR_on;
+		offline_band = all.ThreeShiftXorPIR_off;
+		timer = all.ThreeShiftXorPIR;
 	}
 
 	public ThreeShiftXorPIR(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {
 		super(con1, con2);
 		this.sr1 = sr1;
 		this.sr2 = sr2;
+
+		online_band = all.ThreeShiftXorPIR_on;
+		offline_band = all.ThreeShiftXorPIR_off;
+		timer = all.ThreeShiftXorPIR;
 	}
 
 	public void reinit(Communication con1, Communication con2, SecureRandom sr1, SecureRandom sr2) {

+ 12 - 1
src/util/Bandwidth.java

@@ -7,6 +7,11 @@ public class Bandwidth {
 	public String task;
 	public long bandwidth;
 
+	public Bandwidth() {
+		task = "";
+		bandwidth = 0;
+	}
+
 	public Bandwidth(String t) {
 		task = t;
 		bandwidth = 0;
@@ -25,7 +30,7 @@ public class Bandwidth {
 		bandwidth += n;
 	}
 
-	public Bandwidth add(Bandwidth b) {
+	public Bandwidth addAndReturn(Bandwidth b) {
 		if (!task.equals(b.task))
 			throw new BandwidthException("Task: " + task + " != " + b.task);
 		Bandwidth total = new Bandwidth(task);
@@ -33,6 +38,12 @@ public class Bandwidth {
 		return total;
 	}
 
+	public void add(Bandwidth b) {
+		if (!task.equals(b.task))
+			throw new BandwidthException("Task: " + task + " != " + b.task);
+		bandwidth += b.bandwidth;
+	}
+
 	public String noPreToString() {
 		return "" + bandwidth;
 	}

+ 22 - 1
src/util/StopWatch.java

@@ -108,7 +108,7 @@ public class StopWatch {
 		return sw;
 	}
 
-	public StopWatch add(StopWatch s) {
+	public StopWatch addAndReturn(StopWatch s) {
 		if (isOn || s.isOn) {
 			try {
 				throw new StopWatchException("StopWatch is still running");
@@ -130,4 +130,25 @@ public class StopWatch {
 		sw.elapsedCPU = elapsedCPU + s.elapsedCPU;
 		return sw;
 	}
+
+	public void add(StopWatch s) {
+		if (isOn || s.isOn) {
+			try {
+				throw new StopWatchException("StopWatch is still running");
+			} catch (StopWatchException e) {
+				e.printStackTrace();
+			}
+		}
+
+		if (!task.equals(s.task)) {
+			try {
+				throw new StopWatchException("Tasks don't match: " + task + " != " + s.task);
+			} catch (StopWatchException e) {
+				e.printStackTrace();
+			}
+		}
+
+		elapsedWC += s.elapsedWC;
+		elapsedCPU += s.elapsedCPU;
+	}
 }

+ 18 - 6
src/util/Timer.java

@@ -6,18 +6,20 @@ import exceptions.TimerException;
 
 public class Timer {
 	StopWatch[] watches;
-	Stack<StopWatch> stack;
+	static Stack<StopWatch> stack;
+
+	static {
+		stack = new Stack<StopWatch>();
+	}
 
 	public Timer() {
 		watches = new StopWatch[M.size];
 		for (int j = 0; j < M.size; j++)
 			watches[j] = new StopWatch(M.names[j]);
-		stack = new Stack<StopWatch>();
 	}
 
 	public Timer(StopWatch[] sws) {
 		watches = sws;
-		stack = new Stack<StopWatch>();
 	}
 
 	public void start(int m) {
@@ -70,13 +72,23 @@ public class Timer {
 		return new Timer(sws);
 	}
 
-	public Timer add(Timer t) {
-		if (!stack.empty() || !t.stack.empty())
+	public Timer addAndReturn(Timer t) {
+		// if (!stack.empty() || !t.stack.empty())
+		if (!stack.empty())
 			throw new TimerException("Stack not empty");
 
 		StopWatch[] sws = new StopWatch[M.size];
 		for (int i = 0; i < watches.length; i++)
-			sws[i] = watches[i].add(t.watches[i]);
+			sws[i] = watches[i].addAndReturn(t.watches[i]);
 		return new Timer(sws);
 	}
+
+	public void add(Timer t) {
+		// if (!stack.empty() || !t.stack.empty())
+		if (!stack.empty())
+			throw new TimerException("Stack not empty");
+
+		for (int i = 0; i < watches.length; i++)
+			watches[i].add(t.watches[i]);
+	}
 }