Statistics
| Branch: | Revision:

root / src / tkenv / logbuffer.h @ 79bb12dc

History | View | Annotate | Download (2.18 KB)

1
//==========================================================================
2
//  LOGBUFFER.H - part of
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//==========================================================================
8

    
9
/*--------------------------------------------------------------*
10
  Copyright (C) 1992-2008 Andras Varga
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 __LOGBUFFER_H
18
#define __LOGBUFFER_H
19

    
20
#include <string>
21
#include <list>
22
#include <vector>
23
#include <set>
24
#include "simtime_t.h"
25
#include "tkutil.h"
26

    
27
NAMESPACE_BEGIN
28

    
29
class cModule;
30

    
31
/**
32
 * Stores textual debug output from modules.
33
 */
34
class LogBuffer
35
{
36
  public:
37
    struct Entry {
38
        eventnumber_t eventNumber;
39
        simtime_t simtime;
40
        int *moduleIds;  // from this module up to the root; zero-terminated; NULL for info messages
41
        const char *banner;
42
        std::vector<const char *> lines;
43
        int numChars; // banner plus lines
44

    
45
        Entry() {eventNumber=0; simtime=0; moduleIds=NULL; banner=NULL; numChars=0;}
46
        ~Entry();
47
    };
48

    
49
  protected:
50
    size_t memLimit;
51
    size_t totalChars;
52
    size_t totalStrings;
53
    std::list<Entry> entries;
54
    size_t numEntries;  // gcc's list::size() is O(n)...
55

    
56
  protected:
57
    void discardIfMemoryLimitExceeded();
58
    size_t estimatedMemUsage() {return totalChars + 8*totalStrings + numEntries*(8+2*sizeof(void*)+sizeof(Entry)+32); }
59
    void fillEntry(Entry& entry, eventnumber_t e, simtime_t t, cModule *mod, const char *banner);
60

    
61
  public:
62
    LogBuffer(int memLimit=10*1024*1024);  // 10MB
63
    ~LogBuffer();
64

    
65
    void addEvent(eventnumber_t e, simtime_t t, cModule *moduleIds, const char *banner);
66
    void addLogLine(const char *text);
67
    void addInfo(const char *text);
68

    
69
    void setMemoryLimit(size_t limit);
70
    size_t getMemoryLimit()  {return memLimit;}
71

    
72
    const std::list<Entry>& getEntries() const {return entries;}
73
    size_t getNumEntries() const {return numEntries;}
74

    
75
    void dump() const;
76
};
77

    
78
NAMESPACE_END
79

    
80

    
81
#endif
82

    
83