(file) Return to TraceMemoryHandler.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 martin 1.5 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.6 //
  3 martin 1.5 // Licensed to The Open Group (TOG) under one or more contributor license
  4            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5            // this work for additional information regarding copyright ownership.
  6            // Each contributor licenses this file to you under the OpenPegasus Open
  7            // Source License; you may not use this file except in compliance with the
  8            // License.
  9 martin 1.6 //
 10 martin 1.5 // Permission is hereby granted, free of charge, to any person obtaining a
 11            // copy of this software and associated documentation files (the "Software"),
 12            // to deal in the Software without restriction, including without limitation
 13            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14            // and/or sell copies of the Software, and to permit persons to whom the
 15            // Software is furnished to do so, subject to the following conditions:
 16 martin 1.6 //
 17 martin 1.5 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.6 //
 20 martin 1.5 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.6 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.5 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24            // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.6 //
 28 martin 1.5 //////////////////////////////////////////////////////////////////////////
 29 thilo.boehm 1.1 //
 30                 //%/////////////////////////////////////////////////////////////////////////////
 31                 
 32                 
 33                 #ifndef Pegasus_TraceMemoryHandler_h
 34                 #define Pegasus_TraceMemoryHandler_h
 35                 
 36                 #include <cstdarg>
 37                 #include <cstdio>
 38                 #include <Pegasus/Common/String.h>
 39                 #include <Pegasus/Common/Linkage.h>
 40 thilo.boehm 1.4 #include <Pegasus/Common/Tracer.h>
 41 thilo.boehm 1.1 #include <Pegasus/Common/TraceHandler.h>
 42                 #include <Pegasus/Common/TraceFileHandler.h>
 43                 #include <Pegasus/Common/Mutex.h>
 44                 #include <Pegasus/Common/AtomicInt.h>
 45                 
 46                 PEGASUS_NAMESPACE_BEGIN
 47                 
 48                 /** TraceMemoryHandler implements tracing of messages to a memory buffer
 49                  */
 50                 #define PEGASUS_TRC_DEFAULT_BUFFER_SIZE_KB 10*1024
 51                 #define PEGASUS_TRC_BUFFER_EYE_CATCHER "PEGASUSMEMTRACE"
 52                 #define PEGASUS_TRC_BUFFER_EYE_CATCHER_LEN 16
 53 thilo.boehm 1.3 #define PEGASUS_TRC_BUFFER_TRUNC_MARKER "*TRUNC*"
 54                 #define PEGASUS_TRC_BUFFER_TRUNC_MARKER_LEN 7
 55                 #define PEGASUS_TRC_BUFFER_EOT_MARKER "*EOTRACE*"
 56                 #define PEGASUS_TRC_BUFFER_EOT_MARKER_LEN 9
 57                 
 58 thilo.boehm 1.1 class PEGASUS_COMMON_LINKAGE TraceMemoryHandler: public TraceHandler
 59                 {
 60                 public:
 61                 
 62                     /** Writes message with format string to the tracing facility
 63                         @param    message  message to be written
 64                         @param    msgLen   lenght of message without terminating '\0'
 65                         @param    fmt      printf style format string
 66                         @param    argList  variable argument list
 67                      */
 68                     virtual void handleMessage(const char* message,
 69                                                Uint32 msgLen,
 70                                                const char* fmt,
 71                                                va_list argList);
 72                 
 73                     /** Writes simple message to the tracing facility.
 74                         @param    message  message to be written
 75                      */
 76                     virtual void handleMessage(const char* message,
 77                                                Uint32 msgLen);
 78                 
 79 thilo.boehm 1.1     /** Flushes the trace
 80                      */
 81                     virtual void flushTrace();
 82                 
 83                     /** Dumps the complete content of the trace buffer to a file
 84                         @param    filename  name of the file where to dump the trace buffer
 85                      */
 86                     void dumpTraceBuffer(const char* filename);
 87                 
 88                     /** Tells an instance of the traceMemoryHandler that it will be destructed
 89                         soon and should accept no more requests for trace messages.
 90                      */
 91                     void die();
 92                 
 93 thilo.boehm 1.4     /*
 94                         Constructs a TraceMemoryHandler. No trace memory allocated.
 95                     */
 96 thilo.boehm 1.1     TraceMemoryHandler();
 97                 
 98                     virtual ~TraceMemoryHandler();
 99 kumpf       1.7 
100 thilo.boehm 1.1 private:
101                 
102                     /** The trace area is defined a struct to keep the following information
103                         together in memory, next the trace statementes:
104                         - eyecatcher to locate the trace buffer in a dump
105                         - the size of the trace buffer
106                         - the position after the last written trace statement
107                     */
108                     struct traceArea_t
109                     {
110                         char eyeCatcher[PEGASUS_TRC_BUFFER_EYE_CATCHER_LEN];
111                         Uint32 bufferSize;
112                         Uint32 nextPos;
113 kumpf       1.2         char* traceBuffer;
114 thilo.boehm 1.1     };
115                 
116                     char* _overflowBuffer;
117                     Uint32 _overflowBufferSize;
118                     struct traceArea_t *_traceArea;
119 kumpf       1.7     Uint32 _leftBytesInBuffer;
120 thilo.boehm 1.1 
121                     // Members used for serialization
122                     AtomicInt _inUseCounter;
123                     AtomicInt _lockCounter;
124                     Boolean _dying;
125                 
126                     // Members used for statistics only
127                     AtomicInt _contentionCount;
128                     Uint32    _numberOfLocksObtained;
129 kumpf       1.7 
130 thilo.boehm 1.1     // Name of a tracefile, in case we need to flush the buffer to a file
131                     char* _traceFileName;
132 kumpf       1.7 
133 thilo.boehm 1.1     /** Request to lock the memory buffer for writing a trace message.
134                         @return 1        OK, you got the lock
135                                 0        No lock was obtained, give up!!
136                     */
137                     Boolean _lockBufferAccess();
138                 
139                     /** Unlock the memory buffer when no longer used for writing.
140                     */
141                     void _unlockBufferAccess();
142                 
143                     /** Appends a fixed length message to be buffer
144                     */
145                     void _appendSimpleMessage(const char* message, Uint32 msgLen );
146 kumpf       1.7 
147 thilo.boehm 1.1     /** Appends a marker after the last trace message in the buffer
148                     */
149                     void _appendMarker();
150 kumpf       1.7 
151                     /** Memory buffer initialization routine
152 thilo.boehm 1.1     */
153 thilo.boehm 1.4     void _initializeTraceArea();
154 kumpf       1.7 
155 thilo.boehm 1.1 };
156                 
157                 PEGASUS_NAMESPACE_END
158                 
159                 #endif /* Pegasus_TraceMemoryHandler_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2