Commit | Line | Data |
---|---|---|
5c82e602 AM |
1 | /********************************************************************** |
2 | * Copyright (c) 2015 Ericsson and others | |
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 | ||
10 | package org.eclipse.tracecompass.lttng2.ust.core.trace; | |
11 | ||
12 | import org.eclipse.jdt.annotation.NonNull; | |
13 | import org.eclipse.tracecompass.ctf.core.CTFStrings; | |
14 | import org.eclipse.tracecompass.ctf.core.event.EventDefinition; | |
15 | import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration; | |
16 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp; | |
17 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
18 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; | |
19 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory; | |
20 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; | |
21 | ||
22 | /** | |
23 | * Factory for {@link LttngUstEvent}. | |
24 | * | |
25 | * @author Matthew Khouzam | |
26 | * @author Alexandre Montplaisir | |
27 | * @since 2.0 | |
28 | */ | |
29 | public class LttngUstEventFactory extends CtfTmfEventFactory { | |
30 | ||
31 | private static final @NonNull LttngUstEventFactory INSTANCE = new LttngUstEventFactory(); | |
32 | ||
33 | /** | |
34 | * Private constructor. | |
35 | */ | |
36 | private LttngUstEventFactory() { | |
37 | super(); | |
38 | } | |
39 | ||
40 | public static @NonNull LttngUstEventFactory instance() { | |
41 | return INSTANCE; | |
42 | } | |
43 | ||
44 | @Override | |
45 | public CtfTmfEvent createEvent(CtfTmfTrace trace, EventDefinition eventDef, String fileName) { | |
46 | /* Prepare what to pass to CtfTmfEvent's constructor */ | |
47 | final IEventDeclaration eventDecl = eventDef.getDeclaration(); | |
48 | final long ts = eventDef.getTimestamp(); | |
49 | final TmfNanoTimestamp timestamp = trace.createTimestamp(trace.timestampCyclesToNanos(ts)); | |
50 | ||
51 | int sourceCPU = eventDef.getCPU(); | |
52 | ||
53 | String reference = (fileName == null ? NO_STREAM : fileName); | |
54 | ||
55 | /* Handle the special case of lost events */ | |
56 | if (eventDecl.getName().equals(CTFStrings.LOST_EVENT_NAME)) { | |
57 | return createLostEvent(trace, eventDef, eventDecl, ts, timestamp, sourceCPU, reference); | |
58 | } | |
59 | ||
60 | /* Handle standard event types */ | |
61 | return new LttngUstEvent(trace, | |
62 | ITmfContext.UNKNOWN_RANK, | |
63 | timestamp, | |
64 | reference, // filename | |
65 | sourceCPU, | |
66 | eventDecl, | |
67 | eventDef); | |
68 | } | |
69 | } |