49a6bff89177c9dbf12565cc25503ba4f6a87639
[deliverable/tracecompass.git] / btf / org.eclipse.tracecompass.btf.core / src / org / eclipse / tracecompass / btf / core / trace / BtfEventAspects.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 * Alexandre Montplaisir - Update to new Event Table API
12 * Patrick Tasse - Update for renamed target field
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.btf.core.trace;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.tracecompass.btf.core.event.BtfEvent;
20 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
21 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
22 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
23
24 import com.google.common.collect.ImmutableList;
25
26 /**
27 * Columns to use in the BTF event table
28 *
29 * @author Alexandre Montplaisir
30 */
31 @NonNullByDefault
32 public final class BtfEventAspects {
33
34 private BtfEventAspects() {}
35
36 private static final Iterable<ITmfEventAspect<?>> BTF_ASPECTS =
37 ImmutableList.of(
38 ITmfEventAspect.BaseAspects.TIMESTAMP,
39 new BtfSourceAspect(),
40 new TmfContentFieldAspect(BtfColumnNames.SOURCE_INSTANCE.toString(), BtfColumnNames.SOURCE_INSTANCE.toString()),
41 ITmfEventAspect.BaseAspects.EVENT_TYPE,
42 new BtfTargetAspect(),
43 new TmfContentFieldAspect(BtfColumnNames.TARGET_INSTANCE.toString(), BtfColumnNames.TARGET_INSTANCE.toString()),
44 new TmfContentFieldAspect(BtfColumnNames.EVENT.toString(), BtfColumnNames.EVENT.toString()),
45 new TmfContentFieldAspect(BtfColumnNames.NOTES.toString(), BtfColumnNames.NOTES.toString())
46 );
47
48 /**
49 * The "source" aspect, whose value comes from {@link ITmfEvent#getSource()}
50 */
51 private static class BtfSourceAspect implements ITmfEventAspect<String> {
52
53 @Override
54 public String getName() {
55 return BtfColumnNames.SOURCE.toString();
56 }
57
58 @Override
59 public String getHelpText() {
60 return EMPTY_STRING;
61 }
62
63 @Override
64 public @Nullable String resolve(ITmfEvent event) {
65 if (!(event instanceof BtfEvent)) {
66 return EMPTY_STRING;
67 }
68 String ret = ((BtfEvent) event).getSource();
69 return (ret == null ? EMPTY_STRING : ret);
70 }
71 }
72
73 /**
74 * The "target" aspect, taking its value from
75 * {@link ITmfEvent#getTarget()}.
76 */
77 private static class BtfTargetAspect implements ITmfEventAspect<String> {
78
79 @Override
80 public String getName() {
81 return BtfColumnNames.TARGET.toString();
82 }
83
84 @Override
85 public String getHelpText() {
86 return EMPTY_STRING;
87 }
88
89 @Override
90 public @Nullable String resolve(ITmfEvent event) {
91 if (!(event instanceof BtfEvent)) {
92 return EMPTY_STRING;
93 }
94 String ret = ((BtfEvent) event).getTarget();
95 return (ret == null ? EMPTY_STRING : ret);
96 }
97 }
98
99 /**
100 * Return the event aspects defined for BTF traces.
101 *
102 * @return The aspects
103 */
104 public static Iterable<ITmfEventAspect<?>> getAspects() {
105 return BTF_ASPECTS;
106 }
107 }
This page took 0.032678 seconds and 4 git commands to generate.