package test.appProfConverter; public class AppProfileConverter { 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 lambda; 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.nic.MaxBandwidth; newPhase.RefUpload = (double) targetHW.nic.MaxBandwidth; refCpuWork = refPhase.RefFreq * refPhase.PM_CPU_Usage * refPhase.Duration * refPhase.RefCores; // Best CPU load and time duration loadCpu = Math.min(1.0, refPhase.RefCores * refPhase.PM_CPU_Usage) * Math.min(1.0, ((double) 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; } }