Skip to content

Commit d61285d

Browse files
committed
refactor from isInfoEnabled to the new logging util
1 parent 7ad7181 commit d61285d

File tree

6 files changed

+58
-83
lines changed

6 files changed

+58
-83
lines changed

src/main/java/org/apache/sysds/api/DMLScript.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
import org.apache.commons.cli.AlreadySelectedException;
4040
import org.apache.commons.cli.HelpFormatter;
4141
import org.apache.commons.lang3.StringUtils;
42-
import org.apache.commons.logging.Log;
43-
import org.apache.commons.logging.LogFactory;
42+
import org.apache.sysds.utils.ParameterizedLogger;
4443
import org.apache.hadoop.fs.FileSystem;
4544
import org.apache.hadoop.fs.Path;
4645
import org.apache.sysds.common.Types.ExecMode;
@@ -178,7 +177,7 @@ public class DMLScript
178177
public static boolean VALIDATOR_IGNORE_ISSUES = false;
179178

180179
public static String _uuid = IDHandler.createDistributedUniqueID();
181-
private static final Log LOG = LogFactory.getLog(DMLScript.class.getName());
180+
private static final ParameterizedLogger LOG = ParameterizedLogger.getLogger(DMLScript.class);
182181

183182
///////////////////////////////
184183
// public external interface
@@ -621,14 +620,9 @@ private static void printInvocationInfo(String fnameScript, String fnameOptConfi
621620
}
622621

623622
private static void printStartExecInfo(String dmlScriptString) {
624-
boolean info = LOG.isInfoEnabled();
625-
boolean debug = LOG.isDebugEnabled();
626-
if(info)
627-
LOG.info("BEGIN DML run " + getDateTime());
628-
if(debug)
629-
LOG.debug("DML script: \n" + dmlScriptString);
630-
if(info)
631-
LOG.info("Process id: " + IDHandler.getProcessID());
623+
LOG.info("BEGIN DML run {}", getDateTime());
624+
LOG.debug("DML script: \n{}", dmlScriptString);
625+
LOG.info("Process id: {}", IDHandler.getProcessID());
632626
}
633627

