/******************************************************************************* | |
* Copyright (c) 2019 Dortmund University of Applied Sciences and Arts. | |
* | |
* This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License 2.0 | |
* which accompanies this distribution, and is available at | |
* https://www.eclipse.org/legal/epl-2.0/ | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: Junhyung Ki - initial API and implementation | |
* | |
*******************************************************************************/ | |
package org.eclipse.app4mc.gsoc_rta.ui; | |
import java.awt.Color; | |
import java.awt.EventQueue; | |
import java.awt.Font; | |
import java.awt.List; | |
import java.awt.TextArea; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.math.BigInteger; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import javax.swing.ButtonGroup; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JOptionPane; | |
import javax.swing.JRadioButton; | |
import javax.swing.JTextField; | |
import org.eclipse.app4mc.amalthea.model.ProcessingUnit; | |
import org.eclipse.app4mc.amalthea.model.PuType; | |
import org.eclipse.app4mc.amalthea.model.Task; | |
import org.eclipse.app4mc.amalthea.model.Time; | |
import org.eclipse.app4mc.amalthea.model.TimeUnit; | |
import org.eclipse.app4mc.amalthea.model.io.AmaltheaLoader; | |
import org.eclipse.app4mc.amalthea.model.util.FactoryUtil; | |
import org.eclipse.app4mc.amalthea.model.util.RuntimeUtil.TimeType; | |
import org.eclipse.app4mc.gsoc_rta.*; | |
/** | |
* Date: Jun 20-2019 | |
* @author Junhyung Ki | |
* @version 1.0 | |
* The purpose of this class is to provide users a better visual and increase usability of Response Time Analysis. | |
*/ | |
@SuppressWarnings("serial") | |
public class RTApp_WATERS19 extends JFrame { | |
private HashMap<Integer, java.util.List<Task>> puTaskListHM; | |
private JFrame frame; | |
private boolean iaEntered = false; | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
org.apache.log4j.BasicConfigurator.configure(); | |
final RTApp_WATERS19 window = new RTApp_WATERS19(); | |
window.frame.setVisible(true); | |
window.frame.setTitle("APP4RTA"); | |
} | |
}); | |
} | |
/** | |
* Create the frame. | |
*/ | |
public RTApp_WATERS19() { | |
initialize(); | |
} | |
private void initialize() { | |
final CpuRTA cpurta = new CpuRTA(); | |
final ArrayList<JTextField> jTextFieldList = new ArrayList<JTextField>(); | |
final ArrayList<List> tListList = new ArrayList<List>(); | |
final ArrayList<List> rtListList = new ArrayList<List>(); | |
frame = new JFrame(); | |
frame.setBounds(100, 100, 864, 690); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.getContentPane().setLayout(null); | |
JLabel lblEnterIa = new JLabel("Enter IA"); | |
lblEnterIa.setBounds(32, 13, 56, 16); | |
frame.getContentPane().add(lblEnterIa); | |
JButton btnDefualtIa = new JButton("Defualt IA"); | |
btnDefualtIa.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent arg0) { | |
cpurta.setModel(AmaltheaLoader.loadFromFile(cpurta.inputFile)); | |
cpurta.setTRT(cpurta.getDefaultTRT(cpurta.getModel())); | |
cpurta.setIA(cpurta.getDefaultIAMapping()); | |
cpurta.setPUl(CommonUtils.getPUs(cpurta.getModel())); | |
final int[] defaultIA = cpurta.getIA(); | |
for (int i = 0; i < defaultIA.length; i++) { | |
jTextFieldList.get(i).setText(""+defaultIA[i]); | |
} | |
} | |
}); | |
btnDefualtIa.setBounds(12, 28, 97, 25); | |
frame.getContentPane().add(btnDefualtIa); | |
JRadioButton rdbtnSynchronous = new JRadioButton("Synchronous"); | |
rdbtnSynchronous.setBounds(157, 58, 107, 25); | |
frame.getContentPane().add(rdbtnSynchronous); | |
JRadioButton rdbtnAsynchronous = new JRadioButton("Asynchronous"); | |
rdbtnAsynchronous.setBounds(157, 79, 107, 25); | |
frame.getContentPane().add(rdbtnAsynchronous); | |
ButtonGroup group_0 = new ButtonGroup(); | |
group_0.add(rdbtnSynchronous); | |
group_0.add(rdbtnAsynchronous); | |
JRadioButton rdbtnWorstCase = new JRadioButton("Worst Case"); | |
rdbtnWorstCase.setBounds(268, 58, 107, 25); | |
frame.getContentPane().add(rdbtnWorstCase); | |
JRadioButton rdbtnAverageCase = new JRadioButton("Average Case"); | |
rdbtnAverageCase.setBounds(268, 79, 107, 25); | |
frame.getContentPane().add(rdbtnAverageCase); | |
JRadioButton rdbtnBestCase = new JRadioButton("Best Case"); | |
rdbtnBestCase.setBounds(268, 100, 107, 25); | |
frame.getContentPane().add(rdbtnBestCase); | |
ButtonGroup group_1 = new ButtonGroup(); | |
group_1.add(rdbtnWorstCase); | |
group_1.add(rdbtnAverageCase); | |
group_1.add(rdbtnBestCase); | |
JButton btnEnterIA = new JButton("Enter IA"); | |
btnEnterIA.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
cpurta.setModel(AmaltheaLoader.loadFromFile(cpurta.inputFile)); | |
cpurta.setTRT(cpurta.getDefaultTRT(cpurta.getModel())); | |
int[] tpumap = new int[cpurta.getModel().getSwModel().getTasks().size()]; | |
for (int i = 0; i < jTextFieldList.size(); i++) { | |
if ((jTextFieldList.get(i)).getText().length() == 0) { | |
JOptionPane.showMessageDialog(frame, "ERROR: Fill the rest of the array!"); | |
return ; | |
} | |
else if ((jTextFieldList.get(i)).getText().charAt(0) < 48 || (jTextFieldList.get(i)).getText().charAt(0) > 54) { | |
JOptionPane.showMessageDialog(frame, "ERROR: Wrong array value!"); | |
return ; | |
} | |
// TODO: should be more generic | |
else if (i >= 0 && i <= 9 && Integer.parseInt(((jTextFieldList.get(i)).getText())) == 6) { | |
JOptionPane.showMessageDialog(frame, "ERROR: CPU Tasks should not be mapped to GPU!"); | |
return ; | |
} | |
// TODO: should be more generic | |
else if (i == jTextFieldList.size()-1 && Integer.parseInt(((jTextFieldList.get(i)).getText())) != 6) { | |
JOptionPane.showMessageDialog(frame, "ERROR: 'Detection' task can not be mapped to CPU!"); | |
return ; | |
} | |
tpumap[i] = Integer.parseInt(((jTextFieldList.get(i)).getText())); | |
} | |
cpurta.setIA(tpumap); | |
cpurta.setPUl(CommonUtils.getPUs(cpurta.getModel())); | |
puTaskListHM = cpurta.be_getPUTaskListHashMap(cpurta.getModel()); | |
for (int i = 0; i < puTaskListHM.size(); i++) { | |
if (tListList.get(i).getItemCount() == 0) { | |
for (int j = 0; j < puTaskListHM.get(i).size(); j++) { | |
tListList.get(i).add((puTaskListHM.get(i).get(j)).getName()); | |
} | |
} | |
} | |
iaEntered = true; | |
} | |
}); | |
btnEnterIA.setBounds(616, 28, 97, 25); | |
frame.getContentPane().add(btnEnterIA); | |
JLabel lblResponseTimeSum = new JLabel("Response Time Sum"); | |
lblResponseTimeSum.setBounds(616, 359, 145, 16); | |
frame.getContentPane().add(lblResponseTimeSum); | |
TextArea rtSum = new TextArea(); | |
rtSum.setBounds(616, 381, 218, 50); | |
frame.getContentPane().add(rtSum); | |
JButton btnCalculate = new JButton("Calculate"); | |
btnCalculate.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent arg0) { | |
for (int i = 0; i < jTextFieldList.size(); i++) { | |
if ((jTextFieldList.get(i)).getText().length() == 0) { | |
JOptionPane.showMessageDialog(frame, "ERROR: Fill the array first!"); | |
return ; | |
} | |
} | |
if (rdbtnSynchronous.isSelected()) { | |
SharedConsts.synchronousOffloading = true; | |
} | |
else if (rdbtnAsynchronous.isSelected()) { | |
SharedConsts.synchronousOffloading = false; | |
} | |
else { | |
JOptionPane.showMessageDialog(frame, "ERROR: You should choose an offloading mode! (Sync / Async)"); | |
return ; | |
} | |
if (rdbtnWorstCase.isSelected()) { | |
SharedConsts.timeType = TimeType.WCET; | |
} | |
else if (rdbtnAverageCase.isSelected()) { | |
SharedConsts.timeType = TimeType.ACET; | |
} | |
else if (rdbtnBestCase.isSelected()) { | |
SharedConsts.timeType = TimeType.BCET; | |
} | |
else { | |
JOptionPane.showMessageDialog(frame, "ERROR: You should choose an execution case! (Worst Case / Average Case / Best Case)"); | |
return ; | |
} | |
if (iaEntered == false) { | |
JOptionPane.showMessageDialog(frame, "ERROR: Click the 'Enter IA' button!"); | |
return ; | |
} | |
boolean flag = false; | |
Time pRtSum = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS); | |
for (int i = 0; i < puTaskListHM.size(); i++) { | |
final ProcessingUnit pu = cpurta.getPUl().get(i); | |
final java.util.List<Task> thisPUTaskList = puTaskListHM.get(i); | |
Time thisRT = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS); | |
if (rtListList.get(i).getItemCount() == 0) { | |
if (pu.getDefinition().getPuType().equals(PuType.CPU)) { | |
for (Task t : thisPUTaskList) { | |
thisRT = cpurta.preciseTestCPURT(t, thisPUTaskList, SharedConsts.timeType, pu); | |
if (thisRT.getValue().equals(BigInteger.valueOf(Long.MAX_VALUE))) { | |
rtListList.get(i).add("Non Scheduleable! => MAX Value"); | |
flag = true; | |
} | |
else { | |
rtListList.get(i).add(thisRT.toString()); | |
} | |
pRtSum = pRtSum.add(thisRT); | |
} | |
} | |
else { | |
// TODO: TRT 0s! | |
for (Task t : thisPUTaskList) { | |
thisRT = cpurta.getTRT().get(t); | |
rtListList.get(i).add(thisRT.toString()); | |
pRtSum = pRtSum.add(thisRT); | |
} | |
} | |
} | |
} | |
if (flag) { | |
rtSum.setText("Non Scheduleable!: " + pRtSum.toString()); | |
} | |
else { | |
rtSum.setText(pRtSum.toString()); | |
} | |
} | |
}); | |
btnCalculate.setBounds(616, 58, 97, 25); | |
frame.getContentPane().add(btnCalculate); | |
JButton btnReset = new JButton("Reset"); | |
btnReset.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
cpurta.setModel(null); | |
cpurta.setTRT(null); | |
cpurta.setIA(null); | |
cpurta.setPUl(null); | |
puTaskListHM = null; | |
for (int i = 0; i < jTextFieldList.size(); i++) { | |
jTextFieldList.get(i).setText(""); | |
} | |
for (List tList : tListList) { | |
tList.removeAll(); | |
} | |
for (List rtList : rtListList) { | |
rtList.removeAll(); | |
} | |
rtSum.setText(null); | |
iaEntered = false; | |
} | |
}); | |
btnReset.setBounds(616, 86, 97, 25); | |
frame.getContentPane().add(btnReset); | |
JLabel lblT0 = new JLabel("T0"); | |
lblT0.setBounds(124, 13, 15, 16); | |
frame.getContentPane().add(lblT0); | |
JTextField txtInput0 = new JTextField(); | |
txtInput0.setBounds(124, 29, 23, 22); | |
txtInput0.setColumns(10); | |
frame.getContentPane().add(txtInput0); | |
jTextFieldList.add(txtInput0); | |
JLabel lblT1 = new JLabel("T1"); | |
lblT1.setBounds(159, 13, 15, 16); | |
frame.getContentPane().add(lblT1); | |
JTextField txtInput1 = new JTextField(); | |
txtInput1.setColumns(10); | |
txtInput1.setBounds(159, 29, 23, 22); | |
frame.getContentPane().add(txtInput1); | |
jTextFieldList.add(txtInput1); | |
JLabel lblT2 = new JLabel("T2"); | |
lblT2.setBounds(194, 13, 15, 16); | |
frame.getContentPane().add(lblT2); | |
JTextField txtInput2 = new JTextField(); | |
txtInput2.setColumns(10); | |
txtInput2.setBounds(194, 29, 23, 22); | |
frame.getContentPane().add(txtInput2); | |
jTextFieldList.add(txtInput2); | |
JLabel lblT3 = new JLabel("T3"); | |
lblT3.setBounds(229, 13, 15, 16); | |
frame.getContentPane().add(lblT3); | |
JTextField txtInput3 = new JTextField(); | |
txtInput3.setColumns(10); | |
txtInput3.setBounds(229, 29, 23, 22); | |
frame.getContentPane().add(txtInput3); | |
jTextFieldList.add(txtInput3); | |
JLabel lblT4 = new JLabel("T4"); | |
lblT4.setBounds(264, 13, 15, 16); | |
frame.getContentPane().add(lblT4); | |
JTextField txtInput4 = new JTextField(); | |
txtInput4.setColumns(10); | |
txtInput4.setBounds(264, 29, 23, 22); | |
frame.getContentPane().add(txtInput4); | |
jTextFieldList.add(txtInput4); | |
JLabel lblT5 = new JLabel("T5"); | |
lblT5.setBounds(299, 13, 15, 16); | |
frame.getContentPane().add(lblT5); | |
JTextField txtInput5 = new JTextField(); | |
txtInput5.setColumns(10); | |
txtInput5.setBounds(299, 29, 23, 22); | |
frame.getContentPane().add(txtInput5); | |
jTextFieldList.add(txtInput5); | |
JLabel lblT6 = new JLabel("T6"); | |
lblT6.setBounds(334, 13, 15, 16); | |
frame.getContentPane().add(lblT6); | |
JTextField txtInput6 = new JTextField(); | |
txtInput6.setColumns(10); | |
txtInput6.setBounds(334, 29, 23, 22); | |
frame.getContentPane().add(txtInput6); | |
jTextFieldList.add(txtInput6); | |
JLabel lblT7 = new JLabel("T7"); | |
lblT7.setBounds(369, 13, 15, 16); | |
frame.getContentPane().add(lblT7); | |
JTextField txtInput7 = new JTextField(); | |
txtInput7.setColumns(10); | |
txtInput7.setBounds(369, 29, 23, 22); | |
frame.getContentPane().add(txtInput7); | |
jTextFieldList.add(txtInput7); | |
JLabel lblT8 = new JLabel("T8"); | |
lblT8.setBounds(404, 13, 15, 16); | |
frame.getContentPane().add(lblT8); | |
JTextField txtInput8 = new JTextField(); | |
txtInput8.setColumns(10); | |
txtInput8.setBounds(404, 29, 23, 22); | |
frame.getContentPane().add(txtInput8); | |
jTextFieldList.add(txtInput8); | |
JLabel lblT9 = new JLabel("T9"); | |
lblT9.setBounds(439, 13, 15, 16); | |
frame.getContentPane().add(lblT9); | |
JTextField txtInput9 = new JTextField(); | |
txtInput9.setColumns(10); | |
txtInput9.setBounds(439, 29, 23, 22); | |
frame.getContentPane().add(txtInput9); | |
jTextFieldList.add(txtInput9); | |
JLabel lblT10 = new JLabel("T10"); | |
lblT10.setBounds(474, 13, 23, 16); | |
frame.getContentPane().add(lblT10); | |
JTextField txtInput10 = new JTextField(); | |
txtInput10.setColumns(10); | |
txtInput10.setBounds(474, 29, 23, 22); | |
frame.getContentPane().add(txtInput10); | |
jTextFieldList.add(txtInput10); | |
JLabel lblT11 = new JLabel("T11"); | |
lblT11.setBounds(509, 13, 23, 16); | |
frame.getContentPane().add(lblT11); | |
JTextField txtInput11 = new JTextField(); | |
txtInput11.setColumns(10); | |
txtInput11.setBounds(509, 29, 23, 22); | |
frame.getContentPane().add(txtInput11); | |
jTextFieldList.add(txtInput11); | |
JLabel lblT12 = new JLabel("T12"); | |
lblT12.setBounds(544, 13, 23, 16); | |
frame.getContentPane().add(lblT12); | |
JTextField txtInput12 = new JTextField(); | |
txtInput12.setColumns(10); | |
txtInput12.setBounds(544, 29, 23, 22); | |
frame.getContentPane().add(txtInput12); | |
jTextFieldList.add(txtInput12); | |
JLabel lblT13 = new JLabel("T13"); | |
lblT13.setBounds(579, 13, 23, 16); | |
frame.getContentPane().add(lblT13); | |
JTextField txtInput13 = new JTextField(); | |
txtInput13.setColumns(10); | |
txtInput13.setBounds(579, 29, 23, 22); | |
frame.getContentPane().add(txtInput13); | |
jTextFieldList.add(txtInput13); | |
JLabel txtArm_0 = new JLabel("ARM0"); | |
txtArm_0.setBounds(86, 154, 42, 22); | |
frame.getContentPane().add(txtArm_0); | |
List arm0_list = new List(); | |
arm0_list.setBounds(10, 180, 87, 145); | |
frame.getContentPane().add(arm0_list); | |
tListList.add(arm0_list); | |
List arm0_rtList = new List(); | |
arm0_rtList.setBounds(108, 180, 87, 145); | |
frame.getContentPane().add(arm0_rtList); | |
rtListList.add(arm0_rtList); | |
JLabel txtArm_1 = new JLabel("ARM1"); | |
txtArm_1.setBounds(288, 154, 42, 22); | |
frame.getContentPane().add(txtArm_1); | |
List arm1_list = new List(); | |
arm1_list.setBounds(212, 180, 87, 145); | |
frame.getContentPane().add(arm1_list); | |
tListList.add(arm1_list); | |
List arm1_rtList = new List(); | |
arm1_rtList.setBounds(309, 180, 87, 145); | |
frame.getContentPane().add(arm1_rtList); | |
rtListList.add(arm1_rtList); | |
JLabel txtArm_2 = new JLabel("ARM2"); | |
txtArm_2.setBounds(489, 154, 42, 22); | |
frame.getContentPane().add(txtArm_2); | |
List arm2_list = new List(); | |
arm2_list.setBounds(414, 180, 87, 145); | |
frame.getContentPane().add(arm2_list); | |
tListList.add(arm2_list); | |
List arm2_rtList = new List(); | |
arm2_rtList.setBounds(510, 180, 87, 145); | |
frame.getContentPane().add(arm2_rtList); | |
rtListList.add(arm2_rtList); | |
JLabel txtArm_3 = new JLabel("ARM3"); | |
txtArm_3.setBounds(691, 154, 42, 22); | |
frame.getContentPane().add(txtArm_3); | |
List arm3_list = new List(); | |
arm3_list.setBounds(616, 180, 87, 145); | |
frame.getContentPane().add(arm3_list); | |
tListList.add(arm3_list); | |
List arm3_rtList = new List(); | |
arm3_rtList.setBounds(711, 180, 87, 145); | |
frame.getContentPane().add(arm3_rtList); | |
rtListList.add(arm3_rtList); | |
JLabel txtDenver_0 = new JLabel("Denver0"); | |
txtDenver_0.setBounds(82, 335, 56, 22); | |
frame.getContentPane().add(txtDenver_0); | |
List denver0_list = new List(); | |
denver0_list.setBounds(10, 359, 87, 145); | |
frame.getContentPane().add(denver0_list); | |
tListList.add(denver0_list); | |
List denver0_rtList = new List(); | |
denver0_rtList.setBounds(108, 359, 87, 145); | |
frame.getContentPane().add(denver0_rtList); | |
rtListList.add(denver0_rtList); | |
JLabel txtDenver_1 = new JLabel("Denver1"); | |
txtDenver_1.setBounds(284, 335, 56, 22); | |
frame.getContentPane().add(txtDenver_1); | |
List denver1_list = new List(); | |
denver1_list.setBounds(212, 359, 87, 145); | |
frame.getContentPane().add(denver1_list); | |
tListList.add(denver1_list); | |
List denver1_rtList = new List(); | |
denver1_rtList.setBounds(309, 359, 87, 145); | |
frame.getContentPane().add(denver1_rtList); | |
rtListList.add(denver1_rtList); | |
JLabel txtGpu = new JLabel("GPU"); | |
txtGpu.setBounds(489, 335, 42, 22); | |
frame.getContentPane().add(txtGpu); | |
List gpu_list = new List(); | |
gpu_list.setBounds(414, 359, 87, 145); | |
frame.getContentPane().add(gpu_list); | |
tListList.add(gpu_list); | |
List gpu_rtList = new List(); | |
gpu_rtList.setBounds(510, 359, 87, 145); | |
frame.getContentPane().add(gpu_rtList); | |
rtListList.add(gpu_rtList); | |
JLabel lblArm = new JLabel("0: ARM0"); | |
lblArm.setBounds(12, 62, 56, 16); | |
frame.getContentPane().add(lblArm); | |
JLabel lblArm_1 = new JLabel("1: ARM1"); | |
lblArm_1.setBounds(12, 79, 56, 16); | |
frame.getContentPane().add(lblArm_1); | |
JLabel lblArm_2 = new JLabel("2: ARM2"); | |
lblArm_2.setBounds(12, 98, 56, 16); | |
frame.getContentPane().add(lblArm_2); | |
JLabel lblArm_3 = new JLabel("3: ARM3"); | |
lblArm_3.setBounds(12, 117, 56, 16); | |
frame.getContentPane().add(lblArm_3); | |
JLabel lblDenver = new JLabel("4: Denver0"); | |
lblDenver.setBounds(77, 62, 72, 16); | |
frame.getContentPane().add(lblDenver); | |
JLabel lblDenver_1 = new JLabel("5: Denver1"); | |
lblDenver_1.setBounds(77, 79, 72, 16); | |
frame.getContentPane().add(lblDenver_1); | |
JLabel lblGpu = new JLabel("6: GPU"); | |
lblGpu.setBounds(77, 96, 56, 16); | |
frame.getContentPane().add(lblGpu); | |
JLabel lblApprta = new JLabel("APP4RTA"); | |
lblApprta.setForeground(Color.BLUE); | |
lblApprta.setFont(new Font("Tahoma", Font.ITALIC, 20)); | |
lblApprta.setBounds(747, 1, 87, 34); | |
frame.getContentPane().add(lblApprta); | |
} | |
} |