LTTng: CPU usage analysis from the LTTng kernel trace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfEvent.java
index 2265ce91e7f341e5db2d372e0145483a0a9362d0..8cab950ec05c60a4eb65b5453e6dd9cdad63f538 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2013 Ericsson
+ * Copyright (c) 2011, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License v1.0 which
@@ -18,6 +18,7 @@ import java.util.Set;
 
 import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
 import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.tmf.core.event.ITmfCustomAttributes;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
@@ -28,8 +29,8 @@ import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 
 /**
- * A wrapper class around CTF's Event Definition/Declaration that maps all
- * types of Declaration to native Java types.
+ * A wrapper class around CTF's Event Definition/Declaration that maps all types
+ * of Declaration to native Java types.
  *
  * @version 1.0
  * @author Alexandre Montplaisir
@@ -49,9 +50,9 @@ public class CtfTmfEvent extends TmfEvent
     // Attributes
     // ------------------------------------------------------------------------
 
-    private final int sourceCPU;
-    private final long typeId;
-    private final String eventName;
+    private final int fSourceCPU;
+    private final long fTypeId;
+    private final String fEventName;
     private final IEventDeclaration fDeclaration;
 
     // ------------------------------------------------------------------------
@@ -74,9 +75,9 @@ public class CtfTmfEvent extends TmfEvent
         );
 
         fDeclaration = declaration;
-        sourceCPU = cpu;
-        typeId = declaration.getId();
-        eventName = declaration.getName();
+        fSourceCPU = cpu;
+        fTypeId = declaration.getId();
+        fEventName = declaration.getName();
 
     }
 
@@ -96,10 +97,10 @@ public class CtfTmfEvent extends TmfEvent
                 null,
                 new TmfEventField("", null, new CtfTmfEventField[0]), //$NON-NLS-1$
                 NO_STREAM);
-        this.sourceCPU = -1;
-        this.typeId = -1;
-        this.eventName = EMPTY_CTF_EVENT_NAME;
-        this.fDeclaration = null;
+        fSourceCPU = -1;
+        fTypeId = -1;
+        fEventName = EMPTY_CTF_EVENT_NAME;
+        fDeclaration = null;
     }
 
     // ------------------------------------------------------------------------
@@ -112,7 +113,7 @@ public class CtfTmfEvent extends TmfEvent
      * @return The cpu id for a given source. In lttng it's from CPUINFO
      */
     public int getCPU() {
-        return this.sourceCPU;
+        return fSourceCPU;
     }
 
     /**
@@ -124,30 +125,24 @@ public class CtfTmfEvent extends TmfEvent
      * @return The event ID
      */
     public long getID() {
-        return this.typeId;
-    }
-
-    /**
-     * Gets the name of a current event.
-     *
-     * @return The event name
-     */
-    public String getEventName() {
-        return eventName;
+        return fTypeId;
     }
 
     @Override
     public CtfTmfTrace getTrace() {
-        /* Should be of the right type, since we take a CtfTmfTrace at the constructor */
+        /*
+         * Should be of the right type, since we take a CtfTmfTrace at the
+         * constructor
+         */
         return (CtfTmfTrace) super.getTrace();
     }
 
     @Override
     public ITmfEventType getType() {
-        CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(eventName);
+        CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(getTrace(), fEventName);
         if (ctfTmfEventType == null) {
             /* Should only return null the first time */
-            ctfTmfEventType = new CtfTmfEventType(this.getEventName(), this.getContent());
+            ctfTmfEventType = new CtfTmfEventType(fEventName, getTrace(), getContent());
         }
         return ctfTmfEventType;
     }
@@ -158,7 +153,7 @@ public class CtfTmfEvent extends TmfEvent
     @Override
     public Set<String> listCustomAttributes() {
         if (fDeclaration == null) {
-            return new HashSet<String>();
+            return new HashSet<>();
         }
         return fDeclaration.getCustomAttributes();
     }
@@ -183,18 +178,24 @@ public class CtfTmfEvent extends TmfEvent
     @Override
     public CtfTmfCallsite getCallsite() {
         CTFCallsite callsite = null;
-        if (getTrace() == null) {
+        CtfTmfTrace trace = getTrace();
+        if (trace == null) {
+            return null;
+        }
+        CTFTrace ctfTrace = trace.getCTFTrace();
+        /* Should not happen, but it is a good check */
+        if (ctfTrace == null) {
             return null;
         }
         if (getContent() != null) {
             ITmfEventField ipField = getContent().getField(CtfConstants.CONTEXT_FIELD_PREFIX + CtfConstants.IP_KEY);
             if (ipField != null && ipField.getValue() instanceof Long) {
                 long ip = (Long) ipField.getValue();
-                callsite = getTrace().getCTFTrace().getCallsite(eventName, ip);
+                callsite = ctfTrace.getCallsite(fEventName, ip);
             }
         }
         if (callsite == null) {
-            callsite = getTrace().getCTFTrace().getCallsite(eventName);
+            callsite = ctfTrace.getCallsite(fEventName);
         }
         if (callsite != null) {
             return new CtfTmfCallsite(callsite);
This page took 0.027729 seconds and 5 git commands to generate.