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
57 *a_filter_string
= NULL
;
68 * filters the file input from user
69 * @param hook_data the hook data
70 * @return success/failure of operation
72 void filter_analyze_file(void *hook_data
) {
74 g_print("textFilter::filter_analyze_file\n");
77 * User may specify filtering options through static file
78 * and/or command line string. From these sources, an
79 * option string is rebuilded and sent to the filter core
81 a_file
= fopen(a_file_name
, "r");
83 g_warning("file %s does not exist", a_file_name
);
90 if(a_filter_string
== NULL
) {
91 a_filter_string
= g_string_new("");
94 g_string_append(a_filter_string
,"&"); /*conjonction between expression*/
97 while(!feof(a_file
)) {
98 getline(&line
,&len
,a_file
);
99 g_string_append(a_filter_string
,line
);
107 * filters the string input from user
108 * @param hook_data the hook data
109 * @return success/failure of operation
111 void filter_analyze_string(void *hook_data
) {
113 g_print("textFilter::filter_analyze_string\n");
116 * User may specify filtering options through static file
117 * and/or command line string. From these sources, an
118 * option string is rebuilded and sent to the filter core
120 if(a_filter_string
==NULL
) {
121 a_filter_string
= g_string_new("");
122 g_string_append(a_filter_string
,a_string
);
125 g_string_append(a_filter_string
,"&"); /*conjonction between expression*/
126 g_string_append(a_filter_string
,a_string
);
132 * filter to current event depending on the
133 * filter options tree
134 * @param hook_data the hook data
135 * @param call_data the call data
136 * @return success/error of operation
138 static gboolean
filter_event_content(void *hook_data
, void *call_data
) {
140 g_print("textFilter::filter_event_content\n"); /* debug */
144 * initialize the new module
148 g_print("textFilter::init()\n"); /* debug */
150 LttvAttributeValue value
;
152 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
154 g_info("Init textFilter.c");
157 lttv_option_add("string", 's',
158 "filters a string issued by the user on the command line",
160 LTTV_OPT_STRING
, &a_string
, filter_analyze_string
, NULL
);
161 // add function to call for option
164 lttv_option_add("filename", 'f',
165 "browse the filter options contained in specified file",
167 LTTV_OPT_STRING
, &a_file_name
, filter_analyze_file
, NULL
);
171 * LttvAttributeValue::v_pointer is a gpointer* --> void**
172 * see union LttvAttributeValue for more info
174 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event",
175 LTTV_POINTER
, &value
));
176 g_assert((event_hook
= *(value
.v_pointer
)) != NULL
);
177 lttv_hooks_add(event_hook
, filter_event_content
, NULL
, LTTV_PRIO_DEFAULT
);
179 // g_assert(lttv_iattribute_find_by_path(attributes,"hooks/trace/before",
180 // LTTV_POINTER, &value));
181 // g_assert((before_traceset = *(value.v_pointer)) != NULL);
182 // lttv_hooks_add(before_traceset, parse_filter_options, NULL, LTTV_PRIO_DEFAULT);
187 * Destroy the current module
189 static void destroy() {
190 g_info("Destroy textFilter");
192 lttv_option_remove("string");
194 lttv_option_remove("filename");
196 lttv_hooks_remove_data(event_hook
, filter_event_content
, NULL
);
198 // lttv_hooks_remove_data(before_traceset, parse_filter_options, NULL);
203 LTTV_MODULE("textFilter", "Filters traces", \
204 "Filter the trace following commands issued by user input", \
205 init
, destroy
, "batchAnalysis", "option")
This page took 0.035488 seconds and 4 git commands to generate.