1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2005 Simon Bouvier-Zappa
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,
19 /*! \file lttv/modules/text/textFilter.c
20 * \brief Textual prompt for user filtering expression.
22 * The text filter facility will prompt for user filter option
23 * and transmit them to the lttv core. User can either specify
24 * a filtering string with the command line or/and specify a
25 * file containing filtering expressions.
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>
37 #include <ltt/event.h>
39 #include <ltt/trace.h>
40 #include <ltt/facility.h>
43 /* Insert the hooks before and after each trace and tracefile, and for each
44 event. Print a global header. */
47 * YET TO BE ANSWERED !
48 * - why does this module need dependency with batchAnalysis ?
53 * - specify wich hook function will be used to call the core filter
65 * filters the file input from user
66 * @param hook_data the hook data
67 * @return success/failure of operation
69 void filter_analyze_file(void *hook_data
) {
71 LttvAttributeValue value
;
73 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
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
80 if(!g_file_test(a_file_name
,G_FILE_TEST_EXISTS
)) {
81 g_warning("file %s does not exist", a_file_name
);
85 char* a_file_content
= NULL
;
87 g_file_get_contents(a_file_name
,&a_file_content
,NULL
,NULL
);
89 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
90 LTTV_POINTER
, &value
));
92 if(((GString
*)*(value
.v_pointer
))->len
!= 0) g_string_append_c((GString
*)*(value
.v_pointer
),'&');
93 g_string_append_c((GString
*)*(value
.v_pointer
),'(');
94 g_string_append((GString
*)*(value
.v_pointer
),a_file_content
);
95 g_string_append_c((GString
*)*(value
.v_pointer
),')');
100 * filters the string input from user
101 * @param hook_data the hook data
102 * @return success/failure of operation
104 void filter_analyze_string(void *hook_data
) {
106 LttvAttributeValue value
;
108 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
111 * User may specify filtering options through static file
112 * and/or command line string. From these sources, an
113 * option string is rebuilded and sent to the filter core
115 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
116 LTTV_POINTER
, &value
));
118 if(((GString
*)*(value
.v_pointer
))->len
!= 0) g_string_append_c((GString
*)*(value
.v_pointer
),'&');
119 g_string_append_c((GString
*)*(value
.v_pointer
),'(');
120 g_string_append((GString
*)*(value
.v_pointer
),a_string
);
121 g_string_append_c((GString
*)*(value
.v_pointer
),')');
126 * initialize the new module
130 LttvAttributeValue value
;
132 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
134 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
135 LTTV_POINTER
, &value
));
137 *(value
.v_pointer
) = g_string_new("");
139 g_info("Init textFilter.c");
142 lttv_option_add("expression", 'e',
143 "filters a string issued by the user on the command line",
145 LTTV_OPT_STRING
, &a_string
, filter_analyze_string
, NULL
);
146 // add function to call for option
149 lttv_option_add("filename", 'f',
150 "browse the filter options contained in specified file",
152 LTTV_OPT_STRING
, &a_file_name
, filter_analyze_file
, NULL
);
157 * Destroy the current module
159 static void destroy() {
160 g_info("Destroy textFilter");
162 lttv_option_remove("expression");
164 lttv_option_remove("filename");
166 LttvAttributeValue value
;
168 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
170 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
171 LTTV_POINTER
, &value
));
173 g_string_free((GString
*)*(value
.v_pointer
),TRUE
);
178 LTTV_MODULE("textFilter", "Filters traces", \
179 "Filter the trace following commands issued by user input", \
180 init
, destroy
, "option")
This page took 0.035784 seconds and 5 git commands to generate.