6ea2aecb |
1 | Linux Trace Toolkit |
2 | |
3 | Mathieu Desnoyers 17-05-2004 |
4 | |
5 | |
6 | This document explains how the lttvwindow API could process the event requests |
7 | of the viewers, merging event requests and hook lists to benefit from the fact |
8 | that process_traceset can call multiple hooks for the same event. |
9 | |
10 | First, we will explain the detailed process of event delivery in the current |
11 | framework. We will then study its strengths and weaknesses. |
12 | |
13 | In a second time, a framework where the events requests are dealt by the main |
14 | window with fine granularity will be described. We will then discussed the |
15 | advantages and inconvenients over the first framework. |
16 | |
17 | |
18 | 1. (Actual) Boundaryless event reading |
19 | |
20 | Actually, viewers request events in a time interval from the main window. They |
21 | also specify a (not so) maximum number of events to be delivered. In fact, the |
22 | number of events to read only gives a stop point, from where only events with |
23 | the same timestamp will be delivered. |
24 | |
25 | Viewers register hooks themselves in the traceset context. When merging read |
26 | requests in the main window, all hooks registered by viewers will be called for |
27 | the union of all the read requests, because the main window has no control on |
28 | hook registration. |
29 | |
30 | The main window calls process_traceset on its own for all the intervals |
31 | requested by all the viewers. It must not duplicate a read of the same time |
32 | interval : it could be very hard to filter by viewers. So, in order to achieve |
33 | this, time requests are sorted by start time, and process_traceset is called for |
34 | each time request. We keep the last event time between each read : if the start |
35 | time of the next read is lower than the time reached, we continue the reading |
36 | from the actual position. |
37 | |
38 | We deal with specific number of events requests (infinite end time) by |
39 | garantying that, starting from the time start of the request, at least that |
40 | number of events will be read. As we can't do it efficiently without interacting |
41 | very closely with process_traceset, we always read the specified number of |
42 | events requested starting from the current position when we answer to a request |
43 | based on the number of events. |
44 | |
45 | The viewers have to filter events delivered by traceset reading, because they |
46 | can be asked by another viewer for a totally (or partially) different time |
47 | interval. |
48 | |
49 | |
50 | Weaknesses |
51 | |
52 | - process_middle does not guarantee the number of events read |
53 | |
54 | First of all, a viewer that requests events to process_traceset has no garantee |
55 | that it will get exactly what it asked for. For example, a direct call to |
56 | traceset_middle for a specific number of events will delived _at least_ that |
57 | quantity of events, plus the ones that have the same timestamp that the last one |
58 | has. |
59 | |
60 | - Border effects |
61 | |
62 | Viewer's writers will have to deal with a lot of border effects caused by the |
318585ee |
63 | particularities of the reading. They will be required to select the information |
64 | they need from their input by filtering. |
6ea2aecb |
65 | |
318585ee |
66 | - Lack of encapsulation and difficulty of testing |
6ea2aecb |
67 | |
68 | The viewer's writer will have to take into account all the border effects caused |
69 | by the interaction with other modules. This means that event if a viewer works |
70 | well alone or with another viewer, it's possible that new bugs arises when a new |
318585ee |
71 | viewer comes around. So, even if a perfect testbench works well for a viewer, it |
72 | does not confirm that no new bug will arise when another viewer is loaded at the |
73 | same moment asking for different time intervals. |
6ea2aecb |
74 | |
75 | |
76 | - Duplication of the work |
77 | |
78 | Time based filters and counters of events will have to be implemented at the |
79 | viewer's side, which is a duplication of the functionnalities that would |
80 | normally be expected from the tracecontext API. |
81 | |
82 | - Lack of control over the data input |
83 | |
84 | As we expect module's writers to prefer to be as close as possible from the raw |
85 | datas, making them interact with a lower level library that gives them a data |
86 | input that they only control by further filtering of the input is not |
87 | appropriated. We should expect some reluctancy from them about using this API |
88 | because of this lack of control on the input. |
89 | |
90 | - Speed cost |
91 | |
92 | All hooks of all viewers will be called for all the time intervals. So, if we |
93 | have a detailed events list and a control flow view, asking both for different |
94 | time intervals, the detailed events list will have to filter all the events |
95 | delivered originally to the control flow view. This can be a case occuring quite |
96 | often. |
97 | |
98 | |
99 | |
100 | Strengths |
101 | |
102 | - Simple concatenation of time intervals at the main window level. |
103 | |
104 | Having the opportunity of delivering more events than necessary to the viewers |
105 | means that we can concatenate time intervals and number of events requested |
106 | fairly easily, while being hard to determine if some specific cases will be |
318585ee |
107 | wrong, in depth testing being impossible. |
6ea2aecb |
108 | |
109 | - No duplication of the tracecontext API |
110 | |
111 | Viewers deal directly with the tracecontext API for registering hooks, removing |
112 | a layer of encapsulation. |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | 2. (Proposed) Strict boundaries events reading |
119 | |
120 | The idea behind this method is to provide exactly the events requested by the |
121 | viewers to them, no more, no less. |
122 | |
6ea2aecb |
123 | It uses the new API for process traceset suggested in the document |
124 | process_traceset_strict_boundaries.txt. |
125 | |
126 | It also means that the lttvwindow API will have to deal with viewer's hooks. |
127 | Those will not be allowed to add them directly in the context. They will give |
128 | them to the lttvwindow API, along with the time interval or the position and |
129 | number of events. The lttvwindow API will have to take care of adding and |
130 | removing hooks for the different time intervals requested. That means that hooks |
131 | insertion and removal will be done between each traceset processing based on |
132 | the time intervals and event positions related to each hook. We must therefore |
133 | provide a simple interface for hooks passing between the viewers and the main |
318585ee |
134 | window, make them easier to manage from the main window. A modification to the |
135 | LttvHooks type solves this problem. |
6ea2aecb |
136 | |
137 | |
138 | Architecture |
139 | |
140 | Added to the lttvwindow API : |
141 | |
142 | |
589a505d |
143 | void lttvwindow_events_request |
fc9fa653 |
144 | ( MainWindow *main_win, |
3c502bdc |
145 | EventsRequest *events_request); |
6ea2aecb |
146 | |
147 | |
148 | Internal functions : |
149 | |
150 | - lttvwindow_process_pending_requests |
151 | |
152 | |
153 | |
154 | Implementation |
155 | |
156 | |
318585ee |
157 | - Type LttvHooks |
6ea2aecb |
158 | |
6d917c2c |
159 | see hook_prio.txt |
6ea2aecb |
160 | |
318585ee |
161 | The viewers will just have to pass hooks to the main window through this type, |
162 | using the hook.h interface to manipulate it. Then, the main window will add |
163 | them and remove them from the context to deliver exactly the events requested by |
164 | each viewer through process traceset. |
6ea2aecb |
165 | |
6ea2aecb |
166 | |
318585ee |
167 | - lttvwindow_events_request |
6ea2aecb |
168 | |
3c502bdc |
169 | It adds the a pointer to the EventsRequest struct to the array of time requests |
170 | pending and registers a pending request for the next g_idle if none is |
171 | registered. The viewer has to keep a reference to this structure in its own |
172 | instance data structure. Only the stop_flag can be changed by the viewer |
173 | through the event hooks. |
6ea2aecb |
174 | |
318585ee |
175 | typedef struct _EventsRequest { |
3c502bdc |
176 | LttTime start_time, /* Unset : { 0, 0 } */ |
177 | LttvTracesetContextPosition start_position, /* Unset : num_traces = 0 */ |
178 | gboolean stop_flag, /* Continue:TRUE Stop:FALSE */ |
179 | LttTime end_time, /* Unset : { 0, 0 } */ |
180 | guint num_events, /* Unset : G_MAXUINT */ |
181 | LttvTracesetContextPosition end_position, /* Unset : num_traces = 0 */ |
182 | LttvHooks *before_traceset, /* Unset : NULL */ |
183 | LttvHooks *before_trace, /* Unset : NULL */ |
184 | LttvHooks *before_tracefile, /* Unset : NULL */ |
185 | LttvHooks *event, /* Unset : NULL */ |
186 | LttvHooksById *event_by_id, /* Unset : NULL */ |
187 | LttvHooks *after_tracefile, /* Unset : NULL */ |
188 | LttvHooks *after_trace, /* Unset : NULL */ |
189 | LttvHooks *after_traceset /* Unset : NULL */ |
318585ee |
190 | } EventsRequest; |
6ea2aecb |
191 | |
192 | |
193 | - lttvwindow_process_pending_requests |
194 | |
195 | This internal function gets called by g_idle, taking care of the pending |
196 | requests. It is responsible for concatenation of time intervals and position |
318585ee |
197 | requests. It does it with the following algorithm organizing process traceset |
198 | calls. Here is the detailed description of the way it works : |
199 | |
200 | |
201 | - Events Requests Servicing Algorithm |
202 | |
203 | Data structures necessary : |
204 | |
205 | List of requests added to context : list_in |
206 | List of requests not added to context : list_out |
207 | |
208 | Initial state : |
209 | |
210 | list_in : empty |
211 | list_out : many events requests |
212 | |
213 | |
214 | While list_in !empty and list_out !empty |
215 | 1. If list_in is empty (need a seek) |
216 | 1.1 Add requests to list_in |
217 | 1.1.1 Find all time requests with the lowest start time in list_out |
218 | (ltime) |
219 | 1.1.2 Find all position requests with the lowest position in list_out |
220 | (lpos) |
221 | 1.1.3 If lpos.start time < ltime |
222 | - Add lpos to list_in, remove them from list_out |
223 | 1.1.4 Else, (lpos.start time >= ltime) |
224 | - Add ltime to list_in, remove them from list_out |
225 | 1.2 Seek |
226 | 1.2.1 If first request in list_in is a time request |
227 | 1.2.1.1 Seek to that time |
228 | 1.2.2 Else, the first request in list_in is a position request |
229 | 1.2.2.1 Seek to that position |
230 | 1.3 Call begin for all list_in members |
231 | (1.3.1 begin hooks called) |
232 | (1.3.2 middle hooks added) |
233 | 2. Else, list_in is not empty, we continue a read |
234 | 2.1 For each req of list_out |
d87e4888 |
235 | - if req.start time == current context time |
318585ee |
236 | - Add to list_in, remove from list_out |
237 | - Call begin |
238 | - if req.start position == current position |
239 | - Add to list_in, remove from list_out |
240 | - Call begin |
241 | |
242 | 3. Find end criterions |
243 | 3.1 End time |
244 | 3.1.1 Find lowest end time in list_in |
245 | 3.1.2 Find lowest start time in list_out |
246 | 3.1.3 Use lowest of both as end time |
247 | 3.2 Number of events |
248 | 3.2.1 Find lowest number of events in list_in |
249 | 3.3 End position |
250 | 3.3.1 Find lowest end position in list_in |
251 | 3.3.2 Find lowest start position in list_out |
252 | 3.3.3 Use lowest of both as end position |
253 | |
254 | 4. Call process traceset middle |
255 | 4.1 Call process traceset middle (Use end criterion found in 3) |
3c502bdc |
256 | * note : end criterion can also be viewer's hook returning TRUE |
318585ee |
257 | 5. After process traceset middle |
258 | 5.1 For each req in list_in |
259 | - req.num -= count |
260 | - if req.num == 0 |
261 | - Call end for req |
262 | - remove req from list_in |
d87e4888 |
263 | - if current context time > req.end time |
318585ee |
264 | - Call end for req |
265 | - remove req from list_in |
266 | - if req.end pos == current pos |
267 | - Call end for req |
268 | - remove req from list_in |
3c502bdc |
269 | - if req.stop_flag == TRUE |
270 | - Call end for req |
271 | - remove req from list_in |
318585ee |
272 | |
273 | |
274 | |
275 | Notes : |
276 | End criterions for process traceset middle : |
277 | If the criterion is reached, event is out of boundaries and we return. |
97caad97 |
278 | Current time >= End time |
318585ee |
279 | Event count > Number of events |
280 | Current position >= End position |
3c502bdc |
281 | Last hook list called returned TRUE |
318585ee |
282 | |
283 | The >= for position is necessary to make ensure consistency between start time |
284 | requests and positions requests that happens to be at the exact same start time |
285 | and position. |
6ea2aecb |
286 | |
287 | |
288 | |
289 | Weaknesses |
290 | |
318585ee |
291 | - None (nearly?) :) |
6ea2aecb |
292 | |
293 | |
294 | Strengths |
295 | |
296 | - Removes the need for filtering of information supplied to the viewers. |
297 | |
298 | - Viewers have a better control on their data input. |
299 | |
300 | - Solves all the weaknesses idenfied in the actual boundaryless traceset |
301 | reading. |