package test.appProfConverter.dcworms; public class AppProfileConverter { public static SoftwareProfile convert(SoftwareProfile refSWProf, HardwareProfile targetHWProf) { SoftwareProfile newProf = new SoftwareProfile(); newProf.taskId = refSWProf.taskId; newProf.phases = new SoftwarePhase[refSWProf.phases.length]; for (int i = 0; i < newProf.phases.length; i++) { newProf.phases[i] = convertPhase(refSWProf.phases[i], targetHWProf); } return newProf; } private static SoftwarePhase convertPhase(SoftwarePhase refPhase, HardwareProfile targetHW) { SoftwarePhase newPhase; double refCpuWork; // workload is constant in a phase double loadCpu; double t_cpu, t_nic, t_best; newPhase = new SoftwarePhase(refPhase); newPhase.RefNode = targetHW.componentId; newPhase.RefFreq = targetHW.proc.maxClockSpeed; newPhase.RefCores = targetHW.proc.cores; newPhase.RefDownload = (double) targetHW.net.maxBandwidth; newPhase.RefUpload = (double) targetHW.net.maxBandwidth; refCpuWork = refPhase.RefFreq * refPhase.PM_CPU_Usage * refPhase.Duration * refPhase.RefCores; // Best CPU load and time duration loadCpu = Math.min(1.0, refPhase.PM_CPU_Usage) * Math.min(1.0, ((double) newPhase.PM_Threads / newPhase.RefCores)); System.out.println(loadCpu + ";" + refPhase.RefCores + ";" + refPhase.PM_CPU_Usage + ";" + newPhase.PM_Threads + ";" +newPhase.RefCores); t_cpu = refCpuWork / (newPhase.RefCores * newPhase.RefFreq * loadCpu); // Best network time duration t_nic = Math.max((double) newPhase.PM_Upload / newPhase.RefUpload, (double) newPhase.PM_Download / newPhase.RefDownload); t_best = Math.max(t_cpu, t_nic); // The duration in seconds will impact the load depending on the // approximation error newPhase.Duration = (int) Math.ceil(t_best); // use t_best to debug // newPhase.PM_CPU_Usage = refCpuWork // / (newPhase.RefCores * newPhase.RefFreq * t_best); newPhase.PM_CPU_Usage = refCpuWork / (newPhase.RefCores * newPhase.RefFreq * newPhase.Duration); System.out .printf("l0:%.2f\tl1:%.2f\td0:%d\td1:%d\tc0:%d\tc1:%d\tf0:%.2f\tf1:%.2f\tt0:%d\tt1:%d\n", refPhase.PM_CPU_Usage, newPhase.PM_CPU_Usage, refPhase.Duration, newPhase.Duration, refPhase.RefCores, newPhase.RefCores, refPhase.RefFreq, newPhase.RefFreq, refPhase.PM_Threads, newPhase.PM_Threads); // double newCpuWork = newPhase.RefFreq * newPhase.PM_CPU_Usage // * newPhase.Duration * newPhase.RefCores; // if (newCpuWork != refCpuWork) { // System.out.printf("w0:%.2f\tw0:%.2f\n", refCpuWork, newCpuWork); // } newPhase.PM_Power = AppPowerEstimator.PhasePower(newPhase, targetHW); return newPhase; } }