Update FSF address
[lttv.git] / lttv / modules / text / textFilter.c
CommitLineData
a58509ee 1/* This file is part of the Linux Trace Toolkit viewer
852f16bb 2 * Copyright (C) 2005 Simon Bouvier-Zappa
a58509ee 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
b9ce0bad
YB
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA.
a58509ee 17 */
18
7e7af7f2 19/*! \file lttv/modules/text/textFilter.c
20 * \brief Textual prompt for user filtering expression.
21 *
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.
91ad3f0a 26 */
a58509ee 27
4e4d11b3 28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
4ec0c904 32#include <glib.h>
a58509ee 33#include <lttv/lttv.h>
34#include <lttv/option.h>
35#include <lttv/module.h>
36#include <lttv/hook.h>
37#include <lttv/attribute.h>
38#include <lttv/iattribute.h>
39#include <lttv/stats.h>
40#include <lttv/filter.h>
41#include <ltt/ltt.h>
42#include <ltt/event.h>
a58509ee 43#include <ltt/trace.h>
a58509ee 44
45/* Insert the hooks before and after each trace and tracefile, and for each
46 event. Print a global header. */
47
1601b365 48/*
49 * TODO
50 * - specify wich hook function will be used to call the core filter
51 */
52
91ad3f0a 53static char
a58509ee 54 *a_file_name = NULL,
91ad3f0a 55 *a_string = NULL;
56
43ed82b5 57static LttvHooks __attribute__ ((__unused__))
a58509ee 58 *before_traceset,
59 *event_hook;
60
a58509ee 61/**
91ad3f0a 62 * filters the file input from user
bd523c6f 63 * @param hook_data the hook data, unused
a58509ee 64 */
91ad3f0a 65void filter_analyze_file(void *hook_data) {
66
73050a5f 67 LttvAttributeValue value;
68
69 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
8f318283 70 gboolean retval;
73050a5f 71
91ad3f0a 72 /*
a58509ee 73 * User may specify filtering options through static file
74 * and/or command line string. From these sources, an
75 * option string is rebuilded and sent to the filter core
76 */
c684db06 77 if(!g_file_test(a_file_name,G_FILE_TEST_EXISTS)) {
78 g_warning("file %s does not exist", a_file_name);
79 return;
80 }
81
82 char* a_file_content = NULL;
83
84 g_file_get_contents(a_file_name,&a_file_content,NULL,NULL);
91ad3f0a 85
8f318283
BP
86 retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
87 LTTV_POINTER, &value);
88 g_assert(retval);
29a81f1a
BP
89
90 if (((GString*)*(value.v_pointer))->len != 0)
91 g_string_append_c((GString*)*(value.v_pointer),'&');
92 g_string_append_c((GString*)*(value.v_pointer),'(');
93 g_string_append((GString*)*(value.v_pointer),a_file_content);
94 g_string_append_c((GString*)*(value.v_pointer),')');
91ad3f0a 95}
96
97/**
98 * filters the string input from user
bd523c6f 99 * @param hook_data the hook data, unused
91ad3f0a 100 */
101void filter_analyze_string(void *hook_data) {
102
73050a5f 103 LttvAttributeValue value;
104
105 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
8f318283
BP
106 gboolean retval;
107
91ad3f0a 108 /*
109 * User may specify filtering options through static file
110 * and/or command line string. From these sources, an
111 * option string is rebuilded and sent to the filter core
112 */
8f318283
BP
113 retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
114 LTTV_POINTER, &value);
115 g_assert(retval);
29a81f1a
BP
116
117 if (((GString*)*(value.v_pointer))->len != 0)
118 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),')');
a58509ee 122}
123
bd523c6f 124/**
125 * Output all filter commands on console
126 * @param hook_data the hook data
127 */
128void filter_list_commands(void *hook_data) {
129
130 g_print("[field] [op] [value]\n\n");
131
132 g_print("*** Possible fields ***\n");
6471e71f 133 g_print("event.name (string) (channel_name.event_name)\n");
134 g_print("event.subname (string)\n");
bd523c6f 135 g_print("event.category (string)\n");
136 g_print("event.time (double)\n");
137 g_print("event.tsc (integer)\n");
33bdc8dd 138 g_print("event.target_pid (integer)\n");
6471e71f 139 g_print("event.field.channel_name.event_name.field_name.subfield_name (field_type)\n");
140 g_print("channel.name (string)\n");
bd523c6f 141 g_print("trace.name (string)\n");
142 g_print("state.pid (integer)\n");
143 g_print("state.ppid (integer)\n");
144 g_print("state.creation_time (double)\n");
7b5f6cf1 145 g_print("state.insertion_time (double)\n");
146 g_print("state.process_name (string)\n");
7b5f6cf1 147 g_print("state.execution_mode (string)\n");
148 g_print("state.execution_submode (string)\n");
149 g_print("state.process_status (string)\n");
150 g_print("state.cpu (string)\n\n");
bd523c6f 151
152 g_print("*** Possible operators ***\n");
153 g_print("equal '='\n");
154 g_print("not equal '!='\n");
155 g_print("greater '>'\n");
156 g_print("greater or equal '>='\n");
157 g_print("lower '<'\n");
158 g_print("lower or equal '<='\n");
159
160 g_print("*** Possible values ***\n");
161 g_print("string, integer, double");
162}
163
a58509ee 164/**
165 * initialize the new module
166 */
167static void init() {
168
a58509ee 169 LttvAttributeValue value;
170
171 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
8f318283 172 gboolean retval;
a58509ee 173
8f318283
BP
174 retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
175 LTTV_POINTER, &value);
176 g_assert(retval);
73050a5f 177
178 *(value.v_pointer) = g_string_new("");
179
a58509ee 180 g_info("Init textFilter.c");
cec3d7b0 181
91ad3f0a 182 a_string = NULL;
73050a5f 183 lttv_option_add("expression", 'e',
a58509ee 184 "filters a string issued by the user on the command line",
185 "string",
91ad3f0a 186 LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL);
1a7fa682 187 // add function to call for option
188
a58509ee 189 a_file_name = NULL;
190 lttv_option_add("filename", 'f',
191 "browse the filter options contained in specified file",
192 "file name",
91ad3f0a 193 LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL);
a58509ee 194
bd523c6f 195 lttv_option_add("list", 'l',
196 "list all possible filter commands for module",
197 "list commands",
198 LTTV_OPT_NONE, NULL, filter_list_commands, NULL);
199
a58509ee 200}
201
202/**
203 * Destroy the current module
204 */
205static void destroy() {
8f318283
BP
206 gboolean retval;
207
a58509ee 208 g_info("Destroy textFilter");
209
73050a5f 210 lttv_option_remove("expression");
a58509ee 211
212 lttv_option_remove("filename");
213
bd523c6f 214 lttv_option_remove("list");
215
73050a5f 216 LttvAttributeValue value;
217
218 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
a58509ee 219
8f318283
BP
220 retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
221 LTTV_POINTER, &value);
222 g_assert(retval);
73050a5f 223
224 g_string_free((GString*)*(value.v_pointer),TRUE);
a58509ee 225
226}
227
228
229LTTV_MODULE("textFilter", "Filters traces", \
230 "Filter the trace following commands issued by user input", \
73050a5f 231 init, destroy, "option")
a58509ee 232
This page took 0.071785 seconds and 4 git commands to generate.