Statistics
| Branch: | Revision:

root / src / eventlog / filteredeventlog.h @ 12288d0e

History | View | Annotate | Download (13 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  FILTEREDEVENTLOG.H - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Levente Meszaros
7
//
8
//=========================================================================
9
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16
17
#ifndef __FILTEREDEVENTLOG_H_
18
#define __FILTEREDEVENTLOG_H_
19
20
#include <sstream>
21
#include "patternmatcher.h"
22
#include "matchexpression.h"
23
#include "eventlogdefs.h"
24
#include "ieventlog.h"
25
#include "eventlog.h"
26
#include "filteredevent.h"
27
28
NAMESPACE_BEGIN
29
30
/**
31
 * This is a "view" of the EventLog, including only a subset of events and their dependencies. This class
32
 * uses EventLog by delegation so that multiple instances might share the same EventLog object.
33
 * TODO: filtered event log must save extra info in the exported log file to be able to reproduce the
34
 * same in memory model for filtered message dependencies. These can be done by adding new tags to E lines.
35
 */
36
class EVENTLOG_API FilteredEventLog : public IEventLog
37
{
38
    protected:
39
        IEventLog *eventLog; // this will not be destructed because might be shared among multiple filtered event logs
40
        eventnumber_t approximateNumberOfEvents;
41
        double approximateMatchingEventRatio;
42
43
        // filter parameters
44
        eventnumber_t firstEventNumber; // the first event to be considered by the filter or -1
45
        eventnumber_t lastEventNumber; // the last event to be considered by the filter or -1
46
47
        // module filter
48
        bool enableModuleFilter;
49
        MatchExpression moduleExpression;
50
        std::vector<PatternMatcher> moduleNames;
51
        std::vector<PatternMatcher> moduleClassNames;
52
        std::vector<PatternMatcher> moduleNEDTypeNames;
53
        std::vector<int> moduleIds; // events outside these modules will be filtered out, NULL means include all
54
55
        // message filter
56
        bool enableMessageFilter;
57
        MatchExpression messageExpression;
58
        std::vector<PatternMatcher> messageNames;
59
        std::vector<PatternMatcher> messageClassNames;
60
        std::vector<long> messageIds;
61
        std::vector<long> messageTreeIds;
62
        std::vector<long> messageEncapsulationIds;
63
        std::vector<long> messageEncapsulationTreeIds;
64
65
        // trace filter
66
        eventnumber_t tracedEventNumber; // the event number from which causes and consequences are followed or -1
67
        bool traceCauses; // only when tracedEventNumber is given, includes events which cause the traced event even if through a chain of filtered events
68
        bool traceConsequences; // only when tracedEventNumber is given
69
        bool traceMessageReuses;
70
        bool traceSelfMessages;
71
72
        // collection limits
73
        bool collectMessageReuses; // if false message reuse dependencies will not be collected
74
        int maximumCauseDepth; // maximum depth of message dependencies considered when collecting causes
75
        int maximumNumberOfCauses; // maximum number of message dependencies collected for a single event
76
        int maximumCauseCollectionTime; // in milliseconds
77
        int maximumConsequenceDepth; // maximum depth of message dependencies considered when collecting consequences
78
        int maximumNumberOfConsequences; // maximum number of message dependencies collected for a single event
79
        int maximumConsequenceCollectionTime; // in milliseconds
80
81
        // internal state
82
        typedef std::map<eventnumber_t, FilteredEvent *> EventNumberToFilteredEventMap;
83
        EventNumberToFilteredEventMap eventNumberToFilteredEventMap;
84
85
        typedef std::map<eventnumber_t, bool> EventNumberToBooleanMap;
86
        EventNumberToBooleanMap eventNumberToFilterMatchesFlagMap; // a cache of whether the given event number matches the filter or not
87
        EventNumberToBooleanMap eventNumberToTraceableEventFlagMap;
88
89
        FilteredEvent *firstMatchingEvent;
90
        FilteredEvent *lastMatchingEvent;
91
92
    public:
93
        FilteredEventLog(IEventLog *eventLog);
94
        ~FilteredEventLog();
95
96
    public:
97
        eventnumber_t getFirstEventNumber() { return firstEventNumber; }
98
        void setFirstEventNumber(eventnumber_t firstEventNumber) { this->firstEventNumber = firstEventNumber; }
99
        eventnumber_t getLastEventNumber() { return lastEventNumber; }
100
        void setLastEventNumber(eventnumber_t lastEventNumber) { this->lastEventNumber = lastEventNumber; }
101
102
        bool getCollectMessageReuses() { return collectMessageReuses; }
103
        void setCollectMessageReuses(bool collectMessageReuses) { this->collectMessageReuses = collectMessageReuses; }
104
105
        void setEnableModuleFilter(bool enableModuleFilter) { this->enableModuleFilter = enableModuleFilter; }
106
        void setModuleExpression(const char *moduleExpression) { if (moduleExpression) this->moduleExpression.setPattern(moduleExpression, false, true, false); }
107
        void setModuleNames(std::vector<std::string> &moduleNames) { setPatternMatchers(this->moduleNames, moduleNames, true); }
108
        void setModuleClassNames(std::vector<std::string> &moduleClassNames) { setPatternMatchers(this->moduleClassNames, moduleClassNames); }
109
        void setModuleNEDTypeNames(std::vector<std::string> &moduleNEDTypeNames) { setPatternMatchers(this->moduleNEDTypeNames, moduleNEDTypeNames); }
110
        void setModuleIds(std::vector<int> &moduleIds) { this->moduleIds = moduleIds; }
111
112
        void setEnableMessageFilter(bool enableMessageFilter) { this->enableMessageFilter = enableMessageFilter; }
113
        void setMessageExpression(const char *messageExpression) { if (messageExpression) this->messageExpression.setPattern(messageExpression, false, true, false); }
114
        void setMessageNames(std::vector<std::string> &messageNames) { setPatternMatchers(this->messageNames, messageNames); }
115
        void setMessageClassNames(std::vector<std::string> &messageClassNames) { setPatternMatchers(this->messageClassNames, messageClassNames); }
116
        void setMessageIds(std::vector<long> &messageIds) { this->messageIds = messageIds; }
117
        void setMessageTreeIds(std::vector<long> &messageTreeIds) { this->messageTreeIds = messageTreeIds; }
118
        void setMessageEncapsulationIds(std::vector<long> &messageEncapsulationIds) { this->messageEncapsulationIds = messageEncapsulationIds; }
119
        void setMessageEncapsulationTreeIds(std::vector<long> &messageEncapsulationTreeIds) { this->messageEncapsulationTreeIds = messageEncapsulationTreeIds; }
120
121
        void setTracedEventNumber(eventnumber_t tracedEventNumber) { this->tracedEventNumber = tracedEventNumber; }
122
        void setTraceCauses(bool traceCauses) { this->traceCauses = traceCauses; }
123
        void setTraceConsequences(bool traceConsequences) { this->traceConsequences = traceConsequences; }
124
        void setTraceSelfMessages(bool traceSelfMessages) { this->traceSelfMessages = traceSelfMessages; }
125
        void setTraceMessageReuses(bool traceMessageReuses) { this->traceMessageReuses = traceMessageReuses; }
126
127
        IEventLog *getEventLog() { return eventLog; }
128
129
        int getMaximumCauseDepth() { return maximumCauseDepth; }
130
        void setMaximumCauseDepth(int maximumCauseDepth) { this->maximumCauseDepth = maximumCauseDepth; }
131
        int getMaximumNumberOfCauses() { return maximumNumberOfCauses; }
132
        void setMaximumNumberOfCauses(int maximumNumberOfCauses) { this->maximumNumberOfCauses = maximumNumberOfCauses; }
133
        int getMaximumCauseCollectionTime() { return maximumCauseCollectionTime; }
134
        void setMaximumCauseCollectionTime(int maximumCauseCollectionTime) { this->maximumCauseCollectionTime = maximumCauseCollectionTime; }
135
136
        int getMaximumConsequenceDepth() { return maximumConsequenceDepth; }
137
        void setMaximumConsequenceDepth(int maximumConsequenceDepth) { this->maximumConsequenceDepth = maximumConsequenceDepth; }
138
        int getMaximumNumberOfConsequences() { return maximumNumberOfConsequences; }
139
        void setMaximumNumberOfConsequences(int maximumNumberOfConsequences) { this->maximumNumberOfConsequences = maximumNumberOfConsequences; }
140
        int getMaximumConsequenceCollectionTime() { return maximumConsequenceCollectionTime; }
141
        void setMaximumConsequenceCollectionTime(int maximumConsequenceCollectionTime) { this->maximumConsequenceCollectionTime = maximumConsequenceCollectionTime; }
142
143
        bool matchesFilter(IEvent *event);
144
        bool matchesModuleCreatedEntry(ModuleCreatedEntry *moduleCreatedEntry);
145
        FilteredEvent *getMatchingEventInDirection(eventnumber_t startEventNumber, bool forward, eventnumber_t stopEventNumber = -1);
146
        FilteredEvent *getMatchingEventInDirection(IEvent *event, bool forward, eventnumber_t stopEventNumber = -1);
147
148
        // IEventLog interface
149
        virtual ProgressMonitor setProgressMonitor(ProgressMonitor progressMonitor) { return eventLog->setProgressMonitor(progressMonitor); }
150
        virtual void setProgressCallInterval(double seconds) { eventLog->setProgressCallInterval(seconds); }
151
        virtual void progress() { eventLog->progress(); }
152
        virtual void synchronize(FileReader::FileChangedState change);
153
        virtual FileReader *getFileReader() { return eventLog->getFileReader(); }
154
        virtual eventnumber_t getNumParsedEvents() { return eventLog->getNumParsedEvents(); }
155
        virtual std::set<const char *>& getMessageNames() { return eventLog->getMessageNames(); }
156
        virtual std::set<const char *>& getMessageClassNames() { return eventLog->getMessageClassNames(); }
157
        virtual int getNumModuleCreatedEntries() { return eventLog->getNumModuleCreatedEntries(); }
158
        virtual std::vector<ModuleCreatedEntry *> getModuleCreatedEntries() { return eventLog->getModuleCreatedEntries(); }
159
        virtual ModuleCreatedEntry *getModuleCreatedEntry(int moduleId) { return eventLog->getModuleCreatedEntry(moduleId); }
160
        virtual GateCreatedEntry *getGateCreatedEntry(int moduleId, int gateId) { return eventLog->getGateCreatedEntry(moduleId, gateId); }
161
        virtual SimulationBeginEntry *getSimulationBeginEntry() { return eventLog->getSimulationBeginEntry(); }
162
163
        virtual bool isEmpty();
164
        virtual FilteredEvent *getFirstEvent();
165
        virtual FilteredEvent *getLastEvent();
166 12288d0e Simon Tenbusch
167
        virtual Event *getFirstEventRealTime() {
168
            Assert(false);
169
            return NULL;
170
        }
171
        virtual Event *getLastEventRealTime() {
172
            Assert(false);
173
            return NULL;
174
        }
175
176
        virtual void setFirstEventRealTime(Event* e) {
177
            Assert(false);
178
        }
179
        virtual void setLastEventRealTime(Event* e){
180
            Assert(false);
181
        }
182
183 01873262 Georg Kunz
        virtual FilteredEvent *getNeighbourEvent(IEvent *event, eventnumber_t distance = 1);
184
        virtual FilteredEvent *getEventForEventNumber(eventnumber_t eventNumber, MatchKind matchKind = EXACT);
185
        virtual FilteredEvent *getEventForSimulationTime(simtime_t simulationTime, MatchKind matchKind = EXACT);
186
187
        virtual EventLogEntry *findEventLogEntry(EventLogEntry *start, const char *search, bool forward, bool caseSensitive);
188
189
        virtual eventnumber_t getApproximateNumberOfEvents();
190
        virtual double getApproximatePercentageForEventNumber(eventnumber_t eventNumber);
191
        virtual FilteredEvent *getApproximateEventAt(double percentage);
192
193
        virtual int getNumInitializationLogEntries() { return eventLog->getNumInitializationLogEntries(); }
194
        virtual EventLogEntry *getInitializationLogEntry(int index) { return eventLog->getInitializationLogEntry(index); }
195
        virtual void printInitializationLogEntries(FILE *file = stdout) {  eventLog->printInitializationLogEntries(file); }
196
197 81ad8b66 Georg Kunz
        virtual bool isLegacyTrace()  { return eventLog->isLegacyTrace(); }
198
199 01873262 Georg Kunz
    protected:
200
        /**
201
         * Caches the given filtered event in the event cache if not present yet.
202
         * The event must be known to match this filter.
203
         */
204
        FilteredEvent *cacheFilteredEvent(eventnumber_t eventNumber);
205
206
        /**
207
         * Checks whether the given event matches this filter.
208
         */
209
        bool matchesEvent(IEvent *event);
210
        bool matchesDependency(IEvent *event);
211
        bool matchesBeginSendEntry(BeginSendEntry *beginSendEntry);
212
        bool matchesExpression(MatchExpression &matchExpression, EventLogEntry *eventLogEntry);
213
        bool matchesPatterns(std::vector<PatternMatcher> &patterns, const char *str);
214
215
        template <typename T> bool matchesList(std::vector<T> &elements, T element);
216
        bool isCauseOfTracedEvent(IEvent *cause);
217
        bool isConsequenceOfTracedEvent(IEvent *consequence);
218
        double getApproximateMatchingEventRatio();
219
        void setPatternMatchers(std::vector<PatternMatcher> &patternMatchers, std::vector<std::string> &patterns, bool dottedPath = false);
220
221
        void deleteAllocatedObjects();
222
        void clearInternalState(FileReader::FileChangedState change = FileReader::OVERWRITTEN);
223
224
        bool isAncestorModuleCreatedEntry(ModuleCreatedEntry *ancestor, ModuleCreatedEntry *descendant);
225
};
226
227
NAMESPACE_END
228
229
230
#endif