* MA 02111-1307, USA.
*/
-/*
- read_token
-
- read_expression
- ( read expr )
- simple expr [ op expr ]
-
- read_simple_expression
- read_field_path [ rel value ]
-
- read_field_path
- read_field_component [. field path]
-
- read_field_component
- name [ \[ value \] ]
-
- data struct:
- and/or(left/right)
- not(child)
- op(left/right)
- path(component...) -> field
-
- consist in AND, OR and NOT nested expressions, forming a tree with
- simple relations as leaves. The simple relations test is a field
- in an event is equal, not equal, smaller, smaller or equal, larger, or
- larger or equal to a specified value.
-*/
-
-/*
- * YET TO BE ANSWERED
- * - none yet
+/*! \file lttv/lttv/filter.c
+ * \brief Defines the core filter of application
+ *
+ * consist in AND, OR and NOT nested expressions, forming a tree with
+ * simple relations as leaves. The simple relations test if a field
+ * in an event is equal, not equal, smaller, smaller or equal, larger, or
+ * larger or equal to a specified value.
+ *
+ * Fields specified in a simple expression can take following
+ * values
+ *
+ * \verbatim
+ * LttvTracefileContext{}
+ * |->event\
+ * | |->name (String, converted to GQuark)
+ * | |->category (String, not yet implemented)
+ * | |->time (LttTime)
+ * | |->tsc (LttCycleCount --> uint64)
+ * | |->fields
+ * | |->"event name"
+ * | |->"field name"
+ * | |->"sub-field name"
+ * | |->...
+ * | |->"leaf-field name" (field type)
+ * |->tracefile
+ * | |->name (String, converted to GQuark)
+ * |->trace
+ * | |->name (String, converted to GQuark)
+ * |->state
+ * |->pid (uint64)
+ * |->ppid (uint64)
+ * |->creation_time (LttTime)
+ * |->insertion_time (LttTime)
+ * |->process_name (String, converted to GQuark)
+ * |->execution_mode (LttvExecutionMode)
+ * |->execution_submode (LttvExecutionSubmode)
+ * |->process_status (LttvProcessStatus)
+ * |->cpu (GQuark)
+ * \endverbatim
*/
/*
- * TODO
+ * \todo
* - refine switch of expression in multiple uses functions
- * - remove the idle expressions in the tree ****
- * - add the current simple expression to the tree
- * * clear the field_path array after use
+ * - remove the idle expressions in the tree
*/
#include <lttv/filter.h>
-#include <ltt/time.h>
-
-/*
-GQuark
- LTTV_FILTER_TRACE,
- LTTV_FILTER_TRACESET,
- LTTV_FILTER_TRACEFILE,
- LTTV_FILTER_STATE,
- LTTV_FILTER_EVENT,
- LTTV_FILTER_NAME,
- LTTV_FILTER_CATEGORY,
- LTTV_FILTER_TIME,
- LTTV_FILTER_TSC,
- LTTV_FILTER_PID,
- LTTV_FILTER_PPID,
- LTTV_FILTER_C_TIME,
- LTTV_FILTER_I_TIME,
- LTTV_FILTER_P_NAME,
- LTTV_FILTER_EX_MODE,
- LTTV_FILTER_EX_SUBMODE,
- LTTV_FILTER_P_STATUS,
- LTTV_FILTER_CPU;
-*/
-
/**
* @fn LttvSimpleExpression* lttv_simple_expression_new()
}
/**
- * @fn gboolean lttv_simple_expression_add_field(GPtrArray*,LttvSimpleExpression*)
+ * @fn gboolean lttv_simple_expression_assign_field(GPtrArray*,LttvSimpleExpression*)
*
* Parse through filtering field hierarchy as specified
* by user. This function compares each value to
* Sets the function pointer for the current
* Simple Expression
* @param se current simple expression
+ * @param op current operator
* @return success/failure of operation
*/
gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) {
case LTTV_FILTER_TRACEFILE_NAME:
case LTTV_FILTER_STATE_P_NAME:
case LTTV_FILTER_EVENT_NAME:
+ case LTTV_FILTER_STATE_CPU:
switch(op) {
case LTTV_FIELD_EQ:
se->op = lttv_apply_op_eq_quark;
case LTTV_FILTER_STATE_EX_MODE:
case LTTV_FILTER_STATE_EX_SUBMODE:
case LTTV_FILTER_STATE_P_STATUS:
+ case LTTV_FILTER_EVENT_TSC:
switch(op) {
case LTTV_FIELD_EQ:
se->op = lttv_apply_op_eq_uint64;
case LTTV_FILTER_STATE_CT:
case LTTV_FILTER_STATE_IT:
case LTTV_FILTER_EVENT_TIME:
- case LTTV_FILTER_EVENT_TSC:
switch(op) {
case LTTV_FIELD_EQ:
se->op = lttv_apply_op_eq_ltttime;
}
/**
- * @fn void lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
+ * @fn gboolean lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
*
* Assign the value field to the current LttvSimpleExpression
* @param se pointer to the current LttvSimpleExpression
*/
gboolean lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value) {
-// g_print("se->value:%s\n",value);
unsigned i;
gboolean is_double = FALSE;
LttTime t = ltt_time_zero;
case LTTV_FILTER_TRACEFILE_NAME:
case LTTV_FILTER_STATE_P_NAME:
case LTTV_FILTER_EVENT_NAME:
+ case LTTV_FILTER_STATE_CPU:
// se->value.v_string = value;
- se->value.v_uint32 = g_quark_to_string(value);
+ se->value.v_uint32 = g_quark_from_string(value);
g_free(value);
break;
/*
case LTTV_FILTER_STATE_EX_MODE:
case LTTV_FILTER_STATE_EX_SUBMODE:
case LTTV_FILTER_STATE_P_STATUS:
+ case LTTV_FILTER_EVENT_TSC:
se->value.v_uint64 = atoi(value);
g_free(value);
break;
case LTTV_FILTER_STATE_CT:
case LTTV_FILTER_STATE_IT:
case LTTV_FILTER_EVENT_TIME:
- case LTTV_FILTER_EVENT_TSC:
//se->value.v_double = atof(value);
/*
* parsing logic could be optimised,
lttv_simple_expression_destroy(LttvSimpleExpression* se) {
// g_free(se->value);
- switch(se->field) {
- case LTTV_FILTER_TRACE_NAME:
- case LTTV_FILTER_TRACEFILE_NAME:
- case LTTV_FILTER_STATE_P_NAME:
- case LTTV_FILTER_EVENT_NAME:
- g_free(se->value.v_string);
- break;
- }
+// switch(se->field) {
+// case LTTV_FILTER_TRACE_NAME:
+// case LTTV_FILTER_TRACEFILE_NAME:
+// case LTTV_FILTER_STATE_P_NAME:
+// case LTTV_FILTER_EVENT_NAME:
+// g_free(se->value.v_string);
+// break;
+// }
g_free(se);
}
}
/**
- * @fn gboolean lttv_apply_op_eq_uint64(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
*
* Applies the 'equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_eq_uint32(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
*
* Applies the 'equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_eq_uint16(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
*
* Applies the 'equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_eq_double(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
*
* Applies the 'equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_eq_string(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
*
* Applies the 'equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_eq_quark(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_eq_quark(gpointer,LttvFieldValue)
*
* Applies the 'equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_eq_ltttime(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_eq_ltttime(gpointer,LttvFieldValue)
*
* Applies the 'equal' operator to the
* specified structure and value
*/
gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2) {
LttTime* r = (LttTime*) v1;
-// return ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec == v2.v_ltttime.tv_nsec));
return ltt_time_compare(*r, v2.v_ltttime)==0?1:0;
}
/**
- * @fn gboolean lttv_apply_op_ne_uint64(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
*
* Applies the 'not equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ne_uint32(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
*
* Applies the 'not equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ne_uint16(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
*
* Applies the 'not equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ne_double(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
*
* Applies the 'not equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ne_string(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
*
* Applies the 'not equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ne_quark(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ne_quark(gpointer,LttvFieldValue)
*
* Applies the 'not equal' operator to the
* specified structure and value
/**
- * @fn gboolean lttv_apply_op_ne_ltttime(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ne_ltttime(gpointer,LttvFieldValue)
*
* Applies the 'not equal' operator to the
* specified structure and value
/**
- * @fn gboolean lttv_apply_op_lt_uint64(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
*
* Applies the 'lower than' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_lt_uint32(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
*
* Applies the 'lower than' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_lt_uint16(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
*
* Applies the 'lower than' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_lt_double(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
*
* Applies the 'lower than' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_lt_ltttime(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_lt_ltttime(gpointer,LttvFieldValue)
*
* Applies the 'lower than' operator to the
* specified structure and value
/**
- * @fn gboolean lttv_apply_op_le_uint64(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
*
* Applies the 'lower or equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_le_uint32(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
*
* Applies the 'lower or equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_le_uint16(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
*
* Applies the 'lower or equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_le_double(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
*
* Applies the 'lower or equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_le_ltttime(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_le_ltttime(gpointer,LttvFieldValue)
*
* Applies the 'lower or equal' operator to the
* specified structure and value
/**
- * @fn gboolean lttv_apply_op_gt_uint64(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
*
* Applies the 'greater than' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_gt_uint32(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
*
* Applies the 'greater than' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_gt_uint16(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
*
* Applies the 'greater than' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_gt_double(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
*
* Applies the 'greater than' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_gt_ltttime(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_gt_ltttime(gpointer,LttvFieldValue)
*
* Applies the 'greater than' operator to the
* specified structure and value
/**
- * @fn gboolean lttv_apply_op_ge_uint64(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
*
* Applies the 'greater or equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ge_uint32(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
*
* Applies the 'greater or equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ge_uint16(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
*
* Applies the 'greater or equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ge_double(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
*
* Applies the 'greater or equal' operator to the
* specified structure and value
}
/**
- * @fn gboolean lttv_apply_op_ge_ltttime(const gpointer,LttvFieldValue)
+ * @fn gboolean lttv_apply_op_ge_ltttime(gpointer,LttvFieldValue)
*
* Applies the 'greater or equal' operator to the
* specified structure and value
/**
- * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*)
- *
* Makes a copy of the current filter tree
* @param tree pointer to the current tree
* @return new copy of the filter tree
}
/**
- * @fn LttvFilter* lttv_filter_clone(LttvFilter*)
- *
* Makes a copy of the current filter
* @param filter pointer to the current filter
* @return new copy of the filter
LttvFilter* newfilter = g_new(LttvFilter,1);
- // newfilter->expression = g_new(char,1)
strcpy(newfilter->expression,filter->expression);
newfilter->head = lttv_filter_tree_clone(filter->head);
/**
* @fn LttvFilter* lttv_filter_new()
*
- * Creates a new lttv_filter
- * @param expression filtering options string
- * @param t pointer to the current LttvTrace
- * @return the current lttv_filter or NULL if error
+ * Creates a new LttvFilter
+ * @return the current LttvFilter or NULL if error
*/
LttvFilter*
lttv_filter_new() {
LttvFilter* filter = g_new(LttvFilter,1);
filter->expression = NULL;
filter->head = NULL;
+
+ return filter;
}
* @param expression string that must be appended
* @return Success/Failure of operation
*/
-gboolean lttv_filter_append_expression(LttvFilter* filter, char *expression) {
+gboolean lttv_filter_append_expression(LttvFilter* filter, const char *expression) {
if(expression == NULL) return FALSE;
- if(filter == NULL) {
- filter = lttv_filter_new();
- filter->expression = expression;
- } else if(filter->expression == NULL) {
- filter->expression = expression;
- } else {
- filter->expression = g_strconcat(filter->expression,"&",expression);
-
- /* clear expression */
- g_free(expression);
- }
+ if(filter == NULL) return FALSE;
+ GString* s = g_string_new("");
+ if(filter->expression != NULL) {
+ g_string_append(s,filter->expression);
+ g_string_append_c(s,'&');
+ }
+ g_string_append(s,expression);
+
+ g_free(filter->expression);
+ filter->expression = g_string_free(s,FALSE);
+
+ /* TRUE if construction of tree proceeded without errors */
return lttv_filter_update(filter);
}
}
/**
- * @fn gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
- *
* Global parsing function for the current
* LttvFilterTree
- * @param tree pointer to the current LttvFilterTree
+ * @param t pointer to the current LttvFilterTree
* @param event current LttEvent, NULL if not used
* @param tracefile current LttTracefile, NULL if not used
* @param trace current LttTrace, NULL if not used
}
/**
- * @fn gboolean lttv_filter_tree_parse_branch(LttvFilterTree*,LttEvent*,LttTracefile*,LttTrace*,LttvProcessState*,LttvTracefileContext*)
- *
* This function parses a particular branch of the tree
- * @param tree pointer to the current LttvFilterTree
+ * @param se pointer to the current LttvSimpleExpression
* @param event current LttEvent, NULL if not used
* @param tracefile current LttTracefile, NULL if not used
* @param trace current LttTrace, NULL if not used
case LTTV_FILTER_TRACE_NAME:
if(trace == NULL) return TRUE;
else {
- GQuark quark = g_quark_to_string(ltt_trace_name(trace));
+ char* trace_name = ltt_trace_name(trace);
+ GQuark quark = g_quark_from_string(trace_name);
return se->op((gpointer)&quark,v);
}
break;
case LTTV_FILTER_TRACEFILE_NAME:
if(tracefile == NULL) return TRUE;
else {
- GQuark quark = g_quark_to_string(ltt_tracefile_name(tracefile));
+ char* tracefile_name = ltt_tracefile_name(tracefile);
+ GQuark quark = g_quark_from_string(tracefile_name);
return se->op((gpointer)&quark,v);
}
break;
*/
if(state == NULL) return TRUE;
else {
- GQuark quark = g_quark_to_string(state->name);
+ GQuark quark = state->name;
return se->op((gpointer)&quark,v);
}
break;
case LTTV_FILTER_STATE_CPU:
if(context == NULL) return TRUE;
else {
- /* FIXME: not sure of that one */
- return se->op((gpointer)g_quark_to_string(((LttvTracefileState*)context)->cpu_name),v);
+ /* FIXME: not sure of that one */
+ GQuark quark = ((LttvTracefileState*)context)->cpu_name;
+ return se->op((gpointer)&quark,v);
}
break;
case LTTV_FILTER_EVENT_NAME:
else {
LttEventType* et;
et = ltt_event_eventtype(event);
- g_print("v:%s\n",ltt_eventtype_name(et));
- GQuark quark = g_quark_to_string(ltt_eventtype_name(et));
+ char* event_name = ltt_eventtype_name(et);
+ GQuark quark = g_quark_from_string(event_name);
return se->op((gpointer)&quark,v);
}
break;
}
break;
case LTTV_FILTER_EVENT_TSC:
-// if(event == NULL) return TRUE;
-// else {
-// double val = ltt_time_to_double(event->event_time);
-// return se->op((gpointer)&val,v);
-// }
- /*
- * FIXME: Where is event.tsc
- */
- return TRUE;
+ if(event == NULL) return TRUE;
+ else {
+ LttCycleCount count = ltt_event_cycle_count(event);
+ return se->op((gpointer)&count,v);
+ }
break;
case LTTV_FILTER_EVENT_FIELD:
/*
/**
- * @fn void lttv_print_tree(LttvFilterTree*)
- *
- * Debug
+ * Debug function. Prints tree memory allocation.
* @param t the pointer to the current LttvFilterTree
*/
void
}
/**
- * @fn Destroys the filter module and specific values
+ * Destroys the filter module and specific values
*/
static void module_destroy()
{