634628
private static void registerForMonitoring() {

src/main/java/org/apache/sysds/hops/codegen/SpoofCompiler.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,23 @@
1919

2020
package org.apache.sysds.hops.codegen;
2121

22+
import java.io.File;
23+
import java.io.IOException;
24+
import java.util.ArrayList;
25+
import java.util.Arrays;
26+
import java.util.Collections;
27+
import java.util.Enumeration;
28+
import java.util.HashMap;
29+
import java.util.HashSet;
30+
import java.util.Iterator;
31+
import java.util.LinkedHashMap;
32+
import java.util.Map.Entry;
33+
import java.util.jar.JarEntry;
34+
import java.util.jar.JarFile;
35+
2236
import org.apache.commons.io.FileUtils;
2337
import org.apache.commons.io.IOUtils;
2438
import org.apache.commons.lang3.SystemUtils;
25-
import org.apache.commons.logging.Log;
26-
import org.apache.commons.logging.LogFactory;
2739
import org.apache.sysds.api.DMLScript;
2840
import org.apache.sysds.common.Types.AggOp;
2941
import org.apache.sysds.common.Types.DataType;
@@ -97,24 +109,11 @@
97109
import org.apache.sysds.runtime.matrix.data.Pair;
98110
import org.apache.sysds.utils.Explain;
99111
import org.apache.sysds.utils.NativeHelper;
112+
import org.apache.sysds.utils.ParameterizedLogger;
100113
import org.apache.sysds.utils.stats.CodegenStatistics;
101114

102-
import java.io.File;
103-
import java.io.IOException;
104-
import java.util.ArrayList;
105-
import java.util.Arrays;
106-
import java.util.Collections;
107-
import java.util.Enumeration;
108-
import java.util.HashMap;
109-
import java.util.HashSet;
110-
import java.util.Iterator;
111-
import java.util.LinkedHashMap;
112-
import java.util.Map.Entry;
113-
import java.util.jar.JarEntry;
114-
import java.util.jar.JarFile;
115-
116115
public class SpoofCompiler {
117-
private static final Log LOG = LogFactory.getLog(SpoofCompiler.class.getName());
116+
private static final ParameterizedLogger LOG = ParameterizedLogger.getLogger(SpoofCompiler.class);
118117

119118
//internal configuration flags
120119
public static CompilerType JAVA_COMPILER = CompilerType.JANINO;
@@ -539,21 +538,20 @@ public static ArrayList<Hop> optimize(ArrayList<Hop> roots, boolean recompile)
539538
}
540539

541540
//explain debug output cplans or generated source code
542-
if( LOG.isInfoEnabled() || DMLScript.EXPLAIN.isHopsType(recompile) ) {
543-
LOG.info("Codegen EXPLAIN (generated cplan for HopID: " + cplan.getKey() +
544-
", line "+tmp.getValue().getBeginLine() + ", hash="+tmp.getValue().hashCode()+"):");
541+
if( DMLScript.EXPLAIN.isHopsType(recompile) ) {
542+
LOG.info("Codegen EXPLAIN (generated cplan for HopID: {}, line {}, hash={}):",
543+
cplan.getKey(), tmp.getValue().getBeginLine(), tmp.getValue().hashCode());
545544
LOG.info(tmp.getValue().getClassname()
546545
+ Explain.explainCPlan(cplan.getValue().getValue()));
547546
}
548-
if( LOG.isInfoEnabled() || DMLScript.EXPLAIN.isRuntimeType(recompile) ) {
549-
LOG.info("JAVA Codegen EXPLAIN (generated code for HopID: " + cplan.getKey() +
550-
", line "+tmp.getValue().getBeginLine() + ", hash="+tmp.getValue().hashCode()+"):");
547+
if( DMLScript.EXPLAIN.isRuntimeType(recompile) ) {
548+
LOG.info("JAVA Codegen EXPLAIN (generated code for HopID: {}, line {}, hash={}):",
549+
cplan.getKey(), tmp.getValue().getBeginLine(), tmp.getValue().hashCode());
551550
LOG.info(CodegenUtils.printWithLineNumber(src));
552-
553-
if(API == GeneratorAPI.CUDA) {
554-
LOG.info("CUDA Codegen EXPLAIN (generated code for HopID: " + cplan.getKey() +
555-
", line " + tmp.getValue().getBeginLine() + ", hash=" + tmp.getValue().hashCode() + "):");
556551

552+
if(API == GeneratorAPI.CUDA) {
553+
LOG.info("CUDA Codegen EXPLAIN (generated code for HopID: {}, line {}, hash={}):",
554+
cplan.getKey(), tmp.getValue().getBeginLine(), tmp.getValue().hashCode());
557555
LOG.info(CodegenUtils.printWithLineNumber(src_cuda));
558556
}
559557
}

src/main/java/org/apache/sysds/runtime/controlprogram/paramserv/FederatedPSControlThread.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535
import org.apache.commons.lang3.NotImplementedException;
3636
import org.apache.commons.lang3.tuple.Pair;
37-
import org.apache.commons.logging.Log;
38-
import org.apache.commons.logging.LogFactory;
37+
import org.apache.sysds.utils.ParameterizedLogger;
3938
import org.apache.sysds.api.DMLScript;
4039
import org.apache.sysds.parser.DataIdentifier;
4140
import org.apache.sysds.parser.Statement;
@@ -77,7 +76,7 @@
7776

7877
public class FederatedPSControlThread extends PSWorker implements Callable<Void> {
7978
private static final long serialVersionUID = 6846648059569648791L;
80-
protected static final Log LOG = LogFactory.getLog(ParamServer.class.getName());
79+
protected static final ParameterizedLogger LOG = ParameterizedLogger.getLogger(ParamServer.class);
8180

8281
private FederatedData _featuresData;
8382
private FederatedData _labelsData;
@@ -147,11 +146,9 @@ public void setup(double weightingFactor) {
147146
if(_runtimeBalancing == PSRuntimeBalancing.BASELINE)
148147
_cycleStartAt0 = true;
149148

150-
if( LOG.isInfoEnabled() ) {
151-
LOG.info("Setup config for worker " + this.getWorkerName());
152-
LOG.info("Batch size: " + _batchSize + " possible batches: " + _possibleBatchesPerLocalEpoch
153-
+ " batches to run: " + _numBatchesPerEpoch + " weighting factor: " + _weightingFactor);
154-
}
149+
LOG.info("Setup config for worker {}", this.getWorkerName());
150+
LOG.info("Batch size: {} possible batches: {} batches to run: {} weighting factor: {}",
151+
_batchSize, _possibleBatchesPerLocalEpoch, _numBatchesPerEpoch, _weightingFactor);
155152

156153
// serialize program
157154
// create program blocks for the instruction filtering

src/main/java/org/apache/sysds/runtime/controlprogram/paramserv/ParamServer.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ protected synchronized void updateGlobalGradients(int workerID, ListObject gradi
227227
((_freq == Statement.PSFrequency.EPOCH && ((float) ++_syncCounter % _numWorkers) == 0) ||
228228
(_freq == Statement.PSFrequency.BATCH && ((float) ++_syncCounter / _numWorkers) % _numBatchesPerEpoch == 0)) ||
229229
(_freq == Statement.PSFrequency.NBATCHES)) {
230-
if(LOG.isInfoEnabled())
231-
LOG.info("[+] PARAMSERV: completed PSEUDO EPOCH (ASP) " + _epochCounter);
230+
LOG.info("[+] PARAMSERV: completed PSEUDO EPOCH (ASP) {}", _epochCounter);
232231

233232
time_epoch();
234233

@@ -280,8 +279,7 @@ private void performGlobalGradientUpdate() {
280279
}
281280

282281
if(finishedEpoch()) {
283-
if(LOG.isInfoEnabled())
284-
LOG.info("[+] PARAMSERV: completed EPOCH " + _epochCounter);
282+
LOG.info("[+] PARAMSERV: completed EPOCH {}", _epochCounter);
285283

286284
time_epoch();
287285

@@ -423,8 +421,7 @@ protected void updateAndBroadcastModel(ListObject new_model, Timing tAgg, boolea
423421
if(_numBatchesPerEpoch != -1 && (_freq == Statement.PSFrequency.EPOCH ||
424422
(_freq == Statement.PSFrequency.BATCH && ++_syncCounter % _numBatchesPerEpoch == 0))) {
425423

426-
if(LOG.isInfoEnabled())
427-
LOG.info("[+] PARAMSERV: completed EPOCH " + _epochCounter);
424+
LOG.info("[+] PARAMSERV: completed EPOCH {}", _epochCounter);
428425
time_epoch();
429426
if(_validationPossible) {
430427
validate();
@@ -543,11 +540,10 @@ private void time_epoch() {
543540
double current_total_validation_time = ParamServStatistics.getValidationTime();
544541
double time_to_epoch = current_total_execution_time - current_total_validation_time;
545542

546-
if (LOG.isInfoEnabled())
547-
if(_validationPossible)
548-
LOG.info("[+] PARAMSERV: epoch timer (excl. validation): " + time_to_epoch / 1000 + " secs.");
549-
else
550-
LOG.info("[+] PARAMSERV: epoch timer: " + time_to_epoch / 1000 + " secs.");
543+
if(_validationPossible)
544+
LOG.info("[+] PARAMSERV: epoch timer (excl. validation): {} secs.", time_to_epoch / 1000);
545+
else
546+
LOG.info("[+] PARAMSERV: epoch timer: {} secs.", time_to_epoch / 1000);
551547
}
552548
}
553549

@@ -569,8 +565,7 @@ private void validate() {
569565
ParamservUtils.cleanupListObject(_ec, Statement.PS_MODEL);
570566

571567
// Log validation results
572-
if (LOG.isInfoEnabled())
573-
LOG.info("[+] PARAMSERV: validation-loss: " + loss + " validation-accuracy: " + accuracy);
568+
LOG.info("[+] PARAMSERV: validation-loss: {} validation-accuracy: {}", loss, accuracy);
574569

575570
if(tValidate != null)
576571
ParamServStatistics.accValidationTime((long) tValidate.stop());

src/main/java/org/apache/sysds/runtime/instructions/cp/CompressionCPInstruction.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
import java.util.List;
2424

2525
import org.apache.commons.lang3.tuple.Pair;
26-
import org.apache.commons.logging.Log;
27-
import org.apache.commons.logging.LogFactory;
26+
import org.apache.sysds.utils.ParameterizedLogger;
2827
import org.apache.sysds.hops.OptimizerUtils;
2928
import org.apache.sysds.runtime.compress.CompressedMatrixBlockFactory;
3029
import org.apache.sysds.runtime.compress.CompressionStatistics;
@@ -39,7 +38,7 @@
3938
import org.apache.sysds.runtime.matrix.operators.Operator;
4039

4140
public class CompressionCPInstruction extends ComputationCPInstruction {
42-
private static final Log LOG = LogFactory.getLog(CompressionCPInstruction.class.getName());
41+
private static final ParameterizedLogger LOG = ParameterizedLogger.getLogger(CompressionCPInstruction.class);
4342

4443
private final int _singletonLookupID;
4544
private final int _numThreads;
@@ -197,8 +196,7 @@ private void processMatrixBlockCompression(ExecutionContext ec, MatrixBlock in,
197196
if(LOG.isTraceEnabled())
198197
LOG.trace(compResult.getRight());
199198
MatrixBlock out = compResult.getLeft();
200-
if(LOG.isInfoEnabled())
201-
LOG.info("Compression output class: " + out.getClass().getSimpleName());
199+
LOG.info("Compression output class: {}", out.getClass().getSimpleName());
202200
// Set output and release input
203201
ec.releaseMatrixInput(input1.getName());
204202
ec.setMatrixOutput(output.getName(), out);
@@ -216,8 +214,7 @@ private void processMatrixBlockQuantizationFusedCompression(ExecutionContext ec,
216214
if(LOG.isTraceEnabled())
217215
LOG.trace(compResult.getRight());
218216
MatrixBlock out = compResult.getLeft();
219-
if(LOG.isInfoEnabled())
220-
LOG.info("Compression output class: " + out.getClass().getSimpleName());
217+
LOG.info("Compression output class: {}", out.getClass().getSimpleName());
221218
// Set output and release input
222219
ec.releaseMatrixInput(input1.getName());
223220
ec.releaseMatrixInput(input2.getName());
@@ -229,8 +226,7 @@ private void processMatrixBlockQuantizationFusedCompression(ExecutionContext ec,
229226
if(LOG.isTraceEnabled())
230227
LOG.trace(compResult.getRight());
231228
MatrixBlock out = compResult.getLeft();
232-
if(LOG.isInfoEnabled())
233-
LOG.info("Compression output class: " + out.getClass().getSimpleName());
229+
LOG.info("Compression output class: {}", out.getClass().getSimpleName());
234230
// Set output and release input
235231
ec.releaseMatrixInput(input1.getName());
236232
if (input2.isMatrix()) {

src/main/java/org/apache/sysds/runtime/instructions/cp/ParamservBuiltinCPInstruction.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
import java.util.stream.IntStream;
5757

5858
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
59-
import org.apache.commons.logging.Log;
60-
import org.apache.commons.logging.LogFactory;
6159
import org.apache.spark.network.server.TransportServer;
6260
import org.apache.spark.util.LongAccumulator;
6361
import org.apache.sysds.api.DMLScript;
@@ -92,12 +90,13 @@
9290
import org.apache.sysds.runtime.controlprogram.paramserv.rpc.PSRpcFactory;
9391
import org.apache.sysds.runtime.matrix.operators.Operator;
9492
import org.apache.sysds.runtime.util.ProgramConverter;
93+
import org.apache.sysds.utils.ParameterizedLogger;
9594
import org.apache.sysds.utils.stats.InfrastructureAnalyzer;
9695
import org.apache.sysds.utils.stats.ParamServStatistics;
9796
import org.apache.sysds.utils.stats.Timing;
9897

9998
public class ParamservBuiltinCPInstruction extends ParameterizedBuiltinCPInstruction {
100-
private static final Log LOG = LogFactory.getLog(ParamservBuiltinCPInstruction.class.getName());
99+
private static final ParameterizedLogger LOG = ParameterizedLogger.getLogger(ParamservBuiltinCPInstruction.class);
101100

102101
public static final int DEFAULT_BATCH_SIZE = 64;
103102
private static final PSFrequency DEFAULT_UPDATE_FREQUENCY = PSFrequency.EPOCH;
@@ -159,14 +158,12 @@ private void runFederated(ExecutionContext ec) {
159158
int nbatches = getNbatches();
160159
int numBackupWorkers = getNumBackupWorkers();
161160

162-
if( LOG.isInfoEnabled() ) {
163-
LOG.info("[+] Update Type: " + updateType);
164-
LOG.info("[+] Frequency: " + freq);
165-
LOG.info("[+] Data Partitioning: " + federatedPSScheme);
166-
LOG.info("[+] Runtime Balancing: " + runtimeBalancing);
167-
LOG.info("[+] Weighting: " + weighting);
168-
LOG.info("[+] Seed: " + seed);
169-
}
161+
LOG.info("[+] Update Type: {}", updateType);
162+
LOG.info("[+] Frequency: {}", freq);
163+
LOG.info("[+] Data Partitioning: {}", federatedPSScheme);
164+
LOG.info("[+] Runtime Balancing: {}", runtimeBalancing);
165+
LOG.info("[+] Weighting: {}", weighting);
166+
LOG.info("[+] Seed: {}", seed);
170167
if (tSetup != null)
171168
ParamServStatistics.accSetupTime((long) tSetup.stop());
172169

@@ -612,10 +609,8 @@ private void partitionLocally(PSScheme scheme, ExecutionContext ec, List<LocalPS
612609
List<MatrixObject> pfs = result.pFeatures;
613610
List<MatrixObject> pls = result.pLabels;
614611
if (pfs.size() < workers.size()) {
615-
if (LOG.isWarnEnabled()) {
616-
LOG.warn(String.format("There is only %d batches of data but has %d workers. "
617-
+ "Hence, reset the number of workers with %d.", pfs.size(), workers.size(), pfs.size()));
618-
}
612+
LOG.warn("There is only {} batches of data but has {} workers. "
613+
+ "Hence, reset the number of workers with {}.", pfs.size(), workers.size(), pfs.size());
619614
if (getUpdateType().isSBP() && pfs.size() <= getNumBackupWorkers()) {
620615
throw new DMLRuntimeException(
621616
"Effective number of workers is smaller or equal to the number of backup workers."

0 commit comments

Comments
 (0)