| 1 | #ifndef STATS_H |
| 2 | #define STATS_H |
| 3 | |
| 4 | #include <glib.h> |
| 5 | #include <lttv/state.h> |
| 6 | |
| 7 | /* The statistics are for a complete time interval. These structures differ |
| 8 | from the system state since they relate to static components of the |
| 9 | system (all processes which existed instead of just the currently |
| 10 | existing processes). |
| 11 | |
| 12 | The basic attributes tree to gather for several different execution modes |
| 13 | (e.g., user mode, syscall, irq), thereafter called the "events tree", |
| 14 | contains the following attributes: the number of events of each type, |
| 15 | the total number of events, the number of bytes written, the time spent |
| 16 | executing, waiting for a resource, waiting for a cpu, and possibly many |
| 17 | others. The name "facility-event_type" below is to be replaced |
| 18 | by specific event types (e.g., core-schedchange, code-syscall_entry...). |
| 19 | |
| 20 | event_types/ |
| 21 | "facility-event_type" |
| 22 | events_count |
| 23 | cpu_time |
| 24 | elapsed_time |
| 25 | wait_time |
| 26 | bytes_written |
| 27 | packets_sent |
| 28 | ... |
| 29 | |
| 30 | The events for several different execution modes are joined together to |
| 31 | form the "execution modes tree". The name "execution mode" is to be replaced |
| 32 | by "system call", "trap", "irq", "user mode" or "kernel thread". |
| 33 | The name "submode" is to be replaced by the specific system call, trap or |
| 34 | irq name. The "submode" is an empty string if none is applicable, which is |
| 35 | the case for "user mode" and "kernel thread". |
| 36 | |
| 37 | An "events tree" for each "execution mode" contains the sum for all its |
| 38 | different submodes. An "events tree" in the "execution modes tree" contains |
| 39 | the sum for all its different execution modes. |
| 40 | |
| 41 | mode_types/ |
| 42 | "execution mode"/ |
| 43 | submodes/ |
| 44 | "submode"/ |
| 45 | Events Tree |
| 46 | events/ |
| 47 | Event Tree |
| 48 | events/ |
| 49 | Events Tree |
| 50 | |
| 51 | Each trace set contains an "execution modes tree". While the traces |
| 52 | come from possibly different systems, which may differ in their system |
| 53 | calls..., most of the system calls will have the same name, even if their |
| 54 | actual internal numeric id differs. Categories such as cpu id and process |
| 55 | id are not kept since these are specific to each system. When several |
| 56 | traces are taken from the same system, these categories may make sense and |
| 57 | could eventually be considered. |
| 58 | |
| 59 | Each trace contains a global "execution modes tree", one for each |
| 60 | cpu and process, and one for each process/cpu combination. The name |
| 61 | "cpu number" stands for the cpu identifier, and "process_id-start_time" |
| 62 | is a unique process identifier composed of the process id |
| 63 | (unique at any given time but which may be reused over time) concatenated |
| 64 | with the process start time. |
| 65 | |
| 66 | modes/ |
| 67 | Execution Modes Tree |
| 68 | cpu/ |
| 69 | "cpu number"/ |
| 70 | Execution Modes Tree |
| 71 | processes/ |
| 72 | "process_id-start_time"/ |
| 73 | exec_file_name |
| 74 | parent |
| 75 | start_time |
| 76 | end_time |
| 77 | modes/ |
| 78 | Execution Modes Tree |
| 79 | cpu/ |
| 80 | "cpu number"/ |
| 81 | Execution Modes Tree |
| 82 | |
| 83 | All the events and derived values (cpu, elapsed and wait time) are |
| 84 | added during the trace analysis in the relevant |
| 85 | trace / processes / * / cpu / * / mode_types / * /submodes / * |
| 86 | "events tree". To achieve this efficiently, each tracefile context |
| 87 | contains a pointer to the current relevant "events tree" and "event_types" |
| 88 | tree within it. |
| 89 | |
| 90 | Once all the events are processed, the total number of events is computed |
| 91 | within each trace / processes / * / cpu / * / mode_types / * / submodes / *. |
| 92 | Then, the "events tree" are summed for all submodes within each mode type |
| 93 | and for all mode types within a processes / * / cpu / * |
| 94 | "execution modes tree". |
| 95 | |
| 96 | Finally, the "execution modes trees" for all cpu within a process, |
| 97 | for all processes, and for all traces are computed. Separately, |
| 98 | the "execution modes tree" for each cpu but for all processes within a |
| 99 | trace are summed in the trace / cpu / * subtrees. |
| 100 | |
| 101 | */ |
| 102 | |
| 103 | |
| 104 | /* The various statistics branch names are GQuarks. They are pre-computed for |
| 105 | easy and efficient access */ |
| 106 | |
| 107 | extern GQuark |
| 108 | LTTV_STATS_PROCESS_UNKNOWN, |
| 109 | LTTV_STATS_PROCESSES, |
| 110 | LTTV_STATS_CPU, |
| 111 | LTTV_STATS_MODE_TYPES, |
| 112 | LTTV_STATS_SUBMODES, |
| 113 | LTTV_STATS_EVENT_TYPES, |
| 114 | LTTV_STATS_CPU_TIME, |
| 115 | LTTV_STATS_ELAPSED_TIME, |
| 116 | LTTV_STATS_EVENTS, |
| 117 | LTTV_STATS_EVENTS_COUNT, |
| 118 | LTTV_STATS_BEFORE_HOOKS, |
| 119 | LTTV_STATS_AFTER_HOOKS; |
| 120 | |
| 121 | |
| 122 | typedef struct _LttvTracesetStats LttvTracesetStats; |
| 123 | typedef struct _LttvTracesetStatsClass LttvTracesetStatsClass; |
| 124 | |
| 125 | typedef struct _LttvTraceStats LttvTraceStats; |
| 126 | typedef struct _LttvTraceStatsClass LttvTraceStatsClass; |
| 127 | |
| 128 | typedef struct _LttvTracefileStats LttvTracefileStats; |
| 129 | typedef struct _LttvTracefileStatsClass LttvTracefileStatsClass; |
| 130 | |
| 131 | gboolean lttv_stats_add_event_hooks(LttvTracesetStats *self); |
| 132 | |
| 133 | gboolean lttv_stats_remove_event_hooks(LttvTracesetStats *self); |
| 134 | |
| 135 | |
| 136 | /* The LttvTracesetStats, LttvTraceStats and LttvTracefileStats types |
| 137 | inherit from the corresponding State objects defined in state.h.. */ |
| 138 | |
| 139 | #define LTTV_TRACESET_STATS_TYPE (lttv_traceset_stats_get_type ()) |
| 140 | #define LTTV_TRACESET_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATS_TYPE, LttvTracesetStats)) |
| 141 | #define LTTV_TRACESET_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATS_TYPE, LttvTracesetStatsClass)) |
| 142 | #define LTTV_IS_TRACESET_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_STATS_TYPE)) |
| 143 | #define LTTV_IS_TRACESET_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_STATS_TYPE)) |
| 144 | #define LTTV_TRACESET_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATS_TYPE, LttvTracesetStatsClass)) |
| 145 | |
| 146 | struct _LttvTracesetStats { |
| 147 | LttvTracesetState parent; |
| 148 | |
| 149 | LttvAttribute *stats; |
| 150 | }; |
| 151 | |
| 152 | struct _LttvTracesetStatsClass { |
| 153 | LttvTracesetStateClass parent; |
| 154 | }; |
| 155 | |
| 156 | GType lttv_traceset_stats_get_type (void); |
| 157 | |
| 158 | |
| 159 | #define LTTV_TRACE_STATS_TYPE (lttv_trace_stats_get_type ()) |
| 160 | #define LTTV_TRACE_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_STATS_TYPE, LttvTraceStats)) |
| 161 | #define LTTV_TRACE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_STATS_TYPE, LttvTraceStatsClass)) |
| 162 | #define LTTV_IS_TRACE_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_STATS_TYPE)) |
| 163 | #define LTTV_IS_TRACE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_STATS_TYPE)) |
| 164 | #define LTTV_TRACE_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATS_TYPE, LttvTraceStatsClass)) |
| 165 | |
| 166 | struct _LttvTraceStats { |
| 167 | LttvTraceState parent; |
| 168 | |
| 169 | LttvAttribute *stats; |
| 170 | }; |
| 171 | |
| 172 | struct _LttvTraceStatsClass { |
| 173 | LttvTraceStateClass parent; |
| 174 | }; |
| 175 | |
| 176 | GType lttv_trace_stats_get_type (void); |
| 177 | |
| 178 | |
| 179 | #define LTTV_TRACEFILE_STATS_TYPE (lttv_tracefile_stats_get_type ()) |
| 180 | #define LTTV_TRACEFILE_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStats)) |
| 181 | #define LTTV_TRACEFILE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStatsClass)) |
| 182 | #define LTTV_IS_TRACEFILE_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_STATS_TYPE)) |
| 183 | #define LTTV_IS_TRACEFILE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_STATS_TYPE)) |
| 184 | #define LTTV_TRACEFILE_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStatsClass)) |
| 185 | |
| 186 | struct _LttvTracefileStats { |
| 187 | LttvTracefileState parent; |
| 188 | |
| 189 | LttvAttribute *stats; |
| 190 | LttvAttribute *current_events_tree; |
| 191 | LttvAttribute *current_event_types_tree; |
| 192 | }; |
| 193 | |
| 194 | struct _LttvTracefileStatsClass { |
| 195 | LttvTracefileStateClass parent; |
| 196 | }; |
| 197 | |
| 198 | GType lttv_tracefile_stats_get_type (void); |
| 199 | |
| 200 | |
| 201 | #endif // STATS_H |