import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace;
import org.eclipse.tracecompass.analysis.os.linux.core.trace.KernelEventLayoutRequirement;
import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog;
import org.eclipse.tracecompass.internal.analysis.os.linux.core.Activator;
import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
LAYOUT_REQUIREMENT = new KernelEventLayoutRequirement(ImmutableSet.of((l) -> l.eventSchedSwitch()), PriorityLevel.MANDATORY);
}
+ private static final Logger LOGGER = TraceCompassLog.getLogger(KernelCpuUsageAnalysis.class);
+
private static IKernelAnalysisEventLayout getLayout(@Nullable ITmfTrace trace) {
IKernelAnalysisEventLayout layout;
return map;
}
- try {
+ try (ScopeLog scopeLog = new ScopeLog(LOGGER, Level.FINE, "KernelCpuUsageAnalysis#getCpuUsageInRange")) { //$NON-NLS-1$
/* Get the list of quarks for each CPU and CPU's TIDs */
int cpusNode = cpuSs.getQuarkAbsolute(Attributes.CPUS);
Map<Integer, List<Integer>> tidsPerCpu = new HashMap<>();
* those times
*/
if (tid == startThread || startThread == -1) {
- long runningTime = kernelStartState.get(currentThreadQuark).getEndTime() - kernelStartState.get(currentThreadQuark).getStartTime();
- long runningEnd = kernelStartState.get(currentThreadQuark).getEndTime();
+ ITmfStateInterval threadState = kernelStartState.get(currentThreadQuark);
+ long runningTime = threadState.getEndTime() - threadState.getStartTime();
+ long runningEnd = threadState.getEndTime();
countAtStart = interpolateCount(countAtStart, startTime, runningEnd, runningTime);
}
long currentCount = countAtEnd - countAtStart;
if (currentCount < 0) {
- Activator.getDefault().logWarning(String.format("Negative count: start %d, end %d", countAtStart, countAtEnd)); //$NON-NLS-1$
+ TraceCompassLogUtils.traceInstant(LOGGER, Level.FINE, "Negative count", //$NON-NLS-1$
+ "CPU", curCpuName, //$NON-NLS-1$
+ "tid", curTidName, //$NON-NLS-1$
+ "startTime", startTime, //$NON-NLS-1$
+ "endTime", endTime, //$NON-NLS-1$
+ "countAtStart", countAtStart, //$NON-NLS-1$
+ "countAtEnd", countAtEnd); //$NON-NLS-1$
currentCount = 0;
} else if (currentCount > endTime - startTime) {
- Activator.getDefault().logWarning(String.format("CPU Usage: Spent more time on CPU than allowed: %s spent %d when max should be %d", curTidName, currentCount, endTime - startTime)); //$NON-NLS-1$
+ TraceCompassLogUtils.traceInstant(LOGGER, Level.FINE, "CPU usage over 100%", //$NON-NLS-1$
+ "CPU", curCpuName, //$NON-NLS-1$
+ "tid", curTidName, //$NON-NLS-1$
+ "startTime", startTime, //$NON-NLS-1$
+ "CPU time", currentCount, //$NON-NLS-1$
+ "elapsed time", endTime - startTime, //$NON-NLS-1$
+ "usage", currentCount * 100.0 / (endTime - startTime)); //$NON-NLS-1$
currentCount = 0;
}
cpuTotal += currentCount;
IKernelAnalysisEventLayout layout = getLayout(trace);
Set<TmfAbstractAnalysisRequirement> reqs = LAYOUT_REQ_MAP.get(layout);
if (reqs.isEmpty()) {
- reqs= ImmutableSet.of(LAYOUT_REQUIREMENT.instanciateRequirements(layout));
+ reqs = ImmutableSet.of(LAYOUT_REQUIREMENT.instanciateRequirements(layout));
LAYOUT_REQ_MAP.putAll(layout, reqs);
}
return reqs;