Massive debugging in lttv filter core:
[lttv.git] / ltt / branches / poly / lttv / modules / text / textFilter.c
CommitLineData
a58509ee 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
91ad3f0a 19/*
20 * The text filter facility will prompt for user filter option
21 * and transmit them to the lttv core
22 */
a58509ee 23
24#include <lttv/lttv.h>
25#include <lttv/option.h>
26#include <lttv/module.h>
27#include <lttv/hook.h>
28#include <lttv/attribute.h>
29#include <lttv/iattribute.h>
30#include <lttv/stats.h>
31#include <lttv/filter.h>
32#include <ltt/ltt.h>
33#include <ltt/event.h>
34#include <ltt/type.h>
35#include <ltt/trace.h>
36#include <ltt/facility.h>
37#include <stdio.h>
38
39/* Insert the hooks before and after each trace and tracefile, and for each
40 event. Print a global header. */
41
91ad3f0a 42/*
43 * YET TO BE ANSWERED !
44 * - why does this module need dependency with batchAnalysis ?
45 */
46
1601b365 47/*
48 * TODO
49 * - specify wich hook function will be used to call the core filter
50 */
51
91ad3f0a 52static char
a58509ee 53 *a_file_name = NULL,
91ad3f0a 54 *a_string = NULL;
55
a58509ee 56static LttvHooks
57 *before_traceset,
58 *event_hook;
59
60static FILE *a_file;
61
62/**
91ad3f0a 63 * filters the file input from user
a58509ee 64 * @param hook_data the hook data
91ad3f0a 65 * @return success/failure of operation
a58509ee 66 */
91ad3f0a 67void filter_analyze_file(void *hook_data) {
68
69 g_print("textFilter::filter_analyze_file\n");
70
73050a5f 71 LttvAttributeValue value;
72
73 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
74
91ad3f0a 75 /*
a58509ee 76 * User may specify filtering options through static file
77 * and/or command line string. From these sources, an
78 * option string is rebuilded and sent to the filter core
79 */
73050a5f 80 GString* a_file_content = g_string_new("");
81 a_file = fopen(a_file_name, "r");
91ad3f0a 82 if(a_file == NULL) {
83 g_warning("file %s does not exist", a_file_name);
84 return;
85 }
86
1601b365 87 char* line = NULL;
88 size_t len = 0;
cec3d7b0 89
1601b365 90 while(!feof(a_file)) {
73050a5f 91 len = getline(&line,&len,a_file);
92 g_string_append(a_file_content,line);
91ad3f0a 93 }
73050a5f 94 free(line);
91ad3f0a 95
73050a5f 96 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
97 LTTV_POINTER, &value));
98
99 g_debug("Filter file string b: %s",((GString*)*(value.v_pointer))->str);
100 if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
101 g_string_append((GString*)*(value.v_pointer),a_file_content->str);
102 g_debug("Filter file string a: %s",((GString*)*(value.v_pointer))->str);
103 // lttv_filter_append_expression(lttvfilter_t,a_filter_string->str);
91ad3f0a 104 fclose(a_file);
105}
106
107/**
108 * filters the string input from user
109 * @param hook_data the hook data
110 * @return success/failure of operation
111 */
112void filter_analyze_string(void *hook_data) {
113
114 g_print("textFilter::filter_analyze_string\n");
18d1226f 115
73050a5f 116 LttvAttributeValue value;
117
118 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
119
91ad3f0a 120 /*
121 * User may specify filtering options through static file
122 * and/or command line string. From these sources, an
123 * option string is rebuilded and sent to the filter core
124 */
73050a5f 125/* if(a_filter_string==NULL) {
1601b365 126 a_filter_string = g_string_new("");
91ad3f0a 127 g_string_append(a_filter_string,a_string);
1601b365 128 }
129 else {
cec3d7b0 130 g_string_append(a_filter_string,"&");
1601b365 131 g_string_append(a_filter_string,a_string);
132 }
73050a5f 133*/
cec3d7b0 134// lttv_filter_append_expression(lttvfilter_t,a_string);
73050a5f 135 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
136 LTTV_POINTER, &value));
cec3d7b0 137
a58509ee 138
73050a5f 139 g_debug("Filter string string b: %s",((GString*)*(value.v_pointer))->str);
140 if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
141 g_string_append((GString*)*(value.v_pointer),a_string);
142 g_debug("Filter string string a: %s",((GString*)*(value.v_pointer))->str);
a58509ee 143}
144
145/**
146 * initialize the new module
147 */
148static void init() {
149
91ad3f0a 150 g_print("textFilter::init()\n"); /* debug */
151
a58509ee 152 LttvAttributeValue value;
153
154 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
155
73050a5f 156 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
157 LTTV_POINTER, &value));
158
159 *(value.v_pointer) = g_string_new("");
160
a58509ee 161 g_info("Init textFilter.c");
cec3d7b0 162
91ad3f0a 163 a_string = NULL;
73050a5f 164 lttv_option_add("expression", 'e',
a58509ee 165 "filters a string issued by the user on the command line",
166 "string",
91ad3f0a 167 LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL);
1a7fa682 168 // add function to call for option
169
a58509ee 170 a_file_name = NULL;
171 lttv_option_add("filename", 'f',
172 "browse the filter options contained in specified file",
173 "file name",
91ad3f0a 174 LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL);
a58509ee 175
a58509ee 176}
177
178/**
179 * Destroy the current module
180 */
181static void destroy() {
182 g_info("Destroy textFilter");
183
73050a5f 184 lttv_option_remove("expression");
a58509ee 185
186 lttv_option_remove("filename");
187
73050a5f 188 LttvAttributeValue value;
189
190 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
a58509ee 191
73050a5f 192 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
193 LTTV_POINTER, &value));
194
195 g_string_free((GString*)*(value.v_pointer),TRUE);
a58509ee 196
197}
198
199
200LTTV_MODULE("textFilter", "Filters traces", \
201 "Filter the trace following commands issued by user input", \
73050a5f 202 init, destroy, "option")
a58509ee 203
This page took 0.031512 seconds and 4 git commands to generate.