Commit | Line | Data |
---|---|---|
542ddfb3 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | *******************************************************************************/ | |
9 | ||
10 | package org.eclipse.tracecompass.tmf.ctf.core.trace; | |
11 | ||
12 | import org.eclipse.jdt.annotation.NonNullByDefault; | |
13 | import org.eclipse.jdt.annotation.Nullable; | |
14 | ||
15 | /** | |
16 | * Utility methods for traces in the CTF format. | |
17 | * | |
18 | * @author Alexandre Montplaisir | |
19 | * @since 2.0 | |
20 | */ | |
21 | @NonNullByDefault | |
22 | public final class CtfUtils { | |
23 | ||
24 | private CtfUtils() { | |
25 | } | |
26 | ||
27 | /** | |
28 | * Convenience method to get the tracer name from the trace's metadata. The | |
29 | * leading and trailing "" will be stripped from the returned string. | |
30 | * | |
31 | * @param trace | |
32 | * The trace to query | |
33 | * @return The tracer's name, or null if it is not defined in the metadata. | |
34 | */ | |
35 | public static @Nullable String getTracerName(CtfTmfTrace trace) { | |
36 | String str = trace.getEnvironment().get("tracer_name"); //$NON-NLS-1$ | |
37 | if (str == null) { | |
38 | return null; | |
39 | } | |
40 | /* Remove the "" at the start and end of the string */ | |
41 | return str.replaceAll("^\"|\"$", ""); //$NON-NLS-1$ //$NON-NLS-2$ | |
42 | } | |
43 | ||
44 | /** | |
45 | * Convenience method to get the tracer's major version from the trace | |
46 | * metadata. | |
47 | * | |
48 | * @param trace | |
49 | * The trace to query | |
50 | * @return The tracer's major version, or -1 if it is not defined. | |
51 | */ | |
52 | public static int getTracerMajorVersion(CtfTmfTrace trace) { | |
53 | String str = trace.getEnvironment().get("tracer_major"); //$NON-NLS-1$ | |
54 | if (str == null) { | |
55 | return -1; | |
56 | } | |
57 | try { | |
58 | int ret = Integer.parseInt(str); | |
59 | return ret; | |
60 | } catch (NumberFormatException e) { | |
61 | return -1; | |
62 | } | |
63 | } | |
64 | ||
65 | /** | |
66 | * Convenience method to get the tracer's minor version from the trace | |
67 | * metadata. | |
68 | * | |
69 | * @param trace | |
70 | * The trace to query | |
71 | * @return The tracer's minor version, or -1 if it is not defined. | |
72 | */ | |
73 | public static int getTracerMinorVersion(CtfTmfTrace trace) { | |
74 | String str = trace.getEnvironment().get("tracer_minor"); //$NON-NLS-1$ | |
75 | if (str == null) { | |
76 | return -1; | |
77 | } | |
78 | try { | |
79 | int ret = Integer.parseInt(str); | |
80 | return ret; | |
81 | } catch (NumberFormatException e) { | |
82 | return -1; | |
83 | } | |
84 | } | |
85 | } |