Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraradermache2013-01-28 13:37:38 +0000
committeraradermache2013-01-28 13:37:38 +0000
commitebd5809581875b8c12cb622ae81c8067d668b945 (patch)
treef854e1f8841efea14d48498360f65cbb9926e202 /extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus
parent2744195194144042bef2c17eda5e1ef35d009933 (diff)
downloadorg.eclipse.papyrus-ebd5809581875b8c12cb622ae81c8067d668b945.tar.gz
org.eclipse.papyrus-ebd5809581875b8c12cb622ae81c8067d668b945.tar.xz
org.eclipse.papyrus-ebd5809581875b8c12cb622ae81c8067d668b945.zip
Initial version for migration of Qompass designer from 0.9.2 to the trunk (0.10)
Diffstat (limited to 'extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus')
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/Activator.java51
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/ClientServerTraceTestModelWizard.java11
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/IConfiguratorOTF.java53
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/IConfiguratorTrace.java40
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/QompassTraceMechanism.java181
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/TraceUtils.java45
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceCout.mtl14
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceLTTng.mtl172
-rw-r--r--extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceOTF.mtl28
9 files changed, 595 insertions, 0 deletions
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/Activator.java b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/Activator.java
new file mode 100644
index 00000000000..a9e29bfc7a2
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/Activator.java
@@ -0,0 +1,51 @@
+package org.eclipse.papyrus.qompass.modellibs.tracing;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.qompass.modellibs.tracing"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+}
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/ClientServerTraceTestModelWizard.java b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/ClientServerTraceTestModelWizard.java
new file mode 100644
index 00000000000..44b716be54a
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/ClientServerTraceTestModelWizard.java
@@ -0,0 +1,11 @@
+package org.eclipse.papyrus.qompass.modellibs.tracing;
+
+import org.eclipse.papyrus.qompass.modellibs.core.ModelCopyWizard;
+
+
+public class ClientServerTraceTestModelWizard extends ModelCopyWizard {
+
+ public ClientServerTraceTestModelWizard () {
+ modelName = "ClientServerTraceTest";
+ }
+}
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/IConfiguratorOTF.java b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/IConfiguratorOTF.java
new file mode 100644
index 00000000000..6dae4aa1244
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/IConfiguratorOTF.java
@@ -0,0 +1,53 @@
+package org.eclipse.papyrus.qompass.modellibs.tracing;
+
+import org.eclipse.papyrus.qompass.designer.core.PortUtils;
+import org.eclipse.papyrus.qompass.designer.core.Utils;
+import org.eclipse.papyrus.qompass.designer.core.deployment.DepPlanUtils;
+import org.eclipse.papyrus.qompass.designer.core.extensions.IInstanceConfigurator;
+import org.eclipse.papyrus.qompass.designer.core.transformations.ContainerContext;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Property;
+
+
+public class IConfiguratorOTF implements IInstanceConfigurator {
+
+ static final String PROP_PORT_NAME = "portName";
+
+ static final String PROP_INSTANCE_NAME = "instanceName";
+
+ /**
+ * Configure the passed trace instance
+ *
+ * @see org.eclipse.papyrus.qompass.designer.gentools.core.extensions.IInstanceConfigurator
+ */
+ public void configureInstance(InstanceSpecification instance, Property componentPart, ContainerContext context) {
+ // The tracing code needs informations about the component instance and port.
+
+ DepPlanUtils.configureProperty(instance, PROP_INSTANCE_NAME, "\"" + instance.getName() + "\"");
+
+ // port in context => interception of port => provide information about port and interface
+ if(context.port != null) {
+ // obtain required or provided interface (TODO: will fail, if both are provided!)
+ Interface intf = PortUtils.getProvided(context.port);
+ if(intf == null) {
+ intf = PortUtils.getRequired(context.port);
+ }
+
+ DepPlanUtils.configureProperty(instance, PROP_PORT_NAME, "\"" + context.port.getName() + "\"");
+ if(intf != null) {
+ // this is specific for OTF:
+ // each container contains an attribute (id_<name>) for each operation. This is configured here,
+ // since we add instance information to the trace (is that useful??, seems like a hack)
+ for(Operation op : intf.getOperations()) {
+ String id = Utils.getTop(context.executorIS).getName() + "::Tracing::Trace::ID_" +
+ context.executorIS.getName().replace(".", "_") + "_" + op.getName();
+ DepPlanUtils.configureProperty(instance, "id_" + op.getName(), id);
+ }
+ }
+ }
+
+
+ }
+}
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/IConfiguratorTrace.java b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/IConfiguratorTrace.java
new file mode 100644
index 00000000000..9e33f4bda66
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/IConfiguratorTrace.java
@@ -0,0 +1,40 @@
+package org.eclipse.papyrus.qompass.modellibs.tracing;
+
+import org.eclipse.papyrus.qompass.designer.core.deployment.DepPlanUtils;
+import org.eclipse.papyrus.qompass.designer.core.extensions.IInstanceConfigurator;
+import org.eclipse.papyrus.qompass.designer.core.transformations.ContainerContext;
+import org.eclipse.papyrus.qompass.designer.core.transformations.ContainerTrafo;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.Property;
+
+public class IConfiguratorTrace implements IInstanceConfigurator {
+
+ static final String PROP_PORT_NAME = "portName";
+
+ static final String PROP_INSTANCE_NAME = "instanceName";
+
+ /**
+ * Configure the passed trace instance
+ *
+ * @see org.eclipse.papyrus.qompass.designer.gentools.core.extensions.IInstanceConfigurator
+ */
+ public void configureInstance(InstanceSpecification instance, Property componentPart, ContainerContext context) {
+ // The tracing code needs informations about the component instance and port.
+
+ String instanceName = instance.getName();
+ int index = instanceName.lastIndexOf(".");
+ if(index != -1) {
+ String lastSegment = instanceName.substring(index + 1);
+ if(lastSegment.startsWith(ContainerTrafo.interceptorName)) {
+ instanceName = instanceName.substring(0, index);
+ }
+ }
+
+ DepPlanUtils.configureProperty(instance, PROP_INSTANCE_NAME, "\"" + instanceName + "\"");
+
+ // port in context => interception of port => provide information about port and interface
+ if(context.port != null) {
+ DepPlanUtils.configureProperty(instance, PROP_PORT_NAME, "\"" + context.port.getName() + "\"");
+ }
+ }
+}
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/QompassTraceMechanism.java b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/QompassTraceMechanism.java
new file mode 100644
index 00000000000..0f0979541f7
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/QompassTraceMechanism.java
@@ -0,0 +1,181 @@
+package org.eclipse.papyrus.qompass.modellibs.tracing;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.infra.services.tracepoints.ITraceMechanism;
+import org.eclipse.papyrus.infra.services.tracepoints.MarkerUtils;
+import org.eclipse.papyrus.infra.services.tracepoints.TraceActions.TAOperation;
+import org.eclipse.papyrus.infra.services.tracepoints.TracepointConstants;
+import org.eclipse.papyrus.qompass.designer.core.Description;
+import org.eclipse.papyrus.qompass.designer.core.StUtils;
+import org.eclipse.papyrus.qompass.designer.core.Utils;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Property;
+
+import FCM.ConfigOption;
+import FCM.ContainerRule;
+import FCM.RuleApplication;
+
+public class QompassTraceMechanism implements ITraceMechanism {
+
+ public static final String EC3M_TRACING_URI = "pathmap://QML_TRACE/tracing.uml";
+
+ public static final URI tracingURI = URI.createURI(EC3M_TRACING_URI);
+
+ public EList<String> getTraceMechanismIDs(EObject eObj) {
+ EList<String> ids = new BasicEList<String>();
+ // obtain list of all available container rules via Utils. Restrict to those doing tracing.
+ EList<ContainerRule> containerRules = getContainerRules(eObj);
+ for(ContainerRule containerRule : containerRules) {
+ if(isForTracing(containerRule)) {
+ Class clazz = containerRule.getBase_Class();
+ ids.add(clazz.getName());
+ }
+ }
+ if(ids.size() == 0) {
+ ids.add("dummy qompass rule");
+ }
+ return ids;
+ }
+
+ public String getTraceMechanismDescription(EObject eObj, String id) {
+ EList<ContainerRule> containerRules = getContainerRules(eObj);
+ for(ContainerRule containerRule : containerRules) {
+ if(isForTracing(containerRule)) {
+ Class clazz = containerRule.getBase_Class();
+ if(clazz.getName().equals(id)) {
+ return Description.getDescription(clazz);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Apply the trace mechanism, i.e. set or unset the appropriate ContainerRule for tracing.
+ * Currently handles trace on class.
+ *
+ * Basic idea: always apply same container rule. But container rule expansion is different in function of set tracepoints.
+ * Need to unapply, if there is no longer a trace needing it.
+ */
+ public boolean applyTraceMechanism(EObject eObj, String id, int traceOption) {
+ Class clazzContext = getClassContext(eObj);
+ if(clazzContext == null) {
+ return false;
+ }
+ EList<ContainerRule> containerRules = getContainerRules(eObj);
+ for(ContainerRule containerRule : containerRules) {
+ if(isForTracing(containerRule)) {
+ Class clazz = containerRule.getBase_Class();
+
+ if(clazz.getName().equals(id)) {
+ if(traceOption == TAOperation.OnlyCall.ordinal()) {
+ // yes => what do we then (i.e. how is mapping done??)
+ }
+ RuleApplication ruleApplication = StUtils.applyApp(clazzContext, RuleApplication.class);
+ if((ruleApplication != null) && !ruleApplication.getContainerRule().contains(containerRule)) {
+ ruleApplication.getContainerRule().add(containerRule);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ // QompassTraceMechanism
+
+ public boolean isForTracing(ContainerRule rule) {
+ for(ConfigOption co : rule.getForConfig()) {
+ // TODO: not very clean to used fixed string
+ if(co.getBase_Class().getName().equals("Trace")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return the class (component) for which we need to apply a container rule
+ * to enable the tracing of the passed eObject. This eObject may be
+ * (1) A class, in this case it could be returned directly
+ * (2) An operation. In this case, the owning class is returned (caveat: operation might belong to an interface)
+ * (3) A property of the class (including ports).
+ *
+ * @param eObj
+ * see description above
+ * @return the class to a container rule may be applied
+ */
+ public Class getClassContext(EObject eObj) {
+ if(eObj instanceof Class) {
+ return (Class)eObj;
+ } else if(eObj instanceof Operation) {
+ return ((Operation)eObj).getClass_();
+ } else if(eObj instanceof Property) {
+ return ((Property)eObj).getClass_();
+ } else {
+ return null;
+ }
+ }
+
+ public EList<ContainerRule> getContainerRules(EObject eObj) {
+ if(eObj == null) {
+ // load rules of registered Tracing model library
+ try {
+ ModelSet ms = ServiceUtilsForActionHandlers.getInstance().getModelSet();
+ Resource rs = ms.getResource(tracingURI, true);
+ EList<EObject> contents = rs.getContents();
+ if((contents.size() > 0) && (contents.get(0) instanceof Package)) {
+ return Utils.getAllRules((Package)contents.get(0));
+ }
+ } catch (ServiceException e) {
+ System.err.println(e);
+ }
+ return new BasicEList<ContainerRule>();
+ } else {
+ Package top = Utils.getTop((Element)eObj);
+ return Utils.getAllRules(top);
+ }
+ }
+
+ public boolean configureTraceMechanisms() {
+ String config = "";
+ try {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+
+ if(root != null) {
+ Object tracePoints[] = root.findMarkers(TracepointConstants.tpOrbpMarker, true, IResource.DEPTH_INFINITE);
+ for(Object tracePointObj : tracePoints) {
+ if(tracePointObj instanceof IMarker) {
+ IMarker tracePoint = (IMarker)tracePointObj;
+ EObject eobj = MarkerUtils.getEObjectOfMarker(tracePoint);
+ if(MarkerUtils.isActive(tracePoint)) {
+ if(eobj instanceof NamedElement) {
+ config += ((NamedElement)eobj).getQualifiedName();
+ }
+ }
+ }
+ }
+ }
+ } catch (CoreException e) {
+ }
+ System.err.println(config);
+ return true;
+ }
+
+}
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/TraceUtils.java b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/TraceUtils.java
new file mode 100644
index 00000000000..e8b0e395785
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/TraceUtils.java
@@ -0,0 +1,45 @@
+package org.eclipse.papyrus.qompass.modellibs.tracing.acceleo;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.papyrus.infra.services.tracepoints.MarkerUtils;
+import org.eclipse.papyrus.infra.services.tracepoints.TracepointConstants;
+import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationContext;
+import org.eclipse.uml2.uml.Element;
+
+public class TraceUtils {
+
+ public static IMarker[] getMarkersForEObject(EObject eObject, String markerType) {
+ Resource resource = eObject.eResource();
+ IFile file = WorkspaceSynchronizer.getFile(resource);
+ if(file != null) {
+ try {
+ return file.findMarkers(markerType, true, IResource.DEPTH_INFINITE);
+ } catch (CoreException e) {
+ }
+ }
+ return new IMarker[0];
+ }
+
+ public static boolean hasTrace(Element eObject) {
+ IMarker markers[] = getMarkersForEObject(eObject, TracepointConstants.tpOrbpMarker);
+ for(IMarker marker : markers) {
+ // explicitly pass resourceSet of eObject we want to compare. Otherwise, the marker utils would
+ // load resources into its own resource set (leading to non-comparable eObjects)
+ EObject eObjOfMarker = MarkerUtils.getEObjectOfMarker(eObject.eResource().getResourceSet(), marker);
+ if(eObjOfMarker == eObject) {
+ return true;
+ }
+ }
+ // TODO: testing workaround (always return true for port based transformations)
+ if(TransformationContext.getPort() != null) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceCout.mtl b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceCout.mtl
new file mode 100644
index 00000000000..540bd60fa85
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceCout.mtl
@@ -0,0 +1,14 @@
+[module traceCout('http://www.eclipse.org/uml2/4.0.0/UML')]
+
+[import org::eclipse::papyrus::qompass::designer::core::acceleo::UMLTool/]
+[import org::eclipse::papyrus::qompass::designer::core::acceleo::utils_cpp/]
+
+[template public traceOp(operation: Operation)]
+// declare operation & use directly. Problem: declaration can not be within the scope of an operation
+updateTimestamp ();
+cout "enter operation: " << [operation.name/] << " at " << timestamp.ticks() << " parameters: " <<
+ [for (parameter : Parameter | operation.ownedParameter)] "[parameter.name/] (of type [parameter.type.name/]): " << [parameter.name/] [/for] << endl;
+)
+[if not (type = null)] [type.cppType()/] ret = [/if]rconn->[operation.cppCall()/];
+[if not (type = null)] return ret; [/if]
+[/template]
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceLTTng.mtl b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceLTTng.mtl
new file mode 100644
index 00000000000..af7a3358147
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceLTTng.mtl
@@ -0,0 +1,172 @@
+[module traceLTTng('http://www.eclipse.org/uml2/4.0.0/UML')/]
+
+[import org::eclipse::papyrus::qompass::designer::core::acceleo::UMLTool/]
+[import org::eclipse::papyrus::qompass::designer::core::acceleo::TransformationContext/]
+[import org::eclipse::papyrus::qompass::designer::core::acceleo::utils_cpp/]
+
+[query public hasTrace(element : Element) : Boolean =
+ invoke('org.eclipse.papyrus.qompass.modellibs.tracing.acceleo.TraceUtils',
+ 'hasTrace(org.eclipse.uml2.uml.Element)',
+ Sequence{element}) /]
+
+[template public declareTP(cl: Classifier)]
+#if !defined(HFILENAME_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define HFILENAME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <lttng/tracepoint.h>
+[for (operation : Operation | cl.getAllOperations())]
+[if hasTrace()]
+[declareTPop(tpName1(), operation)/]
+[/if]
+[/for]
+
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER [tpName1() /]
+
+#undef TRACEPOINT_INCLUDE_FILE
+#define TRACEPOINT_INCLUDE_FILE [trafoContextClassifier().getQualifiedName().replaceAll('::', '/') /].h
+
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+[/template]
+
+[template public declareTPop(tpName : String, operation : Operation)]
+#include <stdint.h>
+
+// declare trace point
+TRACEPOINT_EVENT([tpName1()/], [operation.tpName2()/],
+ TP_ARGS(const char *, instanceName[if (operation.parametersInInout()->size() > 0)], [/if][for (parameter : Parameter | operation.parametersInInout()) separator(', ')][flattenParNameAndType()/][/for]),
+ TP_FIELDS(
+ ctf_string(instanceName, instanceName)
+ [for (parameter : Parameter | operation.parametersInInout())]
+ [trafoContextClassifier().declareDependency(parameter.type)/][flattenCtfType(parameter.type, parameter.name)/]
+ [/for]
+ )
+)
+TRACEPOINT_MODEL_EMF_URI([tpName1()/], [operation.tpName2()/], "[operation.modelRef()/]")
+
+[/template]
+
+[template public declareCreateDestroy(tpName : String)]
+TRACEPOINT_EVENT([tpName/], createClass,
+ TP_ARGS(const char *, classURI),
+ TP_FIELDS(
+ ctf_string(classURI, classURI)
+ )
+)
+TRACEPOINT_EVENT([tpName/], destroyClass,
+ TP_ARGS(const char *, className),
+ TP_FIELDS(
+ ctf_string(xmdID, className)
+ )
+)
+[/template]
+
+
+[comment
+ The name that is used for the trace provider
+/]
+[template public tpName1()]
+[templateBinding().getNearestPackage().getQualifiedName().varName()/]
+[/template]
+
+
+[comment
+ The name that is used for the type
+/]
+[template public tpName2(operation : Operation)]
+[operation.name/]
+[/template]
+
+
+[comment
+ Reference either the port (if available in the context) or the operation that is traced
+/]
+[template public modelRef(operation : Operation) post(trim())]
+[if (trafoContextPort() = null)]
+ [operation.getSourceRoot().getURI()/]#[operation.xmlID()/]
+[else]
+ [operation.getSourceRoot().getURI()/]#[trafoContextPort().xmlID()/]
+[/if]
+[/template]
+
+[comment
+/]
+[template public declareTraceOp(operation : Operation)]
+[/template]
+
+[template public invokeTP(operation : Operation)]
+[if hasTrace()]
+// use (call) tracepoint
+tracepoint([tpName1()/], [operation.tpName2()/], instanceName[if (operation.parametersInInout()->size() > 0)], [/if][for (parameter : Parameter | operation.parametersInInout()) separator(', ')][flattenParName()/][/for]);
+[/if]
+[/template]
+
+
+[template flattenParNameAndType(parameter : Parameter) post(trim())]
+[if (type.oclIsTypeOf(DataType))]
+ [for (attribute : Property | type.oclAsType(DataType).attribute) separator(', ')][attribute.type.cppTypeWB()/], [parameter.name + '_' + attribute.name/][/for]
+[else]
+ [parameter.type.cppTypeWB()/], [parameter.name/]
+[/if]
+[/template]
+
+[template flattenParName(parameter : Parameter) post(trim())]
+[if (type.oclIsTypeOf(DataType))]
+ [for (attribute : Property | type.oclAsType(DataType).attribute) separator(', ')][parameter.name + '.' + attribute.name/][/for]
+[else]
+ [parameter.name/]
+[/if]
+[/template]
+
+
+[template flattenCtfType(type : Type, name : String) post(trim())]
+[if (type.oclIsTypeOf(DataType))]
+ [for (attribute : Property | type.oclAsType(DataType).attribute) separator('\n')][ctfType(attribute.type, name + '_' + attribute.name)/][/for]
+[else]
+ [ctfType(type, name)/]
+[/if]
+[/template]
+
+
+[template cppTypeWB(type : Type) post(trim())]
+[if
+ (type.qualifiedName = 'UMLPrimitiveTypes::Boolean') or
+ (type.qualifiedName = 'PrimitiveTypes::Boolean') or
+ (type.qualifiedName = 'CORBA::Boolean')]
+ /* bool */ unsigned char
+[else]
+ [cppType()/]
+[/if]
+[/template]
+
+
+[comment
+ Calculate the typename, defaulting to ctf_integer
+ TODO: treat pointer & ref stereotypes (can only evaulate on parameter or attribute, not on Type)
+/]
+[template public ctfType(type : Type, name : String) post(trim())]
+[if
+ (type.qualifiedName = 'CORBA::String') or
+ (type.qualifiedName = 'PrimitiveTypes::String') or
+ (type.qualifiedName = 'UMLPrimitiveTypes::String')]
+ ctf_string([name/], [name/])
+[elseif
+ (type.qualifiedName = 'CORBA::Float') or
+ (type.qualifiedName = 'CORBA::Double') or
+ (type.qualifiedName = 'AnsiCLibrary::float') or
+ (type.qualifiedName = 'AnsiCLibrary::double')]
+ ctf_float([type.cppType()/], [name/], [name/])
+[else]
+ ctf_integer([type.cppTypeWB()/], [name/], [name/])
+[/if]
+[/template]
diff --git a/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceOTF.mtl b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceOTF.mtl
new file mode 100644
index 00000000000..dbf20923f40
--- /dev/null
+++ b/extraplugins/qompass-designer/tracing/org.eclipse.papyrus.qompass.modellibs.tracing/src/org/eclipse/papyrus/qompass/modellibs/tracing/acceleo/traceOTF.mtl
@@ -0,0 +1,28 @@
+[module traceOTF('http://www.eclipse.org/uml2/4.0.0/UML')/]
+
+[import org::eclipse::papyrus::qompass::designer::core::acceleo::UMLTool/]
+[import org::eclipse::papyrus::qompass::designer::core::acceleo::utils_cpp/]
+
+[template public traceOp(operation: Operation)]
+
+// <instance>_<port>_<operation>
+// easier: <component>_<port>_<operation>
+updateTimestamp ();
+if (!hasDeclaredFunctions) {
+ declareFunctions();
+ hasDeclaredFunctions = true;
+}
+Tracing::TraceInit::wait();
+int processID = Tracing::TraceInit::getProcessID();
+OTF_Writer * writer = Tracing::TraceInit::getWriter();
+OTF_Writer_writeEnter (writer, timestamp.ticks(), <%enumSvcPrefix%>::id_<%owner.varName%>_<%varName%>, processID, 0);
+OTF_Writer_writeEventComment (writer, timestamp.ticks(), processID, portName);
+OTF_Writer_writeEventComment (writer, timestamp.ticks(), processID, instanceName);
+Tracing::TraceInit::post();
+[if not (type = null)] [type.cppType()/] ret = [/if]rconn->[operation.cppCall()/];
+updateTimestamp ();
+Tracing::TraceInit::wait();
+OTF_Writer_writeLeave (writer, timestamp.ticks(), <%enumSvcPrefix%>::id_<%owner.varName%>_<%varName%>, processID, 0);
+Tracing::TraceInit::post();
+[if not (type = null)] return ret;[/if]
+[/template] \ No newline at end of file

Back to the top