Commit | Line | Data |
---|---|---|
8d2e2848 | 1 | /******************************************************************************* |
e31e01e8 | 2 | * Copyright (c) 2009, 2010 Ericsson |
8d2e2848 FC |
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 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.trace; | |
14 | ||
e31e01e8 | 15 | import org.eclipse.linuxtools.tmf.component.ITmfContext; |
8d2e2848 FC |
16 | |
17 | /** | |
18 | * <b><u>TmfTraceContext</u></b> | |
19 | * <p> | |
e31e01e8 FC |
20 | * Trace context structure. It ties a trace location to an event index and |
21 | * timestamp. The context should be enough to restore the trace state so the | |
22 | * corresponding event can be read. | |
23 | * <p> | |
8d2e2848 FC |
24 | * Used to handle conflicting, concurrent accesses to the trace. |
25 | */ | |
e31e01e8 | 26 | public class TmfTraceContext implements ITmfContext, Cloneable { |
8d2e2848 FC |
27 | |
28 | private Object location; | |
e31e01e8 FC |
29 | // private TmfTimestamp timestamp; |
30 | private long rank; | |
8d2e2848 | 31 | |
e31e01e8 FC |
32 | // public TmfTraceContext(Object loc, TmfTimestamp ts, long ind) { |
33 | // location = loc; | |
34 | // timestamp = ts; | |
35 | // index = ind; | |
36 | // } | |
37 | ||
38 | public TmfTraceContext(Object loc, long ind) { | |
39 | // this(loc, null, 0); | |
8d2e2848 | 40 | location = loc; |
e31e01e8 | 41 | rank = ind; |
8d2e2848 FC |
42 | } |
43 | ||
98029bc9 | 44 | public TmfTraceContext(Object loc) { |
e31e01e8 | 45 | this(loc, 0); |
98029bc9 FC |
46 | } |
47 | ||
8d2e2848 | 48 | public TmfTraceContext(TmfTraceContext other) { |
e31e01e8 FC |
49 | // this(other.location, other.timestamp, other.index); |
50 | this(other.location, other.rank); | |
51 | } | |
52 | ||
53 | public TmfTraceContext clone() { | |
54 | try { | |
55 | return (TmfTraceContext) super.clone(); | |
56 | } catch (CloneNotSupportedException e) { | |
57 | e.printStackTrace(); | |
58 | } | |
59 | return null; | |
8d2e2848 FC |
60 | } |
61 | ||
62 | public Object getLocation() { | |
8d2e2848 FC |
63 | return location; |
64 | } | |
65 | ||
66 | public void setLocation(Object loc) { | |
8d2e2848 FC |
67 | location = loc; |
68 | } | |
69 | ||
e31e01e8 FC |
70 | // public TmfTimestamp getTimestamp() { |
71 | // return timestamp; | |
72 | // } | |
8d2e2848 | 73 | |
e31e01e8 FC |
74 | // public void setTimestamp(TmfTimestamp ts) { |
75 | // timestamp = ts; | |
76 | // } | |
8d2e2848 | 77 | |
e31e01e8 FC |
78 | public void setRank(long value) { |
79 | rank = value; | |
8d2e2848 FC |
80 | } |
81 | ||
e31e01e8 FC |
82 | public long getRank() { |
83 | return rank; | |
8d2e2848 FC |
84 | } |
85 | ||
e31e01e8 FC |
86 | public void incrRank() { |
87 | rank++; | |
8d2e2848 FC |
88 | } |
89 | ||
8d2e2848 FC |
90 | // // ======================================================================== |
91 | // // Toubleshooting code | |
92 | // // ======================================================================== | |
93 | // | |
e31e01e8 FC |
94 | // public Object getLocation() { |
95 | // validateLocation(location); | |
96 | // return location; | |
97 | // } | |
98 | // | |
99 | // // The FW expects the trace events to be ordered in time. | |
100 | // // If this is not the case, this invalidates the Trace index (at least) | |
101 | // private TmfTimestamp previous = TmfTimestamp.BigBang; | |
102 | // public void setLocation(Object loc) { | |
103 | // if (loc instanceof TmfTimestamp) { | |
104 | // TmfTimestamp ts = (TmfTimestamp) loc; | |
105 | // if (ts.compareTo(previous, false) < 0) { | |
106 | // System.out.println("Going back in time from " + previous + " to " + ts); | |
107 | // } | |
108 | // previous = ts; | |
109 | // } | |
110 | // validateLocation(loc); | |
111 | // } | |
112 | // | |
8d2e2848 | 113 | // static private DataInputStream in; |
98029bc9 FC |
114 | // static private int size = 100000; |
115 | // static private String locations[] = new String[size]; | |
8d2e2848 | 116 | // static public void init() { |
98029bc9 | 117 | // System.out.println("TmfTraceContext: Loading valid locations..."); |
8d2e2848 | 118 | // try { |
e31e01e8 FC |
119 | // // The trace context validation file is created by TmfTrace |
120 | // in = new DataInputStream(new BufferedInputStream(new FileInputStream("TmfTraceContext.dat"))); | |
98029bc9 FC |
121 | // int i = 0; |
122 | // while (i < size) { | |
123 | // locations[i] = in.readUTF(); | |
124 | // i++; | |
125 | // } | |
126 | // in.close(); | |
8d2e2848 FC |
127 | // } catch (FileNotFoundException e) { |
128 | // // TODO Auto-generated catch block | |
129 | // e.printStackTrace(); | |
130 | // } catch (IOException e) { | |
8d2e2848 FC |
131 | // } |
132 | // System.out.println("TmfTraceContext: Done."); | |
133 | // } | |
e31e01e8 | 134 | // |
8d2e2848 FC |
135 | // private boolean bsearch(long key) { |
136 | // int first = 0; | |
137 | // int last = size; | |
138 | // while (first < last) { | |
139 | // int mid = (first + last) / 2; | |
98029bc9 | 140 | // if (key < locations[mid]) { |
8d2e2848 | 141 | // last = mid; |
98029bc9 | 142 | // } else if (key > locations[mid]) { |
8d2e2848 FC |
143 | // first = mid + 1; |
144 | // } else { | |
145 | // return true; | |
146 | // } | |
147 | // } | |
148 | // return false; | |
149 | // } | |
150 | // | |
151 | // private void validateLocation(Object loc) { | |
152 | // long l = (Long) loc; | |
153 | // if (!bsearch(l)) { | |
154 | // System.out.println("TmfTraceContext: location is invalid!"); | |
155 | // } | |
156 | // } | |
157 | ||
158 | } |