Statistics
| Branch: | Revision:

root / src / eventlog / filteredeventlog.h @ 842775ab

History | View | Annotate | Download (12.6 KB)

1
//=========================================================================
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 <deque>
22
#include "patternmatcher.h"
23
#include "matchexpression.h"
24
#include "eventlogdefs.h"
25
#include "ieventlog.h"
26
#include "eventlog.h"
27
#include "filteredevent.h"
28

    
29
NAMESPACE_BEGIN
30

    
31
/**
32
 * This is a "view" of the EventLog, including only a subset of events and their dependencies. This class
33
 * uses EventLog by delegation so that multiple instances might share the same EventLog object.
34
 * TODO: filtered event log must save extra info in the exported log file to be able to reproduce the
35
 * same in memory model for filtered message dependencies. These can be done by adding new tags to E lines.
36
 */
37
class EVENTLOG_API FilteredEventLog : public IEventLog
38
{
39
    protected:
40
        IEventLog *eventLog; // this will not be destructed because might be shared among multiple filtered event logs
41
        eventnumber_t approximateNumberOfEvents;
42
        double approximateMatchingEventRatio;
43

    
44
        // filter parameters
45
        eventnumber_t firstEventNumber; // the first event to be considered by the filter or -1
46
        eventnumber_t lastEventNumber; // the last event to be considered by the filter or -1
47

    
48
        // module filter
49
        bool enableModuleFilter;
50
        MatchExpression moduleExpression;
51
        std::vector<PatternMatcher> moduleNames;
52
        std::vector<PatternMatcher> moduleClassNames;
53
        std::vector<PatternMatcher> moduleNEDTypeNames;
54
        std::vector<int> moduleIds; // events outside these modules will be filtered out, NULL means include all
55

    
56
        // message filter
57
        bool enableMessageFilter;
58
        MatchExpression messageExpression;
59
        std::vector<PatternMatcher> messageNames;
60
        std::vector<PatternMatcher> messageClassNames;
61
        std::vector<long> messageIds;
62
        std::vector<long> messageTreeIds;
63
        std::vector<long> messageEncapsulationIds;
64
        std::vector<long> messageEncapsulationTreeIds;
65

    
66
        // trace filter
67
        eventnumber_t tracedEventNumber; // the event number from which causes and consequences are followed or -1
68
        bool traceCauses; // only when tracedEventNumber is given, includes events which cause the traced event even if through a chain of filtered events
69
        bool traceConsequences; // only when tracedEventNumber is given
70
        bool traceMessageReuses;
71
        bool traceSelfMessages;
72

    
73
        // collection limits
74
        bool collectMessageReuses; // if false message reuse dependencies will not be collected
75
        int maximumCauseDepth; // maximum depth of message dependencies considered when collecting causes
76
        int maximumNumberOfCauses; // maximum number of message dependencies collected for a single event
77
        int maximumCauseCollectionTime; // in milliseconds
78
        int maximumConsequenceDepth; // maximum depth of message dependencies considered when collecting consequences
79
        int maximumNumberOfConsequences; // maximum number of message dependencies collected for a single event
80
        int maximumConsequenceCollectionTime; // in milliseconds
81

    
82
        // internal state
83
        typedef std::map<eventnumber_t, FilteredEvent *> EventNumberToFilteredEventMap;
84
        EventNumberToFilteredEventMap eventNumberToFilteredEventMap;
85

    
86
        typedef std::map<eventnumber_t, bool> EventNumberToBooleanMap;
87
        EventNumberToBooleanMap eventNumberToFilterMatchesFlagMap; // a cache of whether the given event number matches the filter or not
88
        EventNumberToBooleanMap eventNumberToTraceableEventFlagMap;
89
        std::deque<eventnumber_t> unseenTracedEventCauseEventNumbers; // the remaining cause event number of the traced event that is to be visited
90
        std::deque<eventnumber_t> unseenTracedEventConsequenceEventNumbers; // the remaining consequence event number of the traced event that is to be visited
91

    
92
        FilteredEvent *firstMatchingEvent;
93
        FilteredEvent *lastMatchingEvent;
94

    
95
    public:
96
        FilteredEventLog(IEventLog *eventLog);
97
        virtual ~FilteredEventLog();
98

    
99
    public:
100
        eventnumber_t getFirstEventNumber() { return firstEventNumber; }
101
        void setFirstEventNumber(eventnumber_t firstEventNumber) { this->firstEventNumber = firstEventNumber; }
102
        eventnumber_t getLastEventNumber() { return lastEventNumber; }
103
        void setLastEventNumber(eventnumber_t lastEventNumber) { this->lastEventNumber = lastEventNumber; }
104

    
105
        bool getCollectMessageReuses() { return collectMessageReuses; }
106
        void setCollectMessageReuses(bool collectMessageReuses) { this->collectMessageReuses = collectMessageReuses; }
107

    
108
        void setEnableModuleFilter(bool enableModuleFilter) { this->enableModuleFilter = enableModuleFilter; }
109
        void setModuleExpression(const char *moduleExpression) { if (moduleExpression) this->moduleExpression.setPattern(moduleExpression, false, true, false); }
110
        void setModuleNames(std::vector<std::string> &moduleNames) { setPatternMatchers(this->moduleNames, moduleNames, true); }
111
        void setModuleClassNames(std::vector<std::string> &moduleClassNames) { setPatternMatchers(this->moduleClassNames, moduleClassNames); }
112
        void setModuleNEDTypeNames(std::vector<std::string> &moduleNEDTypeNames) { setPatternMatchers(this->moduleNEDTypeNames, moduleNEDTypeNames); }
113
        void setModuleIds(std::vector<int> &moduleIds) { this->moduleIds = moduleIds; }
114

    
115
        void setEnableMessageFilter(bool enableMessageFilter) { this->enableMessageFilter = enableMessageFilter; }
116
        void setMessageExpression(const char *messageExpression) { if (messageExpression) this->messageExpression.setPattern(messageExpression, false, true, false); }
117
        void setMessageNames(std::vector<std::string> &messageNames) { setPatternMatchers(this->messageNames, messageNames); }
118
        void setMessageClassNames(std::vector<std::string> &messageClassNames) { setPatternMatchers(this->messageClassNames, messageClassNames); }
119
        void setMessageIds(std::vector<long> &messageIds) { this->messageIds = messageIds; }
120
        void setMessageTreeIds(std::vector<long> &messageTreeIds) { this->messageTreeIds = messageTreeIds; }
121
        void setMessageEncapsulationIds(std::vector<long> &messageEncapsulationIds) { this->messageEncapsulationIds = messageEncapsulationIds; }
122
        void setMessageEncapsulationTreeIds(std::vector<long> &messageEncapsulationTreeIds) { this->messageEncapsulationTreeIds = messageEncapsulationTreeIds; }
123

    
124
        void setTracedEventNumber(eventnumber_t tracedEventNumber);
125
        void setTraceCauses(bool traceCauses) { this->traceCauses = traceCauses; }
126
        void setTraceConsequences(bool traceConsequences) { this->traceConsequences = traceConsequences; }
127
        void setTraceSelfMessages(bool traceSelfMessages) { this->traceSelfMessages = traceSelfMessages; }
128
        void setTraceMessageReuses(bool traceMessageReuses) { this->traceMessageReuses = traceMessageReuses; }
129

    
130
        IEventLog *getEventLog() { return eventLog; }
131

    
132
        int getMaximumCauseDepth() { return maximumCauseDepth; }
133
        void setMaximumCauseDepth(int maximumCauseDepth) { this->maximumCauseDepth = maximumCauseDepth; }
134
        int getMaximumNumberOfCauses() { return maximumNumberOfCauses; }
135
        void setMaximumNumberOfCauses(int maximumNumberOfCauses) { this->maximumNumberOfCauses = maximumNumberOfCauses; }
136
        int getMaximumCauseCollectionTime() { return maximumCauseCollectionTime; }
137
        void setMaximumCauseCollectionTime(int maximumCauseCollectionTime) { this->maximumCauseCollectionTime = maximumCauseCollectionTime; }
138

    
139
        int getMaximumConsequenceDepth() { return maximumConsequenceDepth; }
140
        void setMaximumConsequenceDepth(int maximumConsequenceDepth) { this->maximumConsequenceDepth = maximumConsequenceDepth; }
141
        int getMaximumNumberOfConsequences() { return maximumNumberOfConsequences; }
142
        void setMaximumNumberOfConsequences(int maximumNumberOfConsequences) { this->maximumNumberOfConsequences = maximumNumberOfConsequences; }
143
        int getMaximumConsequenceCollectionTime() { return maximumConsequenceCollectionTime; }
144
        void setMaximumConsequenceCollectionTime(int maximumConsequenceCollectionTime) { this->maximumConsequenceCollectionTime = maximumConsequenceCollectionTime; }
145

    
146
        bool matchesFilter(IEvent *event);
147
        bool matchesModuleCreatedEntry(ModuleCreatedEntry *moduleCreatedEntry);
148
        FilteredEvent *getMatchingEventInDirection(eventnumber_t startEventNumber, bool forward, eventnumber_t stopEventNumber = -1);
149
        FilteredEvent *getMatchingEventInDirection(IEvent *event, bool forward, eventnumber_t stopEventNumber = -1);
150

    
151
        // IEventLog interface
152
        virtual ProgressMonitor setProgressMonitor(ProgressMonitor progressMonitor) { return eventLog->setProgressMonitor(progressMonitor); }
153
        virtual void setProgressCallInterval(double seconds) { eventLog->setProgressCallInterval(seconds); }
154
        virtual void progress() { eventLog->progress(); }
155
        virtual void synchronize(FileReader::FileChangedState change);
156
        virtual int getKeyframeBlockSize() { return eventLog->getKeyframeBlockSize(); }
157
        virtual FileReader *getFileReader() { return eventLog->getFileReader(); }
158
        virtual eventnumber_t getNumParsedEvents() { return eventLog->getNumParsedEvents(); }
159
        virtual std::set<const char *>& getMessageNames() { return eventLog->getMessageNames(); }
160
        virtual std::set<const char *>& getMessageClassNames() { return eventLog->getMessageClassNames(); }
161
        virtual int getNumModuleCreatedEntries() { return eventLog->getNumModuleCreatedEntries(); }
162
        virtual std::vector<ModuleCreatedEntry *> getModuleCreatedEntries() { return eventLog->getModuleCreatedEntries(); }
163
        virtual ModuleCreatedEntry *getModuleCreatedEntry(int moduleId) { return eventLog->getModuleCreatedEntry(moduleId); }
164
        virtual GateCreatedEntry *getGateCreatedEntry(int moduleId, int gateId) { return eventLog->getGateCreatedEntry(moduleId, gateId); }
165
        virtual SimulationBeginEntry *getSimulationBeginEntry() { return eventLog->getSimulationBeginEntry(); }
166

    
167
        virtual bool isEmpty();
168
        virtual FilteredEvent *getFirstEvent();
169
        virtual FilteredEvent *getLastEvent();
170
        virtual FilteredEvent *getNeighbourEvent(IEvent *event, eventnumber_t distance = 1);
171
        virtual FilteredEvent *getEventForEventNumber(eventnumber_t eventNumber, MatchKind matchKind = EXACT, bool useCacheOnly = false);
172
        virtual FilteredEvent *getEventForSimulationTime(simtime_t simulationTime, MatchKind matchKind = EXACT, bool useCacheOnly = false);
173

    
174
        virtual EventLogEntry *findEventLogEntry(EventLogEntry *start, const char *search, bool forward, bool caseSensitive);
175

    
176
        virtual eventnumber_t getApproximateNumberOfEvents();
177
        virtual double getApproximatePercentageForEventNumber(eventnumber_t eventNumber);
178
        virtual FilteredEvent *getApproximateEventAt(double percentage);
179

    
180
    protected:
181
        /**
182
         * Caches the given filtered event in the event cache if not present yet.
183
         * The event must be known to match this filter.
184
         */
185
        FilteredEvent *cacheFilteredEvent(eventnumber_t eventNumber);
186

    
187
        /**
188
         * Checks whether the given event matches this filter.
189
         */
190
        bool matchesEvent(IEvent *event);
191
        bool matchesDependency(IEvent *event);
192
        bool matchesBeginSendEntry(BeginSendEntry *beginSendEntry);
193
        bool matchesExpression(MatchExpression &matchExpression, EventLogEntry *eventLogEntry);
194
        bool matchesPatterns(std::vector<PatternMatcher> &patterns, const char *str);
195

    
196
        template <typename T> bool matchesList(std::vector<T> &elements, T element);
197
        bool isCauseOfTracedEvent(IEvent *cause);
198
        bool isConsequenceOfTracedEvent(IEvent *consequence);
199
        double getApproximateMatchingEventRatio();
200
        void setPatternMatchers(std::vector<PatternMatcher> &patternMatchers, std::vector<std::string> &patterns, bool dottedPath = false);
201

    
202
        void clearInternalState();
203
        void deleteConsequences();
204
        void deleteAllocatedObjects();
205
        bool isAncestorModuleCreatedEntry(ModuleCreatedEntry *ancestor, ModuleCreatedEntry *descendant);
206
};
207

    
208
NAMESPACE_END
209

    
210

    
211
#endif