filter core:
[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
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>
36#include <ltt/ltt.h>
37#include <ltt/event.h>
38#include <ltt/type.h>
39#include <ltt/trace.h>
40#include <ltt/facility.h>
41#include <stdio.h>
42
43/* Insert the hooks before and after each trace and tracefile, and for each
44 event. Print a global header. */
45
91ad3f0a 46/*
47 * YET TO BE ANSWERED !
48 * - why does this module need dependency with batchAnalysis ?
49 */
50
1601b365 51/*
52 * TODO
53 * - specify wich hook function will be used to call the core filter
54 */
55
91ad3f0a 56static char
a58509ee 57 *a_file_name = NULL,
91ad3f0a 58 *a_string = NULL;
59
a58509ee 60static LttvHooks
61 *before_traceset,
62 *event_hook;
63
a58509ee 64/**
91ad3f0a 65 * filters the file input from user
a58509ee 66 * @param hook_data the hook data
91ad3f0a 67 * @return success/failure of operation
a58509ee 68 */
91ad3f0a 69void filter_analyze_file(void *hook_data) {
70
73050a5f 71 LttvAttributeValue value;
72
73 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
74
91ad3f0a 75 /*
a58509ee 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
79 */
c684db06 80 if(!g_file_test(a_file_name,G_FILE_TEST_EXISTS)) {
81 g_warning("file %s does not exist", a_file_name);
82 return;
83 }
84
85 char* a_file_content = NULL;
86
87 g_file_get_contents(a_file_name,&a_file_content,NULL,NULL);
91ad3f0a 88
73050a5f 89 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
90 LTTV_POINTER, &value));
91
73050a5f 92 if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
c684db06 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),')');
56e29124 96
91ad3f0a 97}
98
99/**
100 * filters the string input from user
101 * @param hook_data the hook data
102 * @return success/failure of operation
103 */
104void filter_analyze_string(void *hook_data) {
105
73050a5f 106 LttvAttributeValue value;
107
108 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
109
91ad3f0a 110 /*
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
114 */
73050a5f 115 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
116 LTTV_POINTER, &value));
cec3d7b0 117
73050a5f 118 if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
c684db06 119 g_string_append_c((GString*)*(value.v_pointer),'(');
73050a5f 120 g_string_append((GString*)*(value.v_pointer),a_string);
c684db06 121 g_string_append_c((GString*)*(value.v_pointer),')');
56e29124 122
a58509ee 123}
124
125/**
126 * initialize the new module
127 */
128static void init() {
129
a58509ee 130 LttvAttributeValue value;
131
132 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
133
73050a5f 134 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
135 LTTV_POINTER, &value));
136
137 *(value.v_pointer) = g_string_new("");
138
a58509ee 139 g_info("Init textFilter.c");
cec3d7b0 140
91ad3f0a 141 a_string = NULL;
73050a5f 142 lttv_option_add("expression", 'e',
a58509ee 143 "filters a string issued by the user on the command line",
144 "string",
91ad3f0a 145 LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL);
1a7fa682 146 // add function to call for option
147
a58509ee 148 a_file_name = NULL;
149 lttv_option_add("filename", 'f',
150 "browse the filter options contained in specified file",
151 "file name",
91ad3f0a 152 LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL);
a58509ee 153
a58509ee 154}
155
156/**
157 * Destroy the current module
158 */
159static void destroy() {
160 g_info("Destroy textFilter");
161
73050a5f 162 lttv_option_remove("expression");
a58509ee 163
164 lttv_option_remove("filename");
165
73050a5f 166 LttvAttributeValue value;
167
168 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
a58509ee 169
73050a5f 170 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
171 LTTV_POINTER, &value));
172
173 g_string_free((GString*)*(value.v_pointer),TRUE);
a58509ee 174
175}
176
177
178LTTV_MODULE("textFilter", "Filters traces", \
179 "Filter the trace following commands issued by user input", \
73050a5f 180 init, destroy, "option")
a58509ee 181
This page took 0.030112 seconds and 4 git commands to generate.