1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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 /* The text filter facility will prompt for user filter option
20 * and transmit them to the lttv core */
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>
31 #include <ltt/event.h>
33 #include <ltt/trace.h>
34 #include <ltt/facility.h>
37 /* Insert the hooks before and after each trace and tracefile, and for each
38 event. Print a global header. */
42 *a_filter_string
= NULL
;
51 * analyses user filter options and issues the filter string
53 * @param hook_data the hook data
54 * @param call_data the call data
56 static void parse_filter_options(void *hook_data
, void *call_data
) {
58 char* parsed_string
=NULL
; /* the string compiled from user's input */
61 g_print("textFilter::parse_filter_options\n");
63 /* recovering hooks data */
64 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
66 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
68 // LttvTrace* lt = tfc->t_context->vt;
71 g_info("TextFilter options parser");
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(a_file_name
!= NULL
) { /* -f switch in use */
79 a_file
= fopen(a_file_name
, "r");
81 g_error("textFilter::parse_filter_content() cannot open file %s", a_file_name
);
83 fscanf(a_file
,"%s",parsed_string
);
87 if(a_filter_string
!= NULL
) /* -s switch in use */
88 parsed_string
= a_filter_string
;
90 if(parsed_string
==NULL
)
91 g_warning("textFilter::parser_filter_options() no filtering options specified !");
93 /* send the filtering string to the core */
94 lttv_filter_new(parsed_string
,tfs
);
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
105 static gboolean
filter_event_content(void *hook_data
, void *call_data
) {
107 g_print("textFilter::filter_event_content\n"); /* debug */
111 * initialize the new module
115 g_print("textFilter::init()"); /* debug */
117 LttvAttributeValue value
;
119 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
121 g_info("Init textFilter.c");
123 a_filter_string
= NULL
;
124 lttv_option_add("string", 's',
125 "filters a string issued by the user on the command line",
127 LTTV_OPT_STRING
, &a_filter_string
, NULL
, NULL
);
128 // add function to call for option
131 lttv_option_add("filename", 'f',
132 "browse the filter options contained in specified file",
134 LTTV_OPT_STRING
, &a_file_name
, NULL
, NULL
);
138 * LttvAttributeValue::v_pointer is a gpointer* --> void**
139 * see union LttvAttributeValue for more info
141 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event",
142 LTTV_POINTER
, &value
));
143 g_assert((event_hook
= *(value
.v_pointer
)) != NULL
);
144 lttv_hooks_add(event_hook
, filter_event_content
, NULL
, LTTV_PRIO_DEFAULT
);
146 g_assert(lttv_iattribute_find_by_path(attributes
,"hooks/trace/before",
147 LTTV_POINTER
, &value
));
148 g_assert((before_traceset
= *(value
.v_pointer
)) != NULL
);
149 lttv_hooks_add(before_traceset
, parse_filter_options
, NULL
, LTTV_PRIO_DEFAULT
);
155 * Destroy the current module
157 static void destroy() {
158 g_info("Destroy textFilter");
160 lttv_option_remove("string");
162 lttv_option_remove("filename");
164 lttv_hooks_remove_data(event_hook
, filter_event_content
, NULL
);
166 lttv_hooks_remove_data(before_traceset
, parse_filter_options
, NULL
);
171 LTTV_MODULE("textFilter", "Filters traces", \
172 "Filter the trace following commands issued by user input", \
173 init
, destroy
, "option")
This page took 0.036477 seconds and 5 git commands to generate.