From 0769c82fae5a39a6965f63439671ecca48b2d9b5 Mon Sep 17 00:00:00 2001 From: siboud Date: Sun, 13 Feb 2005 03:07:59 +0000 Subject: [PATCH] filter.c -- added quarks for the filter options git-svn-id: http://ltt.polymtl.ca/svn@870 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/lttv/lttv/filter.c | 120 ++++++++++++++++++++++----- ltt/branches/poly/lttv/lttv/filter.h | 12 ++- 2 files changed, 107 insertions(+), 25 deletions(-) diff --git a/ltt/branches/poly/lttv/lttv/filter.c b/ltt/branches/poly/lttv/lttv/filter.c index 8e9aa8fc..d2f62d81 100644 --- a/ltt/branches/poly/lttv/lttv/filter.c +++ b/ltt/branches/poly/lttv/lttv/filter.c @@ -1,5 +1,5 @@ /* This file is part of the Linux Trace Toolkit viewer - * Copyright (C) 2003-2004 Michel Dagenais + * Copyright (C) 2003-2005 Michel Dagenais * * 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 @@ -23,6 +23,12 @@ larger or equal to a specified value. */ +/* + * YET TO BE ANSWERED + * - should the filter be implemented as a module + * - should all the structures and field types be associated with GQuarks + */ + #include /* @@ -48,6 +54,41 @@ path(component...) -> field */ +/** + * Parse through filtering field hierarchy as specified + * by user. This function compares each value to + * predetermined quarks + * @param fp The field path list + * @return success/failure of operation + */ +gboolean +parse_field_path(GList* fp) { + + GString* f = g_list_first(fp)->data; + + switch(g_quark_try_string(f->str)) { +// case LTTV_FILTER_TRACE: + +// break; +// case LTTV_FILTER_TRACEFILE: + +// break; +// case LTTV_FILTER_TRACESET: + +// break; +// case LTTV_FILTER_STATE: + +// break; +// case LTTV_FILTER_EVENT: + +// break; + default: /* Quark value unrecognized or equal to 0 */ + g_warning("Unrecognized field in filter string"); + return FALSE; + } + return TRUE; +} + /** * Add an filtering option to the current tree * @param expression Current expression to parse @@ -59,6 +100,7 @@ parse_simple_expression(GString* expression) { unsigned i; + } @@ -69,32 +111,28 @@ parse_simple_expression(GString* expression) { * @return the current lttv_filter or NULL if error */ lttv_filter* -lttv_filter_new(char *expression, LttvTraceState *tfs) { - - /* test */ - char* field = "cpu"; - LttEventType *et; - - // LttField* a_ltt_field = NULL; - // a_ltt_field = find_field(NULL,field); +lttv_filter_new(char *expression, LttvTraceState *tcs) { - // g_print("%s\n",a_ltt_field->field_type->type_name); + g_print("filter::lttv_filter_new()\n"); /* debug */ - return NULL; - unsigned i, p=0, /* parenthesis nesting value */ b=0; /* current breakpoint in expression string */ + LTTV_FILTER_EVENT = g_quark_from_string("event"); + LTTV_FILTER_TRACE = g_quark_from_string("trace"); + LTTV_FILTER_TRACESET = g_quark_from_string("traceset"); + LTTV_FILTER_STATE = g_quark_from_string("state"); + LTTV_FILTER_TRACEFILE = g_quark_from_string("tracefile"); + gpointer tree = NULL; /* temporary values */ - GString *current_option = g_string_new(""); + GString *a_field_component = g_string_new(""); + GList *a_field_path = NULL; lttv_simple_expression a_simple_expression; - - g_print("filter::lttv_filter_new()\n"); /* debug */ - + /* * 1. parse expression * 2. construct binary tree @@ -114,13 +152,15 @@ lttv_filter_new(char *expression, LttvTraceState *tfs) { * in browsing that string * 1. finding boolean ops ( &,|,^,! ) and parenthesis * 2. finding simple expressions - * - field path + * - field path ( separated by dots ) * - op ( >, <, =, >=, <=, !=) - * - value + * - value ( integer, string ... ) + * To spare computing time, the whole + * string is parsed in this loop for a + * O(n) complexity order. */ - for(i=0;istr); + g_print("%s\n",a_field_component->str); switch(expression[i]) { /* * logical operators @@ -128,14 +168,15 @@ lttv_filter_new(char *expression, LttvTraceState *tfs) { case '&': /* and */ case '|': /* or */ case '^': /* xor */ - current_option = g_string_new(""); + g_list_append( a_field_path, a_field_component ); + a_field_component = g_string_new(""); break; case '!': /* not, or not equal (math op) */ if(expression[i+1] == '=') { /* != */ a_simple_expression.op = LTTV_FIELD_NE; i++; } else { /* ! */ - g_print("%s\n",current_option); + g_print("%s\n",a_field_component); current_option = g_string_new(""); } break; @@ -164,6 +205,13 @@ lttv_filter_new(char *expression, LttvTraceState *tfs) { case '=': /* equal */ a_simple_expression.op = LTTV_FIELD_EQ; break; + /* + * Field concatening caracter + */ + case '.': /* dot */ + g_list_append( a_field_path, a_field_component ); + a_field_component = g_string_new(""); + break; default: /* concatening current string */ g_string_append_c(current_option,expression[i]); } @@ -185,8 +233,34 @@ lttv_filter_new(char *expression, LttvTraceState *tfs) { * @return success/failure of operation */ gboolean -lttv_filter_tracefile(lttv_filter *filter, LttvTrace *tracefile) { +lttv_filter_tracefile(lttv_filter *filter, LttTracefile *tracefile) { + + + + /* test */ +/* int i, nb; + char *f_name, *e_name; + char* field = "cpu"; + + LttvTraceHook h; + + LttEventType *et; + + LttType *t; + + GString *fe_name = g_string_new(""); + + nb = ltt_trace_eventtype_number(tcs->parent.t); + g_print("NB:%i\n",nb); + for(i = 0 ; i < nb ; i++) { + et = ltt_trace_eventtype_get(tcs->parent.t, i); + e_name = ltt_eventtype_name(et); + f_name = ltt_facility_name(ltt_eventtype_facility(et)); + g_string_printf(fe_name, "%s.%s", f_name, e_name); + g_print("facility:%s and event:%s\n",f_name,e_name); + } + */ } /** diff --git a/ltt/branches/poly/lttv/lttv/filter.h b/ltt/branches/poly/lttv/lttv/filter.h index 9224a9a5..99f3c403 100644 --- a/ltt/branches/poly/lttv/lttv/filter.h +++ b/ltt/branches/poly/lttv/lttv/filter.h @@ -52,6 +52,13 @@ */ +static GQuark + LTTV_FILTER_TRACE, + LTTV_FILTER_TRACESET, + LTTV_FILTER_TRACEFILE, + LTTV_FILTER_STATE, + LTTV_FILTER_EVENT; + /** * @enum lttv_expression_op */ @@ -114,17 +121,18 @@ typedef struct _lttv_filter { lttv_filter_tree* tree; } lttv_filter; +gboolean parse_field_path(GList* fp); + gboolean parse_simple_expression(GString* expression); /* Compile the filter expression into an efficient data structure */ - lttv_filter *lttv_filter_new(char *expression, LttvTraceState *tfs); /* Check if the tracefile or event satisfies the filter. The arguments are declared as void * to allow these functions to be used as hooks. */ -gboolean lttv_filter_tracefile(lttv_filter *filter, LttvTrace *tracefile); +gboolean lttv_filter_tracefile(lttv_filter *filter, LttTracefile *tracefile); gboolean lttv_filter_event(lttv_filter *filter, LttEvent *event); -- 2.34.1