Rename parent, releng and target modules to tracecompass
[deliverable/tracecompass.git] / org.eclipse.linuxtools.btf.core / src / org / eclipse / linuxtools / btf / core / trace / BtfTimstampFormat.java
CommitLineData
ff71e543
MK
1/*******************************************************************************
2 * Copyright (c) 2014 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 *******************************************************************************/
12
13package org.eclipse.linuxtools.btf.core.trace;
14
15import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
16import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
17
18/**
19 * Timstamp format of BTF timescale as per v2.1 of the spec
20 *
21 * @author Matthew Khouzam
22 */
23public enum BtfTimstampFormat {
24 /**
25 * Picoseconds
26 */
27 PS("ps", -12, 0.001), //$NON-NLS-1$
28 /**
29 * Nanoseconds
30 */
31 NS("ns", -9, 1.0), //$NON-NLS-1$
32 /**
33 * Microseconds
34 */
35 US("us", -6, 1000.0), //$NON-NLS-1$
36 /**
37 * Milliseconds
38 */
39 MS("ms", -3, 1000000.0), //$NON-NLS-1$
40 /**
41 * Seconds
42 */
43 S("s", 0, 1000000000.0); //$NON-NLS-1$
44
45 private final String fName;
46 private final int fScale;
47 private final double fScaleFactor;
48
49 private BtfTimstampFormat(String name, int scale, double scaleFactor) {
50 fName = name;
51 fScale = scale;
52 fScaleFactor = scaleFactor;
53 }
54
55 /**
56 * Get the scaling factor
57 *
58 * @return the scaling factor
59 */
60 public double getScaleFactor() {
61 return fScaleFactor;
62 }
63
64 @Override
65 public String toString() {
66 return fName;
67 }
68
69 /**
70 * Parse a string to get a scale
71 *
72 * @param text
73 * the timestamp in text "ns", "ms" ...
74 * @return a BtfTimestampFormat object
75 */
76 public static BtfTimstampFormat parse(String text) {
77 switch (text.toLowerCase()) {
78 case "ps": //$NON-NLS-1$
79 throw new IllegalArgumentException("ps not yet supported"); //$NON-NLS-1$
80 case "ns": //$NON-NLS-1$
81 return BtfTimstampFormat.NS;
82 case "us": //$NON-NLS-1$
83 return BtfTimstampFormat.US;
84 case "ms": //$NON-NLS-1$
85 return BtfTimstampFormat.MS;
86 case "s": //$NON-NLS-1$
87 return BtfTimstampFormat.S;
88 default:
89 throw new IllegalArgumentException(text + " not a valid argument, use ps, ns, us, ms, s"); //$NON-NLS-1$
90 }
91 }
92
93 /**
94 * Create an ITmfTimestamp with a proper scale
95 *
96 * @param timestamp
97 * timestamp without scale
98 * @return TmfTimestamp with proper scale
99 */
100 public ITmfTimestamp createTimestamp(long timestamp) {
101 return new TmfTimestamp(timestamp, fScale);
102 }
103}
This page took 0.030546 seconds and 5 git commands to generate.