analysis.os: Add layouted requirements to the CPU analysis
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / parsers / custom / CustomEventAspects.java
CommitLineData
be222f56 1/*******************************************************************************
7a0b1e3c 2 * Copyright (c) 2010, 2015 Ericsson
be222f56
PT
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 * Patrick Tasse - Initial API and implementation
baafe54c 11 * Alexandre Montplaisir - Update for TmfEventTableColumn
be222f56
PT
12 *******************************************************************************/
13
b04903a2 14package org.eclipse.tracecompass.internal.tmf.core.parsers.custom;
be222f56 15
be222f56
PT
16import java.util.List;
17
baafe54c 18import org.eclipse.jdt.annotation.NonNull;
7ab857a1 19import org.eclipse.tracecompass.common.core.NonNullUtils;
2bdf0193 20import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
9447c7ee 21import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
2bdf0193
AM
22import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEvent;
23import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
24import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
be222f56 25
baafe54c
AM
26import com.google.common.collect.ImmutableList;
27
a0a88f65 28/**
b04903a2 29 * Event aspects for Custom {Text|XML} traces.
a0a88f65 30 *
b04903a2
AM
31 * Since this definition will be different for every single custom trace, we
32 * cannot define specific {@link ITmfEventAspect} in advance.
99d7adc6 33 *
b04903a2
AM
34 * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)}
35 * with the CustomTraceDefinition of the the particular trace to display.
99d7adc6
AM
36 *
37 * @author Alexandre Montplaisir
a0a88f65 38 */
b04903a2 39public class CustomEventAspects {
be222f56 40
baafe54c 41 /**
b04903a2
AM
42 * Aspects for custom events, which use an integer ID to represent each
43 * field.
baafe54c 44 */
9447c7ee 45 private static final class CustomEventFieldAspect implements ITmfEventAspect {
baafe54c 46
9447c7ee 47 private final @NonNull String fName;
baafe54c
AM
48 private final int fIndex;
49
50 /**
51 * Constructor
52 *
53 * @param name
b04903a2 54 * The name of this aspect
baafe54c 55 * @param idx
b04903a2 56 * The index of this field in the event's content to display
baafe54c 57 */
9447c7ee
AM
58 public CustomEventFieldAspect(@NonNull String name, int idx) {
59 fName = name;
baafe54c
AM
60 fIndex = idx;
61 }
62
63 @Override
9447c7ee
AM
64 public String getName() {
65 return fName;
66 }
67
68 @Override
69 public String getHelpText() {
70 return EMPTY_STRING;
71 }
72
73 @Override
74 public String resolve(ITmfEvent event) {
baafe54c 75 if (event instanceof CustomEvent) {
7ab857a1 76 return NonNullUtils.nullToEmptyString(((CustomEvent) event).getEventString(fIndex));
baafe54c
AM
77 }
78 return EMPTY_STRING;
79 }
baafe54c 80 }
be222f56 81
a0a88f65 82 /**
b04903a2 83 * Build a set of event aspects for a given trace definition
a0a88f65 84 *
b04903a2
AM
85 * @param definition
86 * The {@link CustomTraceDefinition} of the trace for which you
87 * want the aspects
88 * @return The set of event aspects for the given trace
a0a88f65 89 */
8192209b 90 public static @NonNull Iterable<ITmfEventAspect> generateAspects(CustomTraceDefinition definition) {
b04903a2 91 ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>();
baafe54c
AM
92 List<OutputColumn> outputs = definition.outputs;
93 for (int i = 0; i < outputs.size(); i++) {
94 String name = outputs.get(i).name;
7a0b1e3c 95 builder.add(new CustomEventFieldAspect(name, i));
be222f56 96 }
0e4f957e 97 return builder.build();
be222f56
PT
98 }
99}
This page took 0.086104 seconds and 5 git commands to generate.