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,
20 * The text filter facility will prompt for user filter option
21 * and transmit them to the lttv core
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>
33 #include <ltt/event.h>
35 #include <ltt/trace.h>
36 #include <ltt/facility.h>
39 /* Insert the hooks before and after each trace and tracefile, and for each
40 event. Print a global header. */
43 * YET TO BE ANSWERED !
44 * - why does this module need dependency with batchAnalysis ?
49 * - specify wich hook function will be used to call the core filter
61 * filters the file input from user
62 * @param hook_data the hook data
63 * @return success/failure of operation
65 void filter_analyze_file(void *hook_data
) {
67 g_print("textFilter::filter_analyze_file\n");
69 LttvAttributeValue value
;
71 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
74 * User may specify filtering options through static file
75 * and/or command line string. From these sources, an
76 * option string is rebuilded and sent to the filter core
80 * GString* a_file_content = g_string_new("");
81 a_file = fopen(a_file_name, "r");
83 g_warning("file %s does not exist", a_file_name);
90 while(!feof(a_file)) {
91 len = getline(&line,&len,a_file);
92 g_string_append(a_file_content,line);
99 if(!g_file_test(a_file_name
,G_FILE_TEST_EXISTS
)) {
100 g_warning("file %s does not exist", a_file_name
);
104 char* a_file_content
= NULL
;
106 g_file_get_contents(a_file_name
,&a_file_content
,NULL
,NULL
);
108 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
109 LTTV_POINTER
, &value
));
111 if(((GString
*)*(value
.v_pointer
))->len
!= 0) g_string_append_c((GString
*)*(value
.v_pointer
),'&');
112 g_string_append_c((GString
*)*(value
.v_pointer
),'(');
113 g_string_append((GString
*)*(value
.v_pointer
),a_file_content
);
114 g_string_append_c((GString
*)*(value
.v_pointer
),')');
119 * filters the string input from user
120 * @param hook_data the hook data
121 * @return success/failure of operation
123 void filter_analyze_string(void *hook_data
) {
125 g_print("textFilter::filter_analyze_string\n");
127 LttvAttributeValue value
;
129 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
132 * User may specify filtering options through static file
133 * and/or command line string. From these sources, an
134 * option string is rebuilded and sent to the filter core
136 /* if(a_filter_string==NULL) {
137 a_filter_string = g_string_new("");
138 g_string_append(a_filter_string,a_string);
141 g_string_append(a_filter_string,"&");
142 g_string_append(a_filter_string,a_string);
146 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
147 LTTV_POINTER
, &value
));
149 if(((GString
*)*(value
.v_pointer
))->len
!= 0) g_string_append_c((GString
*)*(value
.v_pointer
),'&');
150 g_string_append_c((GString
*)*(value
.v_pointer
),'(');
151 g_string_append((GString
*)*(value
.v_pointer
),a_string
);
152 g_string_append_c((GString
*)*(value
.v_pointer
),')');
154 // LttvFilter* filter = lttv_filter_new();
155 // lttv_filter_append_expression(filter,a_string);
159 * initialize the new module
163 g_print("textFilter::init()\n"); /* debug */
165 LttvAttributeValue value
;
167 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
169 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
170 LTTV_POINTER
, &value
));
172 *(value
.v_pointer
) = g_string_new("");
174 g_info("Init textFilter.c");
177 lttv_option_add("expression", 'e',
178 "filters a string issued by the user on the command line",
180 LTTV_OPT_STRING
, &a_string
, filter_analyze_string
, NULL
);
181 // add function to call for option
184 lttv_option_add("filename", 'f',
185 "browse the filter options contained in specified file",
187 LTTV_OPT_STRING
, &a_file_name
, filter_analyze_file
, NULL
);
192 * Destroy the current module
194 static void destroy() {
195 g_info("Destroy textFilter");
197 lttv_option_remove("expression");
199 lttv_option_remove("filename");
201 LttvAttributeValue value
;
203 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
205 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
206 LTTV_POINTER
, &value
));
208 g_string_free((GString
*)*(value
.v_pointer
),TRUE
);
213 LTTV_MODULE("textFilter", "Filters traces", \
214 "Filter the trace following commands issued by user input", \
215 init
, destroy
, "option")
This page took 0.042195 seconds and 4 git commands to generate.