This is an automated email from the ASF dual-hosted git repository.
sebwrede pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push:
new 853ecd7353 [MINOR] Add FederatedCompilationTimer
853ecd7353 is described below
commit 853ecd73537a3c6f3d0352f272048ba7e519eefe
Author: sebwrede <[email protected]>
AuthorDate: Tue Aug 2 15:25:43 2022 +0200
[MINOR] Add FederatedCompilationTimer
Closes #1674.
---
.../hops/fedplanner/FederatedCompilationTimer.java | 135 +++++++++++++++++++++
.../hops/fedplanner/FederatedPlannerCostbased.java | 15 ++-
.../hops/fedplanner/PrivacyConstraintLoader.java | 6 +
.../java/org/apache/sysds/utils/Statistics.java | 2 +
4 files changed, 157 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/apache/sysds/hops/fedplanner/FederatedCompilationTimer.java
b/src/main/java/org/apache/sysds/hops/fedplanner/FederatedCompilationTimer.java
new file mode 100644
index 0000000000..fcbffd5187
--- /dev/null
+++
b/src/main/java/org/apache/sysds/hops/fedplanner/FederatedCompilationTimer.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.hops.fedplanner;
+
+import org.apache.sysds.utils.Statistics;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FederatedCompilationTimer {
+ private static final List<TimeEntry> times = new ArrayList<>();
+ private static TimeEntry privProcessTime;
+ private static TimeEntry enumerationTime;
+ private static TimeEntry selectPlanTime;
+ private static boolean activated = false;
+
+ public static class TimeEntry {
+ private final long startTime;
+ private long stopTime;
+ private long duration;
+ private String name;
+
+ public TimeEntry(String name){
+ this.name = name;
+ this.startTime = System.nanoTime();
+ }
+
+ public void stopTime(){
+ this.stopTime = System.nanoTime();
+ this.duration = stopTime-startTime;
+ }
+
+ public boolean is(String searchName){
+ return name.contains(searchName);
+ }
+
+ public long getDuration(){
+ return duration;
+ }
+ }
+
+ public static TimeEntry startPrivProcessTimer(){
+ privProcessTime = new TimeEntry("PrivProcess");
+ times.add(privProcessTime);
+ return privProcessTime;
+ }
+
+ public static TimeEntry stopPrivProcessTimer(){
+ privProcessTime.stopTime();
+ return privProcessTime;
+ }
+
+ public static TimeEntry startPrivFetchTimer(long hopID){
+ TimeEntry privFetchTimer = new TimeEntry("PrivFetch"+hopID);
+ times.add(privFetchTimer);
+ return privFetchTimer;
+ }
+
+ public static void startEnumerationTimer(){
+ enumerationTime = new TimeEntry("Enumeration");
+ times.add(enumerationTime);
+ }
+
+ public static void stopEnumerationTimer(){
+ enumerationTime.stopTime();
+ }
+
+ public static void startSelectPlanTimer(){
+ selectPlanTime = new TimeEntry("Selection");
+ times.add(selectPlanTime);
+ }
+
+ public static void stopSelectPlanTimer(){
+ selectPlanTime.stopTime();
+ }
+
+ private static long getTotalFetchTime(){
+ return times.stream().filter(t ->
t.is("PrivFetch")).map(TimeEntry::getDuration)
+ .reduce(0L, Long::sum);
+ }
+
+ private static long getBasicCompileTime(){
+ return Statistics.getCompileTime() -
privProcessTime.getDuration()
+ - enumerationTime.getDuration() -
selectPlanTime.getDuration();
+ }
+
+ private static String nanoToSeconds(long nanoSeconds){
+ return (String.format("%.3f", nanoSeconds*1e-9) + " sec.");
+ }
+
+ public static String getStringRepresentation(){
+ if (activated && timesNotNull()){
+ long totalFetchTime = getTotalFetchTime();
+ long privPropagationTime =
privProcessTime.getDuration()-totalFetchTime;
+ long basicCompileTime = getBasicCompileTime();
+ StringBuilder sb = new StringBuilder();
+ sb.append("Basic Compilation
Time:\t\t").append(nanoToSeconds(basicCompileTime)).append("\n");
+ sb.append("Total Privacy Fetch
Time:\t").append(nanoToSeconds(totalFetchTime)).append("\n");
+ sb.append("Privacy Propagation
Time:\t").append(nanoToSeconds(privPropagationTime)).append("\n");
+ sb.append("Plan Enumeration
Time:\t\t").append(nanoToSeconds(enumerationTime.getDuration())).append("\n");
+ sb.append("Plan Selection
Time:\t\t").append(nanoToSeconds(selectPlanTime.getDuration())).append("\n");
+ return sb.toString();
+ }
+ else return "";
+ }
+
+ private static boolean timesNotNull(){
+ return privProcessTime != null && enumerationTime != null &&
selectPlanTime != null;
+ }
+
+ public static void activate(){
+ activated = true;
+ }
+
+ public static void display(){
+ System.out.println(getStringRepresentation());
+ }
+}
diff --git
a/src/main/java/org/apache/sysds/hops/fedplanner/FederatedPlannerCostbased.java
b/src/main/java/org/apache/sysds/hops/fedplanner/FederatedPlannerCostbased.java
index d809544f6b..6df8a3982f 100644
---
a/src/main/java/org/apache/sysds/hops/fedplanner/FederatedPlannerCostbased.java
+++
b/src/main/java/org/apache/sysds/hops/fedplanner/FederatedPlannerCostbased.java
@@ -84,10 +84,23 @@ public class FederatedPlannerCostbased extends
AFederatedPlanner {
@Override
public void rewriteProgram( DMLProgram prog, FunctionCallGraph fgraph,
FunctionCallSizeInfo fcallSizes ) {
+ enumeratePlans(prog);
+ selectPlan();
+ updateExplain();
+ FederatedCompilationTimer.activate();
+ }
+
+ private void enumeratePlans(DMLProgram prog){
+ FederatedCompilationTimer.startEnumerationTimer();
prog.updateRepetitionEstimates();
rewriteStatementBlocks(prog, prog.getStatementBlocks(), null);
+ FederatedCompilationTimer.stopEnumerationTimer();
+ }
+
+ private void selectPlan(){
+ FederatedCompilationTimer.startSelectPlanTimer();
setFinalFedouts();
- updateExplain();
+ FederatedCompilationTimer.stopSelectPlanTimer();
}
@Override
diff --git
a/src/main/java/org/apache/sysds/hops/fedplanner/PrivacyConstraintLoader.java
b/src/main/java/org/apache/sysds/hops/fedplanner/PrivacyConstraintLoader.java
index bb8d3b7107..8a977ecf26 100644
---
a/src/main/java/org/apache/sysds/hops/fedplanner/PrivacyConstraintLoader.java
+++
b/src/main/java/org/apache/sysds/hops/fedplanner/PrivacyConstraintLoader.java
@@ -28,6 +28,7 @@ import org.apache.sysds.hops.FunctionOp;
import org.apache.sysds.hops.Hop;
import org.apache.sysds.hops.LiteralOp;
import org.apache.sysds.hops.rewrite.HopRewriteUtils;
+import org.apache.sysds.hops.fedplanner.FederatedCompilationTimer.TimeEntry;
import org.apache.sysds.parser.DMLProgram;
import org.apache.sysds.parser.DataExpression;
import org.apache.sysds.parser.DataIdentifier;
@@ -78,7 +79,9 @@ public class PrivacyConstraintLoader {
private LocalVariableMap localVariableMap = new LocalVariableMap();
public void loadConstraints(DMLProgram prog){
+ FederatedCompilationTimer.startPrivProcessTimer();
rewriteStatementBlocks(prog, prog.getStatementBlocks(), null);
+ FederatedCompilationTimer.stopPrivProcessTimer();
}
private void rewriteStatementBlocks(DMLProgram prog,
List<StatementBlock> sbs, Map<String, Hop> paramMap) {
@@ -196,6 +199,7 @@ public class PrivacyConstraintLoader {
* @param hop for which privacy constraints are loaded
*/
public void loadFederatedPrivacyConstraints(Hop hop){
+ TimeEntry fetchTime =
FederatedCompilationTimer.startPrivFetchTimer(hop.getHopID());
try {
PrivacyConstraint.PrivacyLevel constraintLevel =
hop.getInput(0).getInput().stream().parallel()
.map( in -> ((LiteralOp)in).getStringValue() )
@@ -217,6 +221,8 @@ public class PrivacyConstraintLoader {
}
catch(Exception ex) {
throw new DMLException(ex);
+ } finally {
+ fetchTime.stopTime();
}
}
diff --git a/src/main/java/org/apache/sysds/utils/Statistics.java
b/src/main/java/org/apache/sysds/utils/Statistics.java
index 454ecac6e1..ca359a46e6 100644
--- a/src/main/java/org/apache/sysds/utils/Statistics.java
+++ b/src/main/java/org/apache/sysds/utils/Statistics.java
@@ -24,6 +24,7 @@ import org.apache.commons.lang3.tuple.Pair;
import org.apache.sysds.api.DMLScript;
import org.apache.sysds.conf.ConfigurationManager;
import org.apache.sysds.hops.OptimizerUtils;
+import org.apache.sysds.hops.fedplanner.FederatedCompilationTimer;
import org.apache.sysds.runtime.controlprogram.caching.CacheStatistics;
import org.apache.sysds.runtime.controlprogram.federated.FederatedStatistics;
import org.apache.sysds.runtime.instructions.Instruction;
@@ -599,6 +600,7 @@ public class Statistics
if( DMLScript.STATISTICS ) {
sb.append("Total elapsed time:\t\t" +
String.format("%.3f", (getCompileTime()+getRunTime())*1e-9) + " sec.\n"); //
nanoSec --> sec
sb.append("Total compilation time:\t\t" +
String.format("%.3f", getCompileTime()*1e-9) + " sec.\n"); // nanoSec --> sec
+
sb.append(FederatedCompilationTimer.getStringRepresentation());
}
sb.append("Total execution time:\t\t" + String.format("%.3f",
getRunTime()*1e-9) + " sec.\n"); // nanoSec --> sec
if( OptimizerUtils.isSparkExecutionMode() ) {