mathieu desnoyers : addition of lttv_filter api for Simon. breaks compile.
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.h
CommitLineData
9c312311 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
48f6f3c2 19#ifndef FILTER_H
20#define FILTER_H
21
31452f49 22#include <lttv/traceset.h>
a4c292d4 23#include <lttv/tracecontext.h>
24#include <lttv/state.h>
91ad3f0a 25#include <lttv/module.h>
a4c292d4 26#include <ltt/ltt.h>
27#include <ltt/event.h>
28
29#define AVERAGE_EXPRESSION_LENGTH 6
30#define MAX_FACTOR 1.5
31452f49 31
48f6f3c2 32/* A filter expression consists in nested AND, OR and NOT expressions
33 involving boolean relation (>, >=, =, !=, <, <=) between event fields and
34 specific values. It is compiled into an efficient data structure which
35 is used in functions to check if a given event or tracefile satisfies the
36 filter.
37
38 The grammar for filters is:
39
40 filter = expression
41
42 expression = "(" expression ")" | "!" expression |
43 expression "&&" expression | expression "||" expression |
44 simpleExpression
45
46 simpleExpression = fieldPath op value
47
48 fieldPath = fieldComponent [ "." fieldPath ]
49
50 fieldComponent = name [ "[" integer "]" ]
51
52 value = integer | double | string
53
54*/
55
1a7fa682 56extern GQuark
0769c82f 57 LTTV_FILTER_TRACE,
58 LTTV_FILTER_TRACESET,
59 LTTV_FILTER_TRACEFILE,
60 LTTV_FILTER_STATE,
91ad3f0a 61 LTTV_FILTER_EVENT,
62 LTTV_FILTER_NAME,
63 LTTV_FILTER_CATEGORY,
64 LTTV_FILTER_TIME,
65 LTTV_FILTER_TSC,
66 LTTV_FILTER_PID,
67 LTTV_FILTER_PPID,
68 LTTV_FILTER_C_TIME,
69 LTTV_FILTER_I_TIME,
70 LTTV_FILTER_P_NAME,
71 LTTV_FILTER_EX_MODE,
72 LTTV_FILTER_EX_SUBMODE,
73 LTTV_FILTER_P_STATUS,
74 LTTV_FILTER_CPU;
75
84a333d6 76/**
77 * @enum lttv_expression_op
78 */
79typedef enum _lttv_expression_op
80{
81 LTTV_FIELD_EQ, /** equal */
82 LTTV_FIELD_NE, /** not equal */
83 LTTV_FIELD_LT, /** lower than */
84 LTTV_FIELD_LE, /** lower or equal */
85 LTTV_FIELD_GT, /** greater than */
86 LTTV_FIELD_GE /** greater or equal */
87} lttv_expression_op;
88
89typedef enum _lttv_expression_type
90{
91 LTTV_EXPRESSION,
f4e9dd16 92 LTTV_SIMPLE_EXPRESSION,
93 LTTV_EXPRESSION_OP,
94 LTTV_UNDEFINED_EXPRESSION
84a333d6 95} lttv_expression_type;
96
f4e9dd16 97typedef enum _lttv_tree_element {
2a734d8e 98 LTTV_TREE_IDLE,
f4e9dd16 99 LTTV_TREE_NODE,
100 LTTV_TREE_LEAF
101} lttv_tree_element;
102
84a333d6 103typedef struct _lttv_simple_expression
104{
84a333d6 105 char *field_name;
f4e9dd16 106 lttv_expression_op op;
84a333d6 107 char *value;
108} lttv_simple_expression;
109
1a7fa682 110typedef enum _lttv_logical_op {
f4e9dd16 111 LTTV_LOGICAL_OR = 1, /* 1 */
112 LTTV_LOGICAL_AND = 1<<1, /* 2 */
113 LTTV_LOGICAL_NOT = 1<<2, /* 4 */
114 LTTV_LOGICAL_XOR = 1<<3 /* 8 */
1a7fa682 115} lttv_logical_op;
116
a4c292d4 117/*
1a7fa682 118 * Ah .. that's my tree
119 */
f4e9dd16 120//typedef struct _lttv_expression
121//{
1a7fa682 122// gboolean simple_expression;
f4e9dd16 123// int op;
124// lttv_expression_type type;
125// union {
126// struct lttv_expression *e;
127 // lttv_field_relation *se; /* --> simple expression */
128// } e;
129//} lttv_expression;
130
131typedef struct _lttv_expression {
1a7fa682 132 lttv_expression_type type;
133 union {
f4e9dd16 134 lttv_simple_expression *se;
135 int op;
1a7fa682 136 } e;
a4c292d4 137} lttv_expression;
1a7fa682 138
84a333d6 139typedef struct _lttv_filter_tree {
0cdc2470 140// lttv_expression* node;
141 int node;
f4e9dd16 142 lttv_tree_element left;
143 lttv_tree_element right;
144 union {
145 struct lttv_filter_tree* t;
0cdc2470 146 lttv_simple_expression* leaf;
f4e9dd16 147 } l_child;
148 union {
149 struct lttv_filter_tree* t;
0cdc2470 150 lttv_simple_expression* leaf;
f4e9dd16 151 } r_child;
84a333d6 152} lttv_filter_tree;
153
31452f49 154/**
155 * @struct lttv_filter
156 * ( will later contain a binary tree of filtering options )
157 */
91ad3f0a 158typedef struct _lttv_filter_t {
84a333d6 159 lttv_filter_tree* tree;
91ad3f0a 160} lttv_filter_t;
84a333d6 161
0769c82f 162
0cdc2470 163lttv_simple_expression* lttv_simple_expression_new();
164
f4e9dd16 165lttv_filter_tree* lttv_filter_tree_new();
166
167void lttv_filter_tree_destroy(lttv_filter_tree* tree);
168
0cdc2470 169void lttv_filter_tree_add_node(GPtrArray* stack, lttv_filter_tree* subtree, lttv_logical_op op);
170
f4e9dd16 171/* Parse field path contained in list */
172gboolean parse_field_path(GPtrArray* fp);
91ad3f0a 173
84a333d6 174gboolean parse_simple_expression(GString* expression);
48f6f3c2 175
48f6f3c2 176/* Compile the filter expression into an efficient data structure */
f4e9dd16 177lttv_filter_tree *lttv_filter_new(char *expression, LttvTraceState *tfs);
48f6f3c2 178
179/* Check if the tracefile or event satisfies the filter. The arguments are
180 declared as void * to allow these functions to be used as hooks. */
181
1601b365 182gboolean lttv_filter_tracefile(lttv_filter_tree *filter, LttTracefile *tracefile);
48f6f3c2 183
91ad3f0a 184gboolean lttv_filter_tracestate(lttv_filter_t *filter, LttvTraceState *tracestate);
1a7fa682 185
91ad3f0a 186gboolean lttv_filter_event(lttv_filter_t *filter, LttEvent *event);
48f6f3c2 187
188#endif // FILTER_H
189
This page took 0.037943 seconds and 4 git commands to generate.