1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 * Patrick Tasse - Added base aspect list
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
;
16 import java
.util
.List
;
18 import org
.eclipse
.jdt
.annotation
.Nullable
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
24 import com
.google
.common
.collect
.ImmutableList
;
27 * An aspect is a piece of information that can be extracted, directly or
28 * indirectly, from a trace event.
30 * Simple examples could be timestamp, or event fields. But it could also be
31 * something like a state system request, at the timestamp of the given event.
33 * The aspect can then be used to populate event table columns, to filter
34 * on to only keep certain events, to plot XY charts, etc.
36 * @author Alexandre Montplaisir
38 public interface ITmfEventAspect
{
41 * Static definition of an empty string. You can use this instead of 'null'!
43 String EMPTY_STRING
= ""; //$NON-NLS-1$
46 * List of all common base aspects
48 public static final List
<ITmfEventAspect
> BASE_ASPECTS
=
50 BaseAspects
.TIMESTAMP
,
51 BaseAspects
.EVENT_TYPE
,
53 BaseAspects
.TRACE_NAME
56 * Some basic aspects that all trace types should be able to use, using
57 * methods found in {@link ITmfEvent}.
59 interface BaseAspects
{
62 * Aspect for the event timestamp
64 ITmfEventAspect TIMESTAMP
= new ITmfEventAspect() {
66 public String
getName() {
67 return Messages
.getMessage(Messages
.AspectName_Timestamp
);
71 public String
getHelpText() {
76 public @Nullable ITmfTimestamp
resolve(ITmfEvent event
) {
77 return event
.getTimestamp();
82 * Aspect for the event type
84 ITmfEventAspect EVENT_TYPE
= new ITmfEventAspect() {
86 public String
getName() {
87 return Messages
.getMessage(Messages
.AspectName_EventType
);
91 public String
getHelpText() {
92 return Messages
.getMessage(Messages
.AspectHelpText_EventType
);
96 public @Nullable String
resolve(ITmfEvent event
) {
97 ITmfEventType type
= event
.getType();
101 return type
.getName();
106 * Aspect for the aggregated event contents (fields)
108 TmfEventFieldAspect CONTENTS
= new TmfEventFieldAspect(Messages
.getMessage(Messages
.AspectName_Contents
), null, new TmfEventFieldAspect
.IRootField() {
110 public @Nullable ITmfEventField
getRootField(ITmfEvent event
) {
111 return event
.getContent();
115 public String
getHelpText() {
116 return Messages
.getMessage(Messages
.AspectHelpText_Contents
);
122 * Aspect for the trace's name (for experiments with many traces)
124 ITmfEventAspect TRACE_NAME
= new ITmfEventAspect() {
126 public String
getName() {
127 return Messages
.getMessage(Messages
.AspectName_TraceName
);
131 public String
getHelpText() {
132 return Messages
.getMessage(Messages
.AspectHelpText_TraceName
);
136 public @Nullable String
resolve(ITmfEvent event
) {
137 return event
.getTrace().getName();
143 * Get the name of this aspect. This name will be user-visible and, as such,
144 * should be localized.
146 * @return The name of this aspect.
151 * Return a descriptive help text of what this aspect does. This could then
152 * be shown in tooltip or in option dialogs for instance. It should also be
155 * You can return {@link #EMPTY_STRING} if you judge that the aspect name
158 * @return The help text of this aspect
160 String
getHelpText();
163 * The "functor" representing this aspect. Basically, what to do for an
164 * event that is passed in parameter.
166 * Note to implementers:
168 * The parameter type here is {@link ITmfEvent}. This is because you could
169 * receive any type of event here. Do not assume you will only receive
170 * events of your own trace type. It is perfectly fine to return
171 * {@link #EMPTY_STRING} for event types you don't support.
173 * You also can (and should) provide a more specific return type than
177 * The event to process
178 * @return The resulting tidbit of information for this event.
180 @Nullable Object
resolve(ITmfEvent event
);