1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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;
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.
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,
23 #include <lttv/processTrace.h>
25 /* The operating system state, kept during the trace analysis,
26 contains a subset of the real operating system state,
27 sufficient for the analysis, and possibly organized quite differently.
29 The state information is added to LttvTracesetContext, LttvTraceContext
30 and LttvTracefileContext objects, used by processTrace, through
31 subtyping. The context objects already reflect the multiple tracefiles
32 (one per cpu) per trace and multiple traces per trace set. The state
33 objects defined here simply add fields to the relevant context objects.
35 There is no traceset specific state yet. It may eventually contains such
36 things as clock differences over time.
38 The trace state currently consists in a process table.
40 The tracefile level state relates to the associated cpu. It contains the
41 position of the current event in the tracefile (since the state depends on
42 which events have been processed) and a pointer to the current process,
43 in the process table, being run on that cpu.
45 For each process in the process table, various informations such as exec
46 file name, pid, ppid and creation time are stored. Each process state also
47 contains an execution mode stack (e.g. irq within system call, called
50 typedef struct _LttvTracesetState LttvTracesetState
;
51 typedef struct _LttvTracesetStateClass LttvTracesetStateClass
;
53 typedef struct _LttvTraceState LttvTraceState
;
54 typedef struct _LttvTraceStateClass LttvTraceStateClass
;
56 typedef struct _LttvTracefileState LttvTracefileState
;
57 typedef struct _LttvTracefileStateClass LttvTracefileStateClass
;
59 void lttv_state_add_event_hooks(LttvTracesetState
*self
);
61 void lttv_state_remove_event_hooks(LttvTracesetState
*self
);
63 void lttv_state_save_add_event_hooks(LttvTracesetState
*self
);
65 void lttv_state_save_remove_event_hooks(LttvTracesetState
*self
);
67 void lttv_state_traceset_seek_time_closest(LttvTracesetState
*self
, LttTime t
);
69 /* The LttvProcessState structure defines the current state for each process.
70 A process can make system calls (in some rare cases nested) and receive
71 interrupts/faults. For instance, a process may issue a system call,
72 generate a page fault while reading an argument from user space, and
73 get caught by an interrupt. To represent these nested states, an
74 execution mode stack is maintained. The stack bottom is normal user mode
75 and the top of stack is the current execution mode.
77 The execution mode stack tells about the process status, execution mode and
78 submode (interrupt, system call or IRQ number). All these could be
79 defined as enumerations but may need extensions (e.g. new process state).
80 GQuark are thus used. They are as easy to manipulate as integers but have
81 a string associated, just like enumerations.
83 The execution mode is one of "user mode", "kernel thread", "system call",
84 "interrupt request", "fault". */
86 typedef GQuark LttvExecutionMode
;
88 extern LttvExecutionMode
93 LTTV_STATE_MODE_UNKNOWN
;
96 /* The submode number depends on the execution mode. For user mode or kernel
97 thread, which are the normal mode (execution mode stack bottom),
98 it is set to "none". For interrupt requests, faults and system calls,
99 it is set respectively to the interrupt name (e.g. "timer"), fault name
100 (e.g. "page fault"), and system call name (e.g. "select"). */
102 typedef GQuark LttvExecutionSubmode
;
104 extern LttvExecutionSubmode
105 LTTV_STATE_SUBMODE_NONE
,
106 LTTV_STATE_SUBMODE_UNKNOWN
;
108 /* The process status is one of "running", "wait-cpu" (runnable), or "wait-*"
109 where "*" describes the resource waited for (e.g. timer, process,
112 typedef GQuark LttvProcessStatus
;
114 extern LttvProcessStatus
116 LTTV_STATE_WAIT_FORK
,
123 typedef struct _LttvExecutionState
{
125 LttvExecutionSubmode n
;
129 } LttvExecutionState
;
132 typedef struct _LttvProcessState
{
135 LttTime creation_time
;
138 GArray
*execution_stack
; /* Array of LttvExecutionState */
139 LttvExecutionState
*state
; /* Top of interrupt stack */
140 /* opened file descriptors, address map?... */
143 //FIXME : find by pid and birth time : both are necessary to be unique
144 LttvProcessState
*lttv_state_find_process(LttvTracefileState
*tfs
, guint pid
);
145 LttvProcessState
*lttv_state_find_process_from_trace(LttvTraceState
*ts
, guint pid
);
148 /* The LttvTracesetState, LttvTraceState and LttvTracefileState types
149 inherit from the corresponding Context objects defined in processTrace. */
151 #define LTTV_TRACESET_STATE_TYPE (lttv_traceset_state_get_type ())
152 #define LTTV_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATE_TYPE, LttvTracesetState))
153 #define LTTV_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass))
154 #define LTTV_IS_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_STATE_TYPE))
155 #define LTTV_IS_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_STATE_TYPE))
156 #define LTTV_TRACESET_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass))
158 struct _LttvTracesetState
{
159 LttvTracesetContext parent
;
162 struct _LttvTracesetStateClass
{
163 LttvTracesetContextClass parent
;
166 GType
lttv_traceset_state_get_type (void);
169 #define LTTV_TRACE_STATE_TYPE (lttv_trace_state_get_type ())
170 #define LTTV_TRACE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_STATE_TYPE, LttvTraceState))
171 #define LTTV_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass))
172 #define LTTV_IS_TRACE_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_STATE_TYPE))
173 #define LTTV_IS_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_STATE_TYPE))
174 #define LTTV_TRACE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass))
176 struct _LttvTraceState
{
177 LttvTraceContext parent
;
179 GHashTable
*processes
; /* LttvProcessState objects indexed by pid */
180 guint nb_event
, save_interval
;
181 /* Block/char devices, locks, memory pages... */
182 GQuark
*eventtype_names
;
183 GQuark
*syscall_names
;
186 gboolean recompute_state_in_seek
;
187 gboolean saved_state_ready
;
188 gboolean saved_state_available
;
191 struct _LttvTraceStateClass
{
192 LttvTraceContextClass parent
;
194 void (*state_save
) (LttvTraceState
*self
, LttvAttribute
*container
);
195 void (*state_restore
) (LttvTraceState
*self
, LttvAttribute
*container
);
196 void (*state_saved_free
) (LttvTraceState
*self
, LttvAttribute
*container
);
199 GType
lttv_trace_state_get_type (void);
201 void lttv_state_save(LttvTraceState
*self
, LttvAttribute
*container
);
203 void lttv_state_restore(LttvTraceState
*self
, LttvAttribute
*container
);
205 void lttv_state_saved_state_free(LttvTraceState
*self
,
206 LttvAttribute
*container
);
209 #define LTTV_TRACEFILE_STATE_TYPE (lttv_tracefile_state_get_type ())
210 #define LTTV_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileState))
211 #define LTTV_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass))
212 #define LTTV_IS_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_STATE_TYPE))
213 #define LTTV_IS_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_STATE_TYPE))
214 #define LTTV_TRACEFILE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass))
216 struct _LttvTracefileState
{
217 LttvTracefileContext parent
;
219 LttvProcessState
*process
;
221 guint saved_position
;
224 struct _LttvTracefileStateClass
{
225 LttvTracefileContextClass parent
;
228 GType
lttv_tracefile_state_get_type (void);