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.
32 #include <lttv/lttv.h>
33 #include <lttv/option.h>
34 #include <lttv/module.h>
35 #include <lttv/hook.h>
36 #include <lttv/attribute.h>
37 #include <lttv/iattribute.h>
38 #include <lttv/stats.h>
39 #include <lttv/filter.h>
41 #include <ltt/event.h>
43 #include <ltt/trace.h>
44 #include <ltt/facility.h>
47 /* Insert the hooks before and after each trace and tracefile, and for each
48 event. Print a global header. */
52 * - specify wich hook function will be used to call the core filter
64 * filters the file input from user
65 * @param hook_data the hook data, unused
67 void filter_analyze_file(void *hook_data
) {
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
78 if(!g_file_test(a_file_name
,G_FILE_TEST_EXISTS
)) {
79 g_warning("file %s does not exist", a_file_name
);
83 char* a_file_content
= NULL
;
85 g_file_get_contents(a_file_name
,&a_file_content
,NULL
,NULL
);
87 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
88 LTTV_POINTER
, &value
));
90 if(((GString
*)*(value
.v_pointer
))->len
!= 0) g_string_append_c((GString
*)*(value
.v_pointer
),'&');
91 g_string_append_c((GString
*)*(value
.v_pointer
),'(');
92 g_string_append((GString
*)*(value
.v_pointer
),a_file_content
);
93 g_string_append_c((GString
*)*(value
.v_pointer
),')');
98 * filters the string input from user
99 * @param hook_data the hook data, unused
101 void filter_analyze_string(void *hook_data
) {
103 LttvAttributeValue value
;
105 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
108 * User may specify filtering options through static file
109 * and/or command line string. From these sources, an
110 * option string is rebuilded and sent to the filter core
112 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
113 LTTV_POINTER
, &value
));
115 if(((GString
*)*(value
.v_pointer
))->len
!= 0) g_string_append_c((GString
*)*(value
.v_pointer
),'&');
116 g_string_append_c((GString
*)*(value
.v_pointer
),'(');
117 g_string_append((GString
*)*(value
.v_pointer
),a_string
);
118 g_string_append_c((GString
*)*(value
.v_pointer
),')');
123 * Output all filter commands on console
124 * @param hook_data the hook data
126 void filter_list_commands(void *hook_data
) {
128 g_print("[field] [op] [value]\n\n");
130 g_print("*** Possible fields ***\n");
131 g_print("event.name (string)\n");
132 g_print("event.facility (string)\n");
133 g_print("event.category (string)\n");
134 g_print("event.time (double)\n");
135 g_print("event.tsc (integer)\n");
136 g_print("event.field.facility_name.event_name.field_name.subfield_name (field_type)\n");
137 g_print("tracefile.name (string)\n");
138 g_print("trace.name (string)\n");
139 g_print("state.pid (integer)\n");
140 g_print("state.ppid (integer)\n");
141 g_print("state.creation_time (double)\n");
142 g_print("trace.insertion_time (double)\n");
143 g_print("trace.process_name (string)\n");
144 g_print("trace.execution_mode (string)\n");
145 g_print("trace.execution_submode (string)\n");
146 g_print("trace.process_status (string)\n");
147 g_print("trace.cpu (string)\n\n");
149 g_print("*** Possible operators ***\n");
150 g_print("equal '='\n");
151 g_print("not equal '!='\n");
152 g_print("greater '>'\n");
153 g_print("greater or equal '>='\n");
154 g_print("lower '<'\n");
155 g_print("lower or equal '<='\n");
157 g_print("*** Possible values ***\n");
158 g_print("string, integer, double");
162 * initialize the new module
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 *(value
.v_pointer
) = g_string_new("");
175 g_info("Init textFilter.c");
178 lttv_option_add("expression", 'e',
179 "filters a string issued by the user on the command line",
181 LTTV_OPT_STRING
, &a_string
, filter_analyze_string
, NULL
);
182 // add function to call for option
185 lttv_option_add("filename", 'f',
186 "browse the filter options contained in specified file",
188 LTTV_OPT_STRING
, &a_file_name
, filter_analyze_file
, NULL
);
190 lttv_option_add("list", 'l',
191 "list all possible filter commands for module",
193 LTTV_OPT_NONE
, NULL
, filter_list_commands
, NULL
);
198 * Destroy the current module
200 static void destroy() {
201 g_info("Destroy textFilter");
203 lttv_option_remove("expression");
205 lttv_option_remove("filename");
207 lttv_option_remove("list");
209 LttvAttributeValue value
;
211 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
213 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
214 LTTV_POINTER
, &value
));
216 g_string_free((GString
*)*(value
.v_pointer
),TRUE
);
221 LTTV_MODULE("textFilter", "Filters traces", \
222 "Filter the trace following commands issued by user input", \
223 init
, destroy
, "option")
This page took 0.033051 seconds and 4 git commands to generate.