added the module text/textFilter
[lttv.git] / ltt / branches / poly / lttv / modules / text / textFilter.c
CommitLineData
a58509ee 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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
19/* The text filter facility will prompt for user filter option
20 * and transmit them to the lttv core */
21
22#include <lttv/lttv.h>
23#include <lttv/option.h>
24#include <lttv/module.h>
25#include <lttv/hook.h>
26#include <lttv/attribute.h>
27#include <lttv/iattribute.h>
28#include <lttv/stats.h>
29#include <lttv/filter.h>
30#include <ltt/ltt.h>
31#include <ltt/event.h>
32#include <ltt/type.h>
33#include <ltt/trace.h>
34#include <ltt/facility.h>
35#include <stdio.h>
36
37/* Insert the hooks before and after each trace and tracefile, and for each
38 event. Print a global header. */
39
40static char
41 *a_file_name = NULL,
42 *a_filter_string = NULL;
43
44static LttvHooks
45 *before_traceset,
46 *event_hook;
47
48static FILE *a_file;
49
50/**
51 * analyses user filter options and issues the filter string
52 * to the core
53 * @param hook_data the hook data
54 * @param call_data the call data
55 */
56static void parse_filter_options(void *hook_data, void *call_data) {
57
58 char* parsed_string=NULL; /* the string compiled from user's input */
59
60 /* debug */
61 g_print("textFilter::parse_filter_options\n");
62
63 /* recovering hooks data */
64 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
65
66 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
67
68 LttvTrace* lt = tfc->t_context->vt;
69
70 /* hook header */
71 g_info("TextFilter options parser");
72
73 /*
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
77 */
78 if(a_file_name != NULL) { /* -f switch in use */
79 a_file = fopen(a_file_name, "r");
80 if(a_file == NULL)
81 g_error("textFilter::parse_filter_content() cannot open file %s", a_file_name);
82
83 fscanf(a_file,"%s",parsed_string);
84
85 fclose(a_file);
86 }
87 if(a_filter_string != NULL) /* -s switch in use */
88 parsed_string = a_filter_string;
89
90 if(parsed_string==NULL)
91 g_warning("textFilter::parser_filter_options() no filtering options specified !");
92
93 /* send the filtering string to the core */
94 lttv_filter_new(parsed_string,lt);
95
96}
97
98/**
99 * filter to current event depending on the
100 * filter options tree
101 * @param hook_data the hook data
102 * @param call_data the call data
103 * @return success/error of operation
104 */
105static gboolean filter_event_content(void *hook_data, void *call_data) {
106
107 g_print("textFilter::filter_event_content\n"); /* debug */
108}
109
110/**
111 * initialize the new module
112 */
113static void init() {
114
115 g_print("textFilter::init()"); /* debug */
116
117 LttvAttributeValue value;
118
119 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
120
121 g_info("Init textFilter.c");
122
123 a_filter_string = NULL;
124 lttv_option_add("string", 's',
125 "filters a string issued by the user on the command line",
126 "string",
127 LTTV_OPT_STRING, &a_filter_string, NULL, NULL);
128
129 a_file_name = NULL;
130 lttv_option_add("filename", 'f',
131 "browse the filter options contained in specified file",
132 "file name",
133 LTTV_OPT_STRING, &a_file_name, NULL, NULL);
134
135 /*
136 * Note to myself !
137 * LttvAttributeValue::v_pointer is a gpointer* --> void**
138 * see union LttvAttributeValue for more info
139 */
140 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
141 LTTV_POINTER, &value));
142 g_assert((event_hook = *(value.v_pointer)) != NULL);
143 lttv_hooks_add(event_hook, filter_event_content, NULL, LTTV_PRIO_DEFAULT);
144
145 g_assert(lttv_iattribute_find_by_path(attributes,"hooks/trace/before",
146 LTTV_POINTER, &value));
147 g_assert((before_traceset = *(value.v_pointer)) != NULL);
148 lttv_hooks_add(before_traceset, parse_filter_options, NULL, LTTV_PRIO_DEFAULT);
149
150
151}
152
153/**
154 * Destroy the current module
155 */
156static void destroy() {
157 g_info("Destroy textFilter");
158
159 lttv_option_remove("string");
160
161 lttv_option_remove("filename");
162
163 lttv_hooks_remove_data(event_hook, filter_event_content, NULL);
164
165 lttv_hooks_remove_data(before_traceset, parse_filter_options, NULL);
166
167}
168
169
170LTTV_MODULE("textFilter", "Filters traces", \
171 "Filter the trace following commands issued by user input", \
172 init, destroy, "batchAnalysis", "option")
173
This page took 0.028286 seconds and 4 git commands to generate.