X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fmodules%2Ftext%2FtextFilter.c;h=afac4f91bc6cdcd4ae1e33e3ac996f55e615a1fc;hb=4ec0c90410f2c28ec11fc20a0acf28ce30a97950;hp=83895e9263900f5adabcedd40ff6d3b20e4c8a5c;hpb=1da1525dc4a987ee97bd025f96d2ee75804d2012;p=lttv.git diff --git a/ltt/branches/poly/lttv/modules/text/textFilter.c b/ltt/branches/poly/lttv/modules/text/textFilter.c index 83895e92..afac4f91 100644 --- a/ltt/branches/poly/lttv/modules/text/textFilter.c +++ b/ltt/branches/poly/lttv/modules/text/textFilter.c @@ -1,5 +1,5 @@ /* This file is part of the Linux Trace Toolkit viewer - * Copyright (C) 2003-2004 Michel Dagenais + * Copyright (C) 2005 Simon Bouvier-Zappa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -16,11 +16,20 @@ * MA 02111-1307, USA. */ -/* - * The text filter facility will prompt for user filter option - * and transmit them to the lttv core +/*! \file lttv/modules/text/textFilter.c + * \brief Textual prompt for user filtering expression. + * + * The text filter facility will prompt for user filter option + * and transmit them to the lttv core. User can either specify + * a filtering string with the command line or/and specify a + * file containing filtering expressions. */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include #include #include #include @@ -34,16 +43,10 @@ #include #include #include -#include /* Insert the hooks before and after each trace and tracefile, and for each event. Print a global header. */ -/* - * YET TO BE ANSWERED ! - * - why does this module need dependency with batchAnalysis ? - */ - /* * TODO * - specify wich hook function will be used to call the core filter @@ -53,91 +56,117 @@ static char *a_file_name = NULL, *a_string = NULL; -GString - *a_filter_string = NULL; - - static LttvHooks *before_traceset, *event_hook; -static FILE *a_file; - - /** * filters the file input from user - * @param hook_data the hook data - * @return success/failure of operation + * @param hook_data the hook data, unused */ void filter_analyze_file(void *hook_data) { - g_print("textFilter::filter_analyze_file\n"); - + LttvAttributeValue value; + + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + /* * User may specify filtering options through static file * and/or command line string. From these sources, an * option string is rebuilded and sent to the filter core */ - a_file = fopen(a_file_name, "r"); - if(a_file == NULL) { - g_warning("file %s does not exist", a_file_name); + if(!g_file_test(a_file_name,G_FILE_TEST_EXISTS)) { + g_warning("file %s does not exist", a_file_name); return; } + + char* a_file_content = NULL; + + g_file_get_contents(a_file_name,&a_file_content,NULL,NULL); - char* line = NULL; - size_t len = 0; - - if(a_filter_string == NULL) { - a_filter_string = g_string_new(""); - } - else { - g_string_append(a_filter_string,"&"); /*conjonction between expression*/ - } - - while(!feof(a_file)) { - getline(&line,&len,a_file); - g_string_append(a_filter_string,line); - line = NULL; - } + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); + + if(((GString*)*(value.v_pointer))->len != 0) + (GString*)*(value.v_pointer) = + g_string_append_c((GString*)*(value.v_pointer),'&'); + (GString*)*(value.v_pointer) = + g_string_append_c((GString*)*(value.v_pointer),'('); + (GString*)*(value.v_pointer) = + g_string_append((GString*)*(value.v_pointer),a_file_content); + (GString*)*(value.v_pointer) = + g_string_append_c((GString*)*(value.v_pointer),')'); - fclose(a_file); } /** * filters the string input from user - * @param hook_data the hook data - * @return success/failure of operation + * @param hook_data the hook data, unused */ void filter_analyze_string(void *hook_data) { - g_print("textFilter::filter_analyze_string\n"); + LttvAttributeValue value; + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + /* * User may specify filtering options through static file * and/or command line string. From these sources, an * option string is rebuilded and sent to the filter core */ - if(a_filter_string==NULL) { - a_filter_string = g_string_new(""); - g_string_append(a_filter_string,a_string); - } - else { - g_string_append(a_filter_string,"&"); /*conjonction between expression*/ - g_string_append(a_filter_string,a_string); - } + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); + + if(((GString*)*(value.v_pointer))->len != 0) + (GString*)*(value.v_pointer) = + g_string_append_c((GString*)*(value.v_pointer),'&'); + (GString*)*(value.v_pointer) = + g_string_append_c((GString*)*(value.v_pointer),'('); + (GString*)*(value.v_pointer) = + g_string_append((GString*)*(value.v_pointer),a_string); + (GString*)*(value.v_pointer) = + g_string_append_c((GString*)*(value.v_pointer),')'); } /** - * filter to current event depending on the - * filter options tree + * Output all filter commands on console * @param hook_data the hook data - * @param call_data the call data - * @return success/error of operation */ -static gboolean filter_event_content(void *hook_data, void *call_data) { - - g_print("textFilter::filter_event_content\n"); /* debug */ +void filter_list_commands(void *hook_data) { + + g_print("[field] [op] [value]\n\n"); + + g_print("*** Possible fields ***\n"); + g_print("event.name (string)\n"); + g_print("event.facility (string)\n"); + g_print("event.category (string)\n"); + g_print("event.time (double)\n"); + g_print("event.tsc (integer)\n"); + g_print("event.field.facility_name.event_name.field_name.subfield_name (field_type)\n"); + g_print("tracefile.name (string)\n"); + g_print("trace.name (string)\n"); + g_print("state.pid (integer)\n"); + g_print("state.ppid (integer)\n"); + g_print("state.creation_time (double)\n"); + g_print("state.insertion_time (double)\n"); + g_print("state.process_name (string)\n"); + g_print("state.thread_brand (string)\n"); + g_print("state.execution_mode (string)\n"); + g_print("state.execution_submode (string)\n"); + g_print("state.process_status (string)\n"); + g_print("state.cpu (string)\n\n"); + + g_print("*** Possible operators ***\n"); + g_print("equal '='\n"); + g_print("not equal '!='\n"); + g_print("greater '>'\n"); + g_print("greater or equal '>='\n"); + g_print("lower '<'\n"); + g_print("lower or equal '<='\n"); + + g_print("*** Possible values ***\n"); + g_print("string, integer, double"); } /** @@ -145,16 +174,19 @@ static gboolean filter_event_content(void *hook_data, void *call_data) { */ static void init() { - g_print("textFilter::init()\n"); /* debug */ - LttvAttributeValue value; LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - g_info("Init textFilter.c"); + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); + *(value.v_pointer) = g_string_new(""); + + g_info("Init textFilter.c"); + a_string = NULL; - lttv_option_add("string", 's', + lttv_option_add("expression", 'e', "filters a string issued by the user on the command line", "string", LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL); @@ -165,21 +197,11 @@ static void init() { "browse the filter options contained in specified file", "file name", LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL); - - /* - * Note to myself ! - * LttvAttributeValue::v_pointer is a gpointer* --> void** - * see union LttvAttributeValue for more info - */ - g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event", - LTTV_POINTER, &value)); - g_assert((event_hook = *(value.v_pointer)) != NULL); - lttv_hooks_add(event_hook, filter_event_content, NULL, LTTV_PRIO_DEFAULT); -// g_assert(lttv_iattribute_find_by_path(attributes,"hooks/trace/before", -// LTTV_POINTER, &value)); -// g_assert((before_traceset = *(value.v_pointer)) != NULL); -// lttv_hooks_add(before_traceset, parse_filter_options, NULL, LTTV_PRIO_DEFAULT); + lttv_option_add("list", 'l', + "list all possible filter commands for module", + "list commands", + LTTV_OPT_NONE, NULL, filter_list_commands, NULL); } @@ -189,18 +211,25 @@ static void init() { static void destroy() { g_info("Destroy textFilter"); - lttv_option_remove("string"); + lttv_option_remove("expression"); lttv_option_remove("filename"); - lttv_hooks_remove_data(event_hook, filter_event_content, NULL); + lttv_option_remove("list"); -// lttv_hooks_remove_data(before_traceset, parse_filter_options, NULL); + LttvAttributeValue value; + + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); + + g_string_free((GString*)*(value.v_pointer),TRUE); } LTTV_MODULE("textFilter", "Filters traces", \ "Filter the trace following commands issued by user input", \ - init, destroy, "batchAnalysis", "option") + init, destroy, "option")