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 static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import java
.util
.List
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
25 import com
.google
.common
.collect
.ImmutableList
;
28 * An aspect is a piece of information that can be extracted, directly or
29 * indirectly, from a trace event.
31 * Simple examples could be timestamp, or event fields. But it could also be
32 * something like a state system request, at the timestamp of the given event.
34 * The aspect can then be used to populate event table columns, to filter
35 * on to only keep certain events, to plot XY charts, etc.
37 * @author Alexandre Montplaisir
39 public interface ITmfEventAspect
{
42 * Static definition of an empty string. You can use this instead of 'null'!
44 String EMPTY_STRING
= ""; //$NON-NLS-1$
47 * List of all common base aspects
49 public static final List
<ITmfEventAspect
> BASE_ASPECTS
=
50 checkNotNull(ImmutableList
.of(
51 BaseAspects
.TIMESTAMP
,
52 BaseAspects
.EVENT_TYPE
,
54 BaseAspects
.TRACE_NAME
57 * Some basic aspects that all trace types should be able to use, using
58 * methods found in {@link ITmfEvent}.
60 interface BaseAspects
{
63 * Aspect for the event timestamp
65 ITmfEventAspect TIMESTAMP
= new ITmfEventAspect() {
67 public String
getName() {
68 return Messages
.getMessage(Messages
.AspectName_Timestamp
);
72 public String
getHelpText() {
77 public @Nullable ITmfTimestamp
resolve(ITmfEvent event
) {
78 return event
.getTimestamp();
83 * Aspect for the event type
85 ITmfEventAspect EVENT_TYPE
= new ITmfEventAspect() {
87 public String
getName() {
88 return Messages
.getMessage(Messages
.AspectName_EventType
);
92 public String
getHelpText() {
93 return Messages
.getMessage(Messages
.AspectHelpText_EventType
);
97 public @Nullable String
resolve(ITmfEvent event
) {
98 ITmfEventType type
= event
.getType();
102 return type
.getName();
107 * Aspect for the aggregated event contents (fields)
109 ITmfEventAspect CONTENTS
= new ITmfEventAspect() {
111 public String
getName() {
112 return Messages
.getMessage(Messages
.AspectName_Contents
);
116 public String
getHelpText() {
117 return Messages
.getMessage(Messages
.AspectHelpText_Contents
);
121 public @Nullable String
resolve(ITmfEvent event
) {
122 return event
.getContent().toString();
127 * Aspect for the trace's name (for experiments with many traces)
129 ITmfEventAspect TRACE_NAME
= new ITmfEventAspect() {
131 public String
getName() {
132 return Messages
.getMessage(Messages
.AspectName_TraceName
);
136 public String
getHelpText() {
137 return Messages
.getMessage(Messages
.AspectHelpText_TraceName
);
141 public @Nullable String
resolve(ITmfEvent event
) {
142 return event
.getTrace().getName();
148 * Get the name of this aspect. This name will be user-visible and, as such,
149 * should be localized.
151 * @return The name of this aspect.
156 * Return a descriptive help text of what this aspect does. This could then
157 * be shown in tooltip or in option dialogs for instance. It should also be
160 * You can return {@link #EMPTY_STRING} if you judge that the aspect name
163 * @return The help text of this aspect
165 String
getHelpText();
168 * The "functor" representing this aspect. Basically, what to do for an
169 * event that is passed in parameter.
171 * Note to implementers:
173 * The parameter type here is {@link ITmfEvent}. This is because you could
174 * receive any type of event here. Do not assume you will only receive
175 * events of your own trace type. It is perfectly fine to return
176 * {@link #EMPTY_STRING} for event types you don't support.
178 * You also can (and should) provide a more specific return type than
182 * The event to process
183 * @return The resulting tidbit of information for this event.
185 @Nullable Object
resolve(ITmfEvent event
);