Skip to content

Commit

Permalink
ProfilingModelInspector.java: Runtime(s)/PartRuntime cleanup
Browse files Browse the repository at this point in the history
Private nested Runtimes was renamed to Runtime.
Nested PartRuntime does not contain Runtime, but extends from it,
this saves space (+collocates the data) and is also easier to use.
  • Loading branch information
virgo47 committed Nov 11, 2020
1 parent a5c400f commit 65a1147
Showing 1 changed file with 32 additions and 33 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum and contributors
* Copyright (C) 2010-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -12,6 +12,8 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.ObjectUtils;

import com.evolveum.midpoint.model.api.context.Mapping;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.api.context.ModelProjectionContext;
Expand All @@ -27,16 +29,16 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import org.apache.commons.lang3.ObjectUtils;

public class ProfilingModelInspector implements DiagnosticContext, ClockworkInspector, RepositoryPerformanceMonitor, DebugDumpable {
public class ProfilingModelInspector
implements DiagnosticContext, ClockworkInspector, RepositoryPerformanceMonitor, DebugDumpable {

protected static final Trace LOGGER = TraceManager.getTrace(ProfilingModelInspector.class);

private final Runtimes totalOperationTimes = new Runtimes();
private Runtimes totalClockworkTimes = new Runtimes();
private Map<ModelState, Runtimes> clockworkStateTimes = new HashMap<>();
private Map<ModelState, Runtimes> projectorTimes = new HashMap<>();
private final Runtime totalOperationTimes = new Runtime();
private Runtime totalClockworkTimes = new Runtime();
private Map<ModelState, Runtime> clockworkStateTimes = new HashMap<>();
private Map<ModelState, Runtime> projectorTimes = new HashMap<>();
private Map<ModelState, List<PartRuntime>> projectorPartMap = new HashMap<>();
private long totalMappingTimeMillis = 0;
private long projectorMappingTotalMillis = 0;
Expand All @@ -45,27 +47,25 @@ public class ProfilingModelInspector implements DiagnosticContext, ClockworkInsp
private ModelState currentState = null;
private long totalRepoTime = 0;

private static class Runtimes {
private long startTime = 0;
private long finishTime = 0;
private static class Runtime {
protected long startTime = 0;
protected long finishTime = 0;

private long etime() {
protected long etime() {
return finishTime - startTime;
}

private String etimeStr() {
protected String etimeStr() {
return etime() + " ms";
}
}

private static class PartRuntime {

private static class PartRuntime extends Runtime {
private PartRuntime(String part) {
this.part = part;
}

private final String part;
private final Runtimes runtimes = new Runtimes();
}

public void recordStart() {
Expand All @@ -76,22 +76,23 @@ public void recordFinish() {
totalOperationTimes.finishTime = System.currentTimeMillis();
}

private void recordStateTime(Map<ModelState, Runtimes> map, ModelState state, Long start, Long finish) {
Runtimes runtimes = map.get(state);
if (runtimes == null) {
runtimes = new Runtimes();
map.put(state, runtimes);
private void recordStateTime(
Map<ModelState, Runtime> map, ModelState state, Long start, Long finish) {
Runtime runtime = map.get(state);
if (runtime == null) {
runtime = new Runtime();
map.put(state, runtime);
}
if (start != null) {
runtimes.startTime = start;
runtime.startTime = start;
}
if (finish != null) {
runtimes.finishTime = finish;
runtime.finishTime = finish;
}
}

public void reset() {
totalClockworkTimes = new Runtimes();
totalClockworkTimes = new Runtime();
clockworkStateTimes = new HashMap<>();
projectorTimes = new HashMap<>();
projectorPartMap = new HashMap<>();
Expand Down Expand Up @@ -143,7 +144,7 @@ public <F extends ObjectType> void projectorFinish(ModelContext<F> context) {
desc = focusObject.toString();
}
} else {
for (ModelProjectionContext projectionContext: context.getProjectionContexts()) {
for (ModelProjectionContext projectionContext : context.getProjectionContexts()) {
PrismObject<ShadowType> projObj = projectionContext.getObjectNew();
if (projObj == null) {
projObj = projectionContext.getObjectOld();
Expand Down Expand Up @@ -172,7 +173,7 @@ public ModelContext<?> getLastLensContext() {
}

@Override
public <F extends ObjectType> void afterMappingEvaluation(ModelContext<F> context, Mapping<?,?> evaluatedMapping) {
public <F extends ObjectType> void afterMappingEvaluation(ModelContext<F> context, Mapping<?, ?> evaluatedMapping) {
totalMappingTimeMillis += ObjectUtils.defaultIfNull(evaluatedMapping.getEtime(), 0L);
projectorMappingTotalMillis += ObjectUtils.defaultIfNull(evaluatedMapping.getEtime(), 0L);
projectorMappingTotalCount++;
Expand All @@ -186,10 +187,10 @@ private void recordProjectorPartTime(ModelState state, String componentName, Lon
partList.add(partRuntime);
}
if (start != null) {
partRuntime.runtimes.startTime = start;
partRuntime.startTime = start;
}
if (finish != null) {
partRuntime.runtimes.finishTime = finish;
partRuntime.finishTime = finish;
}
}

Expand Down Expand Up @@ -222,11 +223,10 @@ public void recordRepoOperation(long durationMillis) {
totalRepoTime = totalRepoTime + durationMillis;
}


@Override
public String debugDump(int indent) {
StringBuilder sb = DebugUtil.createTitleStringBuilderLn(ProfilingModelInspector.class, indent);
DebugUtil.debugDumpWithLabelLn(sb, "Clockwork", totalClockworkTimes==null?null:totalClockworkTimes.etimeStr(), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "Clockwork", totalClockworkTimes == null ? null : totalClockworkTimes.etimeStr(), indent + 1);
dumpState(sb, ModelState.INITIAL, indent);
dumpState(sb, ModelState.PRIMARY, indent);
dumpState(sb, ModelState.SECONDARY, indent);
Expand All @@ -240,21 +240,20 @@ public String debugDump(int indent) {
}

private void dumpState(StringBuilder sb, ModelState state, int indent) {
Runtimes runtimes = clockworkStateTimes.get(state);
Runtime runtimes = clockworkStateTimes.get(state);
if (runtimes == null) {
return;
}
DebugUtil.debugDumpWithLabelLn(sb, state.toString(), runtimes.etimeStr(), indent + 2);
Runtimes projectorRuntimes = projectorTimes.get(state);
Runtime projectorRuntimes = projectorTimes.get(state);
if (projectorRuntimes != null) {
DebugUtil.debugDumpWithLabelLn(sb, "projector", projectorRuntimes.etimeStr(), indent + 3);
List<PartRuntime> partList = projectorPartMap.get(state);
if (partList != null) {
for (PartRuntime partRuntime : partList) {
DebugUtil.debugDumpWithLabelLn(sb, partRuntime.part, partRuntime.runtimes.etimeStr(), indent + 4);
DebugUtil.debugDumpWithLabelLn(sb, partRuntime.part, partRuntime.etimeStr(), indent + 4);
}
}
}
}

}

0 comments on commit 65a1147

Please sign in to comment.