1 thilo.boehm 1.1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 thilo.boehm 1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34
35 #ifndef Pegasus_TraceMemoryHandler_h
36 #define Pegasus_TraceMemoryHandler_h
37
38 #include <cstdarg>
39 #include <cstdio>
40 #include <Pegasus/Common/String.h>
41 #include <Pegasus/Common/Linkage.h>
42 #include <Pegasus/Common/TraceHandler.h>
43 thilo.boehm 1.1 #include <Pegasus/Common/TraceFileHandler.h>
44 #include <Pegasus/Common/Mutex.h>
45 #include <Pegasus/Common/AtomicInt.h>
46
47 PEGASUS_NAMESPACE_BEGIN
48
49 /** TraceMemoryHandler implements tracing of messages to a memory buffer
50 */
51 #define PEGASUS_TRC_DEFAULT_BUFFER_SIZE_KB 10*1024
52 #define PEGASUS_TRC_BUFFER_EYE_CATCHER "PEGASUSMEMTRACE"
53 #define PEGASUS_TRC_BUFFER_EYE_CATCHER_LEN 16
|
60 thilo.boehm 1.1
61 class PEGASUS_COMMON_LINKAGE TraceMemoryHandler: public TraceHandler
62 {
63 public:
64
65 /** Writes message with format string to the tracing facility
66 @param message message to be written
67 @param msgLen lenght of message without terminating '\0'
68 @param fmt printf style format string
69 @param argList variable argument list
70 */
71 virtual void handleMessage(const char* message,
72 Uint32 msgLen,
73 const char* fmt,
74 va_list argList);
75
76 /** Writes simple message to the tracing facility.
77 @param message message to be written
78 */
79 virtual void handleMessage(const char* message,
80 Uint32 msgLen);
81 thilo.boehm 1.1
82 /** Validates the File Path for the trace File
83 @param filePath full path of the file
84 @return 1 if the file path is valid
85 0 if the file path is invalid
86 */
87 virtual Boolean isValidMessageDestination(const char* traceFileName);
88
89 /** Sets the filename for the trace handler. In this implementation
90 we just keep the name around in case we have to flush the trace
91 buffer later on to somewhere.
92 @param destination tracer destination, e.g. file
93 @return 0 if the function is successful
94 1 if an error occurs
95 */
96 virtual Uint32 setMessageDestination(const char* destination);
97
98 /** Flushes the trace
99 */
100 virtual void flushTrace();
101
102 thilo.boehm 1.1 /** Dumps the complete content of the trace buffer to a file
103 @param filename name of the file where to dump the trace buffer
104 */
105 void dumpTraceBuffer(const char* filename);
106
107 /** Tells an instance of the traceMemoryHandler that it will be destructed
108 soon and should accept no more requests for trace messages.
109 */
110 void die();
111
112 /** Constructs a TraceMemoryHandler with a default buffer size.
113 */
114 TraceMemoryHandler();
115
116 /** Constructs a TraceMemoryHandler with a custom buffer size.
117 @param bufferSize size of the trace buffer in Kbyte
118 */
119 TraceMemoryHandler(Uint32 bufferSize);
120
121 virtual ~TraceMemoryHandler();
122
123 thilo.boehm 1.1 private:
124
125 /** The trace area is defined a struct to keep the following information
126 together in memory, next the trace statementes:
127 - eyecatcher to locate the trace buffer in a dump
128 - the size of the trace buffer
129 - the position after the last written trace statement
130 */
131 struct traceArea_t
132 {
133 char eyeCatcher[PEGASUS_TRC_BUFFER_EYE_CATCHER_LEN];
134 Uint32 bufferSize;
135 Uint32 nextPos;
|
137 thilo.boehm 1.1 };
138
139 char* _overflowBuffer;
140 Uint32 _overflowBufferSize;
141 struct traceArea_t *_traceArea;
142 Uint32 _leftBytesInBuffer;
143
144 // Members used for serialization
145 AtomicInt _inUseCounter;
146 AtomicInt _lockCounter;
147 Boolean _dying;
148
149 // Members used for statistics only
150 AtomicInt _contentionCount;
151 Uint32 _numberOfLocksObtained;
152
153 // Name of a tracefile, in case we need to flush the buffer to a file
154 char* _traceFileName;
155
156 /** Request to lock the memory buffer for writing a trace message.
157 @return 1 OK, you got the lock
158 thilo.boehm 1.1 0 No lock was obtained, give up!!
159 */
160 Boolean _lockBufferAccess();
161
162 /** Unlock the memory buffer when no longer used for writing.
163 */
164 void _unlockBufferAccess();
165
166 /** Appends a fixed length message to be buffer
167 */
168 void _appendSimpleMessage(const char* message, Uint32 msgLen );
169
170 /** Appends a marker after the last trace message in the buffer
171 */
172 void _appendMarker();
173
174 /** Memory buffer initialization routine
175 @param traceAreaSize the size of the used trace buffer
176 */
177 void _initialize( Uint32 traceAreaSize );
178
179 thilo.boehm 1.1 };
180
181 PEGASUS_NAMESPACE_END
182
183 #endif /* Pegasus_TraceMemoryHandler_h */
|