update
[lttv.git] / ltt / branches / poly / lttv / modules / text / precomputeState.c
CommitLineData
f204781b 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 * 2005 Mathieu Desnoyers
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
17 * MA 02111-1307, USA.
18 */
19
20/* The text dump facility needs to print headers before the trace set and
21 before each trace, to print each event, and to print statistics
22 after each trace. */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <lttv/lttv.h>
29#include <lttv/option.h>
30#include <lttv/module.h>
31#include <lttv/hook.h>
32#include <lttv/attribute.h>
33#include <lttv/iattribute.h>
34#include <lttv/stats.h>
35#include <lttv/filter.h>
36#include <lttv/print.h>
37#include <ltt/ltt.h>
38#include <ltt/event.h>
39#include <ltt/type.h>
40#include <ltt/trace.h>
41#include <ltt/facility.h>
42#include <stdio.h>
43
44static gboolean
45 a_field_names,
46 a_state,
47 a_cpu_stats,
48 a_process_stats;
49
50static char
51 *a_file_name = NULL;
52
53static LttvHooks
54 *before_traceset,
55 *after_traceset,
56 *before_trace,
57 *event_hook;
58
59
60/* Insert the hooks before and after each trace and tracefile, and for each
61 event. Print a global header. */
62
63static FILE *a_file;
64
65static GString *a_string;
66
67static gboolean write_traceset_header(void *hook_data, void *call_data)
68{
69 LttvTracesetContext *tc = (LttvTracesetContext *)call_data;
70
71 g_info("TextDump traceset header");
72
73 if(a_file_name == NULL) a_file = stdout;
74 else a_file = fopen(a_file_name, "w");
75
76 if(a_file == NULL) g_error("cannot open file %s", a_file_name);
77
78 /* Print the trace set header */
79 fprintf(a_file,"Trace set contains %d traces\n\n",
80 lttv_traceset_number(tc->ts));
81
82 return FALSE;
83}
84
85
86static gboolean write_traceset_footer(void *hook_data, void *call_data)
87{
88 LttvTracesetContext *tc = (LttvTracesetContext *)call_data;
89
90 g_info("TextDump traceset footer");
91
92 fprintf(a_file,"End trace set\n\n");
93
94 if(LTTV_IS_TRACESET_STATS(tc)) {
95 lttv_stats_sum_traceset((LttvTracesetStats *)tc);
96 print_stats(a_file, (LttvTracesetStats *)tc);
97 }
98
99 if(a_file_name != NULL) fclose(a_file);
100
101 return FALSE;
102}
103
104
105static gboolean write_trace_header(void *hook_data, void *call_data)
106{
107 LttvTraceContext *tc = (LttvTraceContext *)call_data;
108#if 0 //FIXME
109 LttSystemDescription *system = ltt_trace_system_description(tc->t);
110
111 fprintf(a_file," Trace from %s in %s\n%s\n\n",
112 ltt_trace_system_description_node_name(system),
113 ltt_trace_system_description_domain_name(system),
114 ltt_trace_system_description_description(system));
115#endif //0
116 return FALSE;
117}
118
119
120static int for_each_event(void *hook_data, void *call_data)
121{
122 guint *event_count = (guint*)hook_data;
123
124 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
125
126 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
127
128 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
129
130 LttEvent *e;
131
132 LttvAttributeValue value_filter;
133
134 /* Only save at LTTV_STATE_SAVE_INTERVAL */
135 if(likely((*event_count)++ < LTTV_STATE_SAVE_INTERVAL))
136 return FALSE;
137 else
138 *event_count = 0;
139
140 guint cpu = tfs->cpu;
141 LttvTraceState *ts = (LttvTraceState*)tfc->t_context;
142 LttvProcessState *process = ts->running_process[cpu];
143
144 e = ltt_tracefile_get_event(tfc->tf);
145
146 lttv_state_write(ts, tfs->parent.timestamp, a_file);
147
148 return FALSE;
149}
150
151
152static void init()
153{
154 LttvAttributeValue value;
155
156 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
157
158 g_info("Init textDump.c");
159
160 a_string = g_string_new("");
161
162 a_file_name = NULL;
163 lttv_option_add("output", 'o',
164 "output file where the saved states are to be written",
165 "file name",
166 LTTV_OPT_STRING, &a_file_name, NULL, NULL);
167
168 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
169 LTTV_POINTER, &value));
170 g_assert((event_hook = *(value.v_pointer)) != NULL);
171 lttv_hooks_add(event_hook, write_event_content, NULL, LTTV_PRIO_DEFAULT);
172
173 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
174 LTTV_POINTER, &value));
175 g_assert((before_trace = *(value.v_pointer)) != NULL);
176 lttv_hooks_add(before_trace, write_trace_header, NULL, LTTV_PRIO_DEFAULT);
177
178 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
179 LTTV_POINTER, &value));
180 g_assert((before_traceset = *(value.v_pointer)) != NULL);
181 lttv_hooks_add(before_traceset, write_traceset_header, NULL,
182 LTTV_PRIO_DEFAULT);
183
184 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
185 LTTV_POINTER, &value));
186 g_assert((after_traceset = *(value.v_pointer)) != NULL);
187 lttv_hooks_add(after_traceset, write_traceset_footer, NULL,
188 LTTV_PRIO_DEFAULT);
189}
190
191static void destroy()
192{
193 g_info("Destroy textDump");
194
195 lttv_option_remove("output");
196
197 g_string_free(a_string, TRUE);
198
199 lttv_hooks_remove_data(event_hook, for_each_event, NULL);
200
201 lttv_hooks_remove_data(before_trace, write_trace_header, NULL);
202
203 lttv_hooks_remove_data(before_trace, write_traceset_header, NULL);
204
205 lttv_hooks_remove_data(before_trace, write_traceset_footer, NULL);
206}
207
208
209LTTV_MODULE("textDump", "Print events in a file", \
210 "Produce a detailed text printout of a trace", \
211 init, destroy, "stats", "batchAnalysis", "option", "print")
212
This page took 0.029798 seconds and 4 git commands to generate.