| /** |
| * Copyright (c) 2020-2021 Robert Bosch GmbH. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| */ |
| package org.eclipse.app4mc.slg.linux.generators; |
| |
| import java.util.Properties; |
| import java.util.Set; |
| |
| import org.eclipse.app4mc.amalthea.model.ActivityGraphItem; |
| import org.eclipse.app4mc.amalthea.model.LabelAccess; |
| import org.eclipse.app4mc.amalthea.model.LabelAccessEnum; |
| import org.eclipse.app4mc.amalthea.model.LabelAccessStatistic; |
| import org.eclipse.app4mc.amalthea.model.MinAvgMaxStatistic; |
| import org.eclipse.app4mc.amalthea.model.NumericStatistic; |
| import org.eclipse.app4mc.amalthea.model.ProcessingUnitDefinition; |
| import org.eclipse.app4mc.amalthea.model.Runnable; |
| import org.eclipse.app4mc.amalthea.model.SingleValueStatistic; |
| import org.eclipse.app4mc.amalthea.model.Ticks; |
| import org.eclipse.app4mc.slg.linux.generators.LinuxRunnableGenerator.Calculation; |
| import org.eclipse.app4mc.slg.linux.transformers.sw.LinuxActivityGraphItemTransformer; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| |
| public class LinuxRunnableTranslationUnit extends LinuxSyntheticTranslationUnit { |
| public static String getModulePathStatic() { |
| return getBasePathStatic() + "/" + getModuleNameStatic(); |
| } |
| |
| public static String getMakeFilePathStatic() { |
| return getModulePathStatic() + "/" + getMakeFileName(); |
| } |
| |
| public static String getModuleNameStatic() { |
| return "runnables"; |
| } |
| |
| public static String getLibName() { |
| return "RUNNABLES_LIB"; |
| } |
| |
| @Override |
| public String getModuleName() { |
| return getModuleNameStatic(); |
| } |
| |
| @Override |
| public String getCall() { |
| String name = (this.runnable == null) ? "???" : runnable.getName(); |
| return name + "()"; |
| } |
| |
| @Override |
| public String getIncFile() { |
| return (getModuleName() + ".h"); |
| } |
| |
| private Runnable runnable; |
| private Properties properties; |
| |
| public LinuxRunnableTranslationUnit(final OutputBuffer outputBuffer, |
| final LinuxActivityGraphItemTransformer linuxCallGraphItemTransformer, |
| final Runnable runnable, final Properties properties) { |
| super(outputBuffer); |
| this.runnable = runnable; |
| this.properties = properties; |
| |
| this.genFiles(); |
| } |
| |
| private String runnableName() { |
| return (runnable == null) ? "???" : runnable.getName(); |
| } |
| |
| public void genFiles() { |
| if (isIncFileEmpty()) { |
| incAppend(LinuxRunnableGenerator.snippetIncStart()); |
| } |
| if (this.isSrcFileEmpty()) { |
| srcAppend(LinuxRunnableGenerator.snippetSrcStart()); |
| } |
| |
| // write header |
| incAppend("\n//Runnable " + runnableName() + "----\n"); |
| incAppend("void " + runnableName() + "(char* coreName);\n"); |
| |
| Calculation calc = new Calculation(); |
| calc.ticksSumMap.put("default", Integer.valueOf(0)); |
| |
| if (runnable != null && runnable.getActivityGraph() != null) { |
| for (ActivityGraphItem item : runnable.getActivityGraph().getItems()) { |
| if (item instanceof Ticks) { |
| Ticks ticks = (Ticks) item; |
| if (ticks.getDefault() != null && ticks.getDefault().getAverage() != null) { |
| calc.ticksSum += ticks.getDefault().getAverage().intValue(); |
| calc.ticksSumMap.put("default", calc.ticksSum); |
| } |
| |
| Set<ProcessingUnitDefinition> puDefinitions = ticks.getExtended().keySet(); |
| for (ProcessingUnitDefinition puDef : puDefinitions) { |
| if (puDef != null) { |
| String puDefName = puDef.getName(); |
| if (!calc.ticksSumMap.containsKey(puDefName)) { |
| calc.ticksSumMap.put(puDefName, 0); |
| } |
| calc.ticksSumMap.put(puDefName, calc.ticksSumMap.get(puDefName) + |
| ticks.getExtended().get(puDef).getAverage().intValue()); |
| } |
| } |
| } else if (item instanceof LabelAccess) { |
| LabelAccess la = (LabelAccess) item; |
| Float value = Float.parseFloat( |
| properties.getOrDefault("labelAccessStatisticValueDefault", "1.0F").toString()); |
| |
| LabelAccessStatistic labelStatistic = la.getStatistic(); |
| if (labelStatistic != null) { |
| NumericStatistic labelStatisticValue = labelStatistic.getValue(); |
| |
| if (labelStatisticValue instanceof SingleValueStatistic) { |
| value = ((SingleValueStatistic) labelStatisticValue).getValue(); |
| } else if (labelStatisticValue instanceof MinAvgMaxStatistic) { |
| // TODO: provide a configuration option, to select appropriate value |
| // from labelStatistic (min/max/avg) |
| // right now considering the average value |
| value = ((MinAvgMaxStatistic) labelStatisticValue).getAvg(); |
| } |
| } |
| |
| if (la.getAccess() == LabelAccessEnum.READ) { |
| calc.readsSum += value.intValue(); |
| } else if (la.getAccess() == LabelAccessEnum.WRITE) { |
| calc.writesSum += value.intValue(); |
| } |
| } |
| } |
| } |
| |
| boolean useExperimental = Boolean.parseBoolean(properties.getProperty("experimentalCodeSnippetMatching")); |
| |
| String codeString = LinuxRunnableGenerator.syntheticLoad(useExperimental); |
| srcAppend(LinuxRunnableGenerator.snippetSrcBody(runnable, codeString)); |
| } |
| |
| } |