events req servicing v2, with background computation, mod
[lttv.git] / ltt / branches / poly / doc / developer / lttvwindow_events_delivery.txt
CommitLineData
6ea2aecb 1Linux Trace Toolkit
2
3Mathieu Desnoyers 17-05-2004
4
5
6This document explains how the lttvwindow API could process the event requests
7of the viewers, merging event requests and hook lists to benefit from the fact
8that process_traceset can call multiple hooks for the same event.
9
10First, we will explain the detailed process of event delivery in the current
11framework. We will then study its strengths and weaknesses.
12
13In a second time, a framework where the events requests are dealt by the main
14window with fine granularity will be described. We will then discussed the
15advantages and inconvenients over the first framework.
16
17
181. (Actual) Boundaryless event reading
19
20Actually, viewers request events in a time interval from the main window. They
21also specify a (not so) maximum number of events to be delivered. In fact, the
22number of events to read only gives a stop point, from where only events with
23the same timestamp will be delivered.
24
25Viewers register hooks themselves in the traceset context. When merging read
26requests in the main window, all hooks registered by viewers will be called for
27the union of all the read requests, because the main window has no control on
28hook registration.
29
30The main window calls process_traceset on its own for all the intervals
31requested by all the viewers. It must not duplicate a read of the same time
32interval : it could be very hard to filter by viewers. So, in order to achieve
33this, time requests are sorted by start time, and process_traceset is called for
34each time request. We keep the last event time between each read : if the start
35time of the next read is lower than the time reached, we continue the reading
36from the actual position.
37
38We deal with specific number of events requests (infinite end time) by
39garantying that, starting from the time start of the request, at least that
40number of events will be read. As we can't do it efficiently without interacting
41very closely with process_traceset, we always read the specified number of
42events requested starting from the current position when we answer to a request
43based on the number of events.
44
45The viewers have to filter events delivered by traceset reading, because they
46can be asked by another viewer for a totally (or partially) different time
47interval.
48
49
50Weaknesses
51
52- process_middle does not guarantee the number of events read
53
54First of all, a viewer that requests events to process_traceset has no garantee
55that it will get exactly what it asked for. For example, a direct call to
56traceset_middle for a specific number of events will delived _at least_ that
57quantity of events, plus the ones that have the same timestamp that the last one
58has.
59
60- Border effects
61
62Viewer's writers will have to deal with a lot of border effects caused by the
318585ee 63particularities of the reading. They will be required to select the information
64they need from their input by filtering.
6ea2aecb 65
318585ee 66- Lack of encapsulation and difficulty of testing
6ea2aecb 67
68The viewer's writer will have to take into account all the border effects caused
69by the interaction with other modules. This means that event if a viewer works
70well alone or with another viewer, it's possible that new bugs arises when a new
318585ee 71viewer comes around. So, even if a perfect testbench works well for a viewer, it
72does not confirm that no new bug will arise when another viewer is loaded at the
73same moment asking for different time intervals.
6ea2aecb 74
75
76- Duplication of the work
77
78Time based filters and counters of events will have to be implemented at the
79viewer's side, which is a duplication of the functionnalities that would
80normally be expected from the tracecontext API.
81
82- Lack of control over the data input
83
84As we expect module's writers to prefer to be as close as possible from the raw
85datas, making them interact with a lower level library that gives them a data
86input that they only control by further filtering of the input is not
87appropriated. We should expect some reluctancy from them about using this API
88because of this lack of control on the input.
89
90- Speed cost
91
92All hooks of all viewers will be called for all the time intervals. So, if we
93have a detailed events list and a control flow view, asking both for different
94time intervals, the detailed events list will have to filter all the events
95delivered originally to the control flow view. This can be a case occuring quite
96often.
97
98
99
100Strengths
101
102- Simple concatenation of time intervals at the main window level.
103
104Having the opportunity of delivering more events than necessary to the viewers
105means that we can concatenate time intervals and number of events requested
106fairly easily, while being hard to determine if some specific cases will be
318585ee 107wrong, in depth testing being impossible.
6ea2aecb 108
109- No duplication of the tracecontext API
110
111Viewers deal directly with the tracecontext API for registering hooks, removing
112a layer of encapsulation.
113
114
115
116
117
1182. (Proposed) Strict boundaries events reading
119
120The idea behind this method is to provide exactly the events requested by the
121viewers to them, no more, no less.
122
6ea2aecb 123It uses the new API for process traceset suggested in the document
124process_traceset_strict_boundaries.txt.
125
126It also means that the lttvwindow API will have to deal with viewer's hooks.
127Those will not be allowed to add them directly in the context. They will give
128them to the lttvwindow API, along with the time interval or the position and
129number of events. The lttvwindow API will have to take care of adding and
130removing hooks for the different time intervals requested. That means that hooks
131insertion and removal will be done between each traceset processing based on
132the time intervals and event positions related to each hook. We must therefore
133provide a simple interface for hooks passing between the viewers and the main
318585ee 134window, make them easier to manage from the main window. A modification to the
135LttvHooks type solves this problem.
6ea2aecb 136
137
138Architecture
139
140Added to the lttvwindow API :
141
142
8646cedb 143void lttvwindow_events_request
144( MainWindow *main_win,
145 EventsRequest events_request);
6ea2aecb 146
8646cedb 147void lttvwindow_events_request_remove_all
148( MainWindow *main_win,
149 gpointer viewer);
6ea2aecb 150
6ea2aecb 151
8646cedb 152Internal functions :
6ea2aecb 153
154- lttvwindow_process_pending_requests
155
318585ee 156
8646cedb 157Events Requests Removal
318585ee 158
8646cedb 159A new API function will be necessary to let viewers remove all event requests
160they have made previously. By allowing this, no more out of bound requests will
161be serviced : a viewer that sees its time interval changed before the first
162servicing is completed can clear its previous events requests and make a new
163one for the new interval needed, considering the finished chunks as completed
164area.
318585ee 165
8646cedb 166It is also very useful for dealing with the viewer destruction case : the viewer
167just has to remove its events requests from the main window before it gets
168destroyed.
318585ee 169
318585ee 170
8646cedb 171Permitted GTK Events Between Chunks
318585ee 172
8646cedb 173All GTK Events will be enabled between chunks. This is due to the fact that the
174background processing and a high priority request are seen as the same case.
175While a background processing is in progress, the whole graphical interface must
176be enabled.
318585ee 177
8646cedb 178We needed to deal with the coherence of background processing and diverse GTK
179events anyway. This algorithm provides a generalized way to deal with any type
180of request and any GTK events.
318585ee 181
318585ee 182
8646cedb 183Background Computation Request
318585ee 184
8646cedb 185The types of background computation that can be requested by a viewer : state
186computation (main window scope) or viewer specific background computation.
318585ee 187
8646cedb 188A background computation request is asked via lttvwindow_events_request, with a
189priority field set with a low priority.
6ea2aecb 190
8646cedb 191If a lttvwindow_events_request_remove_all is done on the viewer pointer, it will
192not affect the state computation as no viewer pointer will have been passed in
193the initial request. This is the expected result. For the background processings
194that call viewer's hooks, they will be removed.
6ea2aecb 195
196
206ea1f4 197A New "Redraw" Button
198
199It will be used to redraw the viewers entirely. It is useful to restart the
200servicing after a "stop" action.
201
202A New "Continue" Button
203
204It will tell the viewers to send requests for damaged areas. It is useful to
205complete the servicing after a "stop" action.
206
207
6ea2aecb 208
65bc0600 209Tab change
210
211If a tab change occurs, we still want to do background processing.
212Events requests must be stocked in a list located in the same scope than the
213traceset context. Right now, this is tab scope. All functions called from the
214request servicing function must _not_ use the current_tab concept, as it may
215change. The idle function must the take a tab, and not the main window, as
216parameter.
217
218If a tab is removed, its associated idle events requests servicing function must
219also be removed.
220
4a97e95b 221It now looks a lot more useful to give a Tab* to the viewer instead of a
222MainWindow*, as all the information needed by the viewer is located at the tab
223level. It will diminish the dependance upon the current tab concept.
224
65bc0600 225
226
227Idle function (lttvwindow_process_pending_requests)
228
229The idle function must return FALSE to be removed from the idle functions when
230no more events requests are pending. Otherwise, it returns TRUE. It will service
231requests until there is no more request left.
232
233
234
235
8646cedb 236Implementation
6ea2aecb 237
6ea2aecb 238
8646cedb 239- Type LttvHooks
6ea2aecb 240
8646cedb 241see hook_prio.txt
69381fc7 242
8646cedb 243The viewers will just have to pass hooks to the main window through this type,
244using the hook.h interface to manipulate it. Then, the main window will add
245them and remove them from the context to deliver exactly the events requested by
246each viewer through process traceset.
69381fc7 247
248
8646cedb 249- lttvwindow_events_request
69381fc7 250
8646cedb 251It adds the an EventsRequest struct to the array of time requests
252pending and registers a pending request for the next g_idle if none is
253registered. The viewer can access this structure during the read as its
254hook_data. Only the stop_flag can be changed by the viewer through the
255event hooks.
69381fc7 256
257typedef LttvEventsRequestPrio guint;
258
259typedef struct _EventsRequest {
260 gpointer viewer_data;
261 gboolean servicing; /* service in progress: TRUE */
262 LttvEventsRequestPrio prio; /* Ev. Req. priority */
263 LttTime start_time; /* Unset : { 0, 0 } */
264 LttvTracesetContextPosition *start_position; /* Unset : num_traces = 0 */
265 gboolean stop_flag; /* Continue:TRUE Stop:FALSE */
266 LttTime end_time; /* Unset : { 0, 0 } */
267 guint num_events; /* Unset : G_MAXUINT */
268 LttvTracesetContextPosition *end_position; /* Unset : num_traces = 0 */
269 LttvHooks *before_traceset; /* Unset : NULL */
270 LttvHooks *before_trace; /* Unset : NULL */
271 LttvHooks *before_tracefile;/* Unset : NULL */
272 LttvHooks *event; /* Unset : NULL */
273 LttvHooksById *event_by_id; /* Unset : NULL */
274 LttvHooks *after_tracefile; /* Unset : NULL */
275 LttvHooks *after_trace; /* Unset : NULL */
276 LttvHooks *after_traceset; /* Unset : NULL */
277 LttvHooks *before_chunk; /* Unset : NULL */
278 LttvHooks *after_chunk /* Unset : NULL */
279} EventsRequest;
280
281
8646cedb 282
283- lttvwindow_events_request_remove_all
284
285It removes all the events requests from the pool that has their "viewer" field
286maching the viewer pointer given in argument.
287
288It calls the traceset/trace/tracefile end hooks for each request removed.
289
290
291- lttvwindow_process_pending_requests
292
293This internal function gets called by g_idle, taking care of the pending
294requests. It is responsible for concatenation of time intervals and position
295requests. It does it with the following algorithm organizing process traceset
296calls. Here is the detailed description of the way it works :
297
298
299
300- Revised Events Requests Servicing Algorithm (v2)
301
69381fc7 302The reads are splitted in chunks. After a chunk is over, we want to check if
303there is a GTK Event pending and execute it. It can add or remove events
304requests from the event requests list. If it happens, we want to start over
305the algorithm from the beginning.
306
307Two levels of priority exists. High priority and low priority. High prio
308requests are serviced first, even if lower priority requests has lower start
309time or position.
310
311
312Data structures necessary :
313
314List of requests added to context : list_in
315List of requests not added to context : list_out
316
317Initial state :
318
319list_in : empty
320list_out : many events requests
321
322
323A. While list_in !empty and list_out !empty and !GTK Event pending
324 1. If list_in is empty (need a seek)
325 1.1 Add requests to list_in
326 1.1.1 Find all time requests with the highest priority and lowest start
327 time in list_out (ltime)
328 1.1.2 Find all position requests with the highest priority and lowest
329 position in list_out (lpos)
330 1.1.3 If lpos.prio > ltime.prio
331 || (lpos.prio == ltime.prio && lpos.start time < ltime)
332 - Add lpos to list_in, remove them from list_out
333 1.1.4 Else, (lpos.prio < ltime.prio
334 ||(lpos.prio == ltime.prio && lpos.start time >= ltime))
335 - Add ltime to list_in, remove them from list_out
336 1.2 Seek
337 1.2.1 If first request in list_in is a time request
e6359327 338 - If first req in list_in start time != current time
339 - Seek to that time
69381fc7 340 1.2.2 Else, the first request in list_in is a position request
e6359327 341 - If first req in list_in pos != current pos
342 - If the position is the same than the saved state, restore state
343 - Else, seek to that position
69381fc7 344 1.3 Add hooks and call begin for all list_in members
345 1.3.1 If !servicing
346 - begin hooks called
347 - servicing = TRUE
348 1.3.2 call before_chunk
349 1.3.3 events hooks added
350 2. Else, list_in is not empty, we continue a read
351 2.1 For each req of list_out
352 - if req.start time == current context time
353 - Add to list_in, remove from list_out
354 - If !servicing
355 - Call begin
356 - servicing = TRUE
357 - Call before_chunk
358 - events hooks added
359 - if req.start position == current position
360 - Add to list_in, remove from list_out
361 - If !servicing
362 - Call begin
363 - servicing = TRUE
364 - Call before_chunk
365 - events hooks added
366
367 3. Find end criterions
368 3.1 End time
369 3.1.1 Find lowest end time in list_in
370 3.1.2 Find lowest start time in list_out (>= than current time*)
371 * To eliminate lower prio requests
372 3.1.3 Use lowest of both as end time
373 3.2 Number of events
374 3.2.1 Find lowest number of events in list_in
375 3.2.2 Use min(CHUNK_NUM_EVENTS, min num events in list_in) as num_events
376 3.3 End position
377 3.3.1 Find lowest end position in list_in
378 3.3.2 Find lowest start position in list_out (>= than current
379 position)
380 3.3.3 Use lowest of both as end position
381
382 4. Call process traceset middle
383 4.1 Call process traceset middle (Use end criterion found in 3)
384 * note : end criterion can also be viewer's hook returning TRUE
385 5. After process traceset middle
386 - if current context time > traceset.end time
387 - For each req in list_in
388 - Call end for req
389 - Remove events hooks for req
390 - remove req from list_in
391 5.1 For each req in list_in
392 - req.num -= count
393 - if req.num == 0
394 - Call end for req
395 - Remove events hooks for req
396 - remove req from list_in
397 - if current context time > req.end time
398 - Call end for req
399 - Remove events hooks for req
400 - remove req from list_in
401 - if req.end pos == current pos
402 - Call end for req
403 - Remove events hooks for req
404 - remove req from list_in
405 - if req.stop_flag == TRUE
406 - Call end for req
407 - Remove events hooks for req
408 - remove req from list_in
409 - if exists one events requests in list_out that has
410 higher priority and time != current time
411 - Use current position as start position for req
412 - Remove start time from req
413 - Call after_chunk for req
414 - Remove event hooks for req
415 - Put req back in list_out, remove from list_in
416 - Save current state into saved_state.
417
418B. When interrupted
419 1. for each request in list_in
420 1.1. Use current postition as start position
421 1.2. Remove start time
422 1.3. Call after_chunk
423 1.4. Remove event hooks
424 1.5. Put it back in list_out
425 2. Save current state into saved_state.
426 2.1 Free old saved state.
427 2.2 save current state.
428
429
430
431
432
433Notes :
434End criterions for process traceset middle :
435If the criterion is reached, event is out of boundaries and we return.
436Current time >= End time
437Event count > Number of events
438Current position >= End position
439Last hook list called returned TRUE
440
441The >= for position is necessary to make ensure consistency between start time
442requests and positions requests that happens to be at the exact same start time
443and position.
444
445We only keep one saved state in memory. If, for example, a low priority
446servicing is interrupted, a high priority is serviced, then the low priority
447will use the saved state to start back where it was instead of seeking to the
448time. In the very specific case where a low priority servicing is interrupted,
449and then a high priority servicing on top of it is also interrupted, well, the
450low priority will loose its state and will have to seek back. It should not
451occur often. The solution to it would be to save one state per priority.
452
453
8646cedb 454
455
456
457
458Weaknesses
459
4bcbbd42 460- There is a possibility that we must use seek if more than one interruption
461 occurs, i.e. low priority interrupted by addition of high priority, and then
462 high priority interrupted. The seek will be necessary for the low priority.
463 It could be a good idea to keep one saved_state per priority ?
8646cedb 464
465
466Strengths
467
468- Removes the need for filtering of information supplied to the viewers.
469
470- Viewers have a better control on their data input.
471
472- Solves all the weaknesses idenfied in the actual boundaryless traceset
473reading.
474
475- Background processing available.
476
This page took 0.040923 seconds and 4 git commands to generate.