filter by facility
[lttv.git] / ltt / branches / poly / 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
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
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
a58509ee 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>
40#include <ltt/ltt.h>
41#include <ltt/event.h>
42#include <ltt/type.h>
43#include <ltt/trace.h>
44#include <ltt/facility.h>
45#include <stdio.h>
46
47/* Insert the hooks before and after each trace and tracefile, and for each
48 event. Print a global header. */
49
91ad3f0a 50/*
51 * YET TO BE ANSWERED !
52 * - why does this module need dependency with batchAnalysis ?
53 */
54
1601b365 55/*
56 * TODO
57 * - specify wich hook function will be used to call the core filter
58 */
59
91ad3f0a 60static char
a58509ee 61 *a_file_name = NULL,
91ad3f0a 62 *a_string = NULL;
63
a58509ee 64static LttvHooks
65 *before_traceset,
66 *event_hook;
67
a58509ee 68/**
91ad3f0a 69 * filters the file input from user
bd523c6f 70 * @param hook_data the hook data, unused
a58509ee 71 */
91ad3f0a 72void filter_analyze_file(void *hook_data) {
73
73050a5f 74 LttvAttributeValue value;
75
76 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
77
91ad3f0a 78 /*
a58509ee 79 * User may specify filtering options through static file
80 * and/or command line string. From these sources, an
81 * option string is rebuilded and sent to the filter core
82 */
c684db06 83 if(!g_file_test(a_file_name,G_FILE_TEST_EXISTS)) {
84 g_warning("file %s does not exist", a_file_name);
85 return;
86 }
87
88 char* a_file_content = NULL;
89
90 g_file_get_contents(a_file_name,&a_file_content,NULL,NULL);
91ad3f0a 91
73050a5f 92 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
93 LTTV_POINTER, &value));
94
73050a5f 95 if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
c684db06 96 g_string_append_c((GString*)*(value.v_pointer),'(');
97 g_string_append((GString*)*(value.v_pointer),a_file_content);
98 g_string_append_c((GString*)*(value.v_pointer),')');
56e29124 99
91ad3f0a 100}
101
102/**
103 * filters the string input from user
bd523c6f 104 * @param hook_data the hook data, unused
91ad3f0a 105 */
106void filter_analyze_string(void *hook_data) {
107
73050a5f 108 LttvAttributeValue value;
109
110 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
111
91ad3f0a 112 /*
113 * User may specify filtering options through static file
114 * and/or command line string. From these sources, an
115 * option string is rebuilded and sent to the filter core
116 */
73050a5f 117 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
118 LTTV_POINTER, &value));
cec3d7b0 119
73050a5f 120 if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
c684db06 121 g_string_append_c((GString*)*(value.v_pointer),'(');
73050a5f 122 g_string_append((GString*)*(value.v_pointer),a_string);
c684db06 123 g_string_append_c((GString*)*(value.v_pointer),')');
56e29124 124
a58509ee 125}
126
bd523c6f 127/**
128 * Output all filter commands on console
129 * @param hook_data the hook data
130 */
131void filter_list_commands(void *hook_data) {
132
133 g_print("[field] [op] [value]\n\n");
134
135 g_print("*** Possible fields ***\n");
136 g_print("event.name (string)\n");
ffd088ef 137 g_print("event.facility (string)\n");
bd523c6f 138 g_print("event.category (string)\n");
139 g_print("event.time (double)\n");
140 g_print("event.tsc (integer)\n");
141 g_print("tracefile.name (string)\n");
142 g_print("trace.name (string)\n");
143 g_print("state.pid (integer)\n");
144 g_print("state.ppid (integer)\n");
145 g_print("state.creation_time (double)\n");
146 g_print("trace.insertion_time (double)\n");
147 g_print("trace.process_name (string)\n");
148 g_print("trace.execution_mode (string)\n");
149 g_print("trace.execution_submode (string)\n");
150 g_print("trace.process_status (string)\n");
151 g_print("trace.cpu (string)\n\n");
152
153 g_print("*** Possible operators ***\n");
154 g_print("equal '='\n");
155 g_print("not equal '!='\n");
156 g_print("greater '>'\n");
157 g_print("greater or equal '>='\n");
158 g_print("lower '<'\n");
159 g_print("lower or equal '<='\n");
160
161 g_print("*** Possible values ***\n");
162 g_print("string, integer, double");
163}
164
a58509ee 165/**
166 * initialize the new module
167 */
168static void init() {
169
a58509ee 170 LttvAttributeValue value;
171
172 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
173
73050a5f 174 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
175 LTTV_POINTER, &value));
176
177 *(value.v_pointer) = g_string_new("");
178
a58509ee 179 g_info("Init textFilter.c");
cec3d7b0 180
91ad3f0a 181 a_string = NULL;
73050a5f 182 lttv_option_add("expression", 'e',
a58509ee 183 "filters a string issued by the user on the command line",
184 "string",
91ad3f0a 185 LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL);
1a7fa682 186 // add function to call for option
187
a58509ee 188 a_file_name = NULL;
189 lttv_option_add("filename", 'f',
190 "browse the filter options contained in specified file",
191 "file name",
91ad3f0a 192 LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL);
a58509ee 193
bd523c6f 194 lttv_option_add("list", 'l',
195 "list all possible filter commands for module",
196 "list commands",
197 LTTV_OPT_NONE, NULL, filter_list_commands, NULL);
198
a58509ee 199}
200
201/**
202 * Destroy the current module
203 */
204static void destroy() {
205 g_info("Destroy textFilter");
206
73050a5f 207 lttv_option_remove("expression");
a58509ee 208
209 lttv_option_remove("filename");
210
bd523c6f 211 lttv_option_remove("list");
212
73050a5f 213 LttvAttributeValue value;
214
215 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
a58509ee 216
73050a5f 217 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
218 LTTV_POINTER, &value));
219
220 g_string_free((GString*)*(value.v_pointer),TRUE);
a58509ee 221
222}
223
224
225LTTV_MODULE("textFilter", "Filters traces", \
226 "Filter the trace following commands issued by user input", \
73050a5f 227 init, destroy, "option")
a58509ee 228
This page took 0.037369 seconds and 4 git commands to generate.