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
.ITmfEventField
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
26 import com
.google
.common
.collect
.ImmutableList
;
29 * An aspect is a piece of information that can be extracted, directly or
30 * indirectly, from a trace event.
32 * Simple examples could be timestamp, or event fields. But it could also be
33 * something like a state system request, at the timestamp of the given event.
35 * The aspect can then be used to populate event table columns, to filter
36 * on to only keep certain events, to plot XY charts, etc.
38 * @author Alexandre Montplaisir
40 public interface ITmfEventAspect
{
43 * Static definition of an empty string. You can use this instead of 'null'!
45 String EMPTY_STRING
= ""; //$NON-NLS-1$
48 * List of all common base aspects
50 public static final List
<ITmfEventAspect
> BASE_ASPECTS
=
51 checkNotNull(ImmutableList
.of(
52 BaseAspects
.TIMESTAMP
,
53 BaseAspects
.EVENT_TYPE
,
55 BaseAspects
.TRACE_NAME
58 * Some basic aspects that all trace types should be able to use, using
59 * methods found in {@link ITmfEvent}.
61 interface BaseAspects
{
64 * Aspect for the event timestamp
66 ITmfEventAspect TIMESTAMP
= new ITmfEventAspect() {
68 public String
getName() {
69 return Messages
.getMessage(Messages
.AspectName_Timestamp
);
73 public String
getHelpText() {
78 public @Nullable ITmfTimestamp
resolve(ITmfEvent event
) {
79 return event
.getTimestamp();
84 * Aspect for the event type
86 ITmfEventAspect EVENT_TYPE
= new ITmfEventAspect() {
88 public String
getName() {
89 return Messages
.getMessage(Messages
.AspectName_EventType
);
93 public String
getHelpText() {
94 return Messages
.getMessage(Messages
.AspectHelpText_EventType
);
98 public @Nullable String
resolve(ITmfEvent event
) {
99 ITmfEventType type
= event
.getType();
103 return type
.getName();
108 * Aspect for the aggregated event contents (fields)
110 TmfEventFieldAspect CONTENTS
= new TmfEventFieldAspect(Messages
.getMessage(Messages
.AspectName_Contents
), null, new TmfEventFieldAspect
.IRootField() {
112 public @Nullable ITmfEventField
getRootField(ITmfEvent event
) {
113 return event
.getContent();
117 public String
getHelpText() {
118 return Messages
.getMessage(Messages
.AspectHelpText_Contents
);
124 * Aspect for the trace's name (for experiments with many traces)
126 ITmfEventAspect TRACE_NAME
= new ITmfEventAspect() {
128 public String
getName() {
129 return Messages
.getMessage(Messages
.AspectName_TraceName
);
133 public String
getHelpText() {
134 return Messages
.getMessage(Messages
.AspectHelpText_TraceName
);
138 public @Nullable String
resolve(ITmfEvent event
) {
139 return event
.getTrace().getName();
145 * Get the name of this aspect. This name will be user-visible and, as such,
146 * should be localized.
148 * @return The name of this aspect.
153 * Return a descriptive help text of what this aspect does. This could then
154 * be shown in tooltip or in option dialogs for instance. It should also be
157 * You can return {@link #EMPTY_STRING} if you judge that the aspect name
160 * @return The help text of this aspect
162 String
getHelpText();
165 * The "functor" representing this aspect. Basically, what to do for an
166 * event that is passed in parameter.
168 * Note to implementers:
170 * The parameter type here is {@link ITmfEvent}. This is because you could
171 * receive any type of event here. Do not assume you will only receive
172 * events of your own trace type. It is perfectly fine to return
173 * {@link #EMPTY_STRING} for event types you don't support.
175 * You also can (and should) provide a more specific return type than
179 * The event to process
180 * @return The resulting tidbit of information for this event.
182 @Nullable Object
resolve(ITmfEvent event
);