| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 Michel Dagenais |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | |
| 20 | /* This file does not even compile yet. It is a starting point to compute |
| 21 | some values in the background. This is why process_trace was split in |
| 22 | three. However, process_trace_middle as it is currently is would not work. |
| 23 | It needs to reinitialize its trace event positions each time since, |
| 24 | in between background calls to process middle, other foreground calls to |
| 25 | process_middle can happen. */ |
| 26 | |
| 27 | #include <lttvwindow/idleprocesstrace.h> |
| 28 | |
| 29 | /* The calling function has checked that the needed information has not |
| 30 | been or is not being computed yet, has prepared the trace, and now all |
| 31 | that is needed is to queue it for processing. |
| 32 | |
| 33 | CHECK remove the work_queue global variable, have an automatic adjustment |
| 34 | of the number of events to process by iteration. */ |
| 35 | |
| 36 | static gboolean inserted = false; |
| 37 | |
| 38 | static GList *work_queue = NULL; |
| 39 | |
| 40 | typedef struct _WorkPiece WorkPiece; |
| 41 | |
| 42 | struct _WorkPiece { |
| 43 | LttvTracesetContext *self; |
| 44 | LttTime end; |
| 45 | unsigned nb_events; |
| 46 | LttvHook f; |
| 47 | void *hook_data; |
| 48 | unsigned nb_done; |
| 49 | } |
| 50 | |
| 51 | guint lttv_process_traceset_piece(gpointer data) |
| 52 | { |
| 53 | GList *first = g_list_first(work_queue); |
| 54 | |
| 55 | guint nb_done, nb_asked; |
| 56 | |
| 57 | if(first == NULL) { |
| 58 | inserted = false; |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | WorkPiece *work_piece = (WorkPiece *)first->data; |
| 63 | nb_asked = work_piece->nb_events - work_piece->nb_done; |
| 64 | nb_asked = min(nb_asked, 10000); |
| 65 | nb_done = lttv_process_trace_middle(work_piece->self,work_piece->end, |
| 66 | nb_asked); |
| 67 | work_piece->nb_done += nb_done; |
| 68 | if(nb_done < nb_asked) { |
| 69 | lttv_process_trace_end(work_piece->self); |
| 70 | work_queue = g_list_delete(work_queue, first); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | |
| 75 | void lttv_process_traceset_when_idle(LttvTracesetContext *self, LttTime end, |
| 76 | unsigned nb_events, LttvHook f, void *hook_data) |
| 77 | { |
| 78 | WorkPiece *work_piece = g_new(WorkPiece); |
| 79 | work_piece->self = self; |
| 80 | work_piece->end = end; |
| 81 | work_piece->nb_events = nb_events; |
| 82 | work_piece->f = f; |
| 83 | work_piece->hook_data = hook_data; |
| 84 | eork_piece->nb_done = 0; |
| 85 | |
| 86 | lttv_process_traceset_begin(self); |
| 87 | work_queue = g_list_append(work_queue, work_piece); |
| 88 | if(!inserted) g_idle_add(lttv_process_traceset_piece, work_queue); |
| 89 | } |
| 90 | |
| 91 | |