1 martin 1.46 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.47 //
|
3 martin 1.46 // 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.47 //
|
10 martin 1.46 // 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.47 //
|
17 martin 1.46 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.47 //
|
20 martin 1.46 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.47 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.46 // 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.47 //
|
28 martin 1.46 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_Tracer_h
33 #define Pegasus_Tracer_h
34
|
35 marek 1.31 #include <cstdarg>
|
36 mike 1.2 #include <Pegasus/Common/String.h>
37 #include <Pegasus/Common/System.h>
38 #include <Pegasus/Common/Logger.h>
|
39 kumpf 1.12 #include <Pegasus/Common/InternalException.h>
|
40 r.kieninger 1.35 #include <Pegasus/Common/TraceHandler.h>
|
41 kumpf 1.11 #include <Pegasus/Common/Linkage.h>
|
42 sushma.fernandes 1.30 #include <Pegasus/Common/SharedPtr.h>
|
43 mike 1.2
44 PEGASUS_NAMESPACE_BEGIN
45
|
46 kumpf 1.41 /**
47 Trace component identifiers. This list must be kept in sync with the
48 TRACE_COMPONENT_LIST in Tracer.cpp.
|
49 kumpf 1.48 The tracer uses the _traceComponentMask 64bit field to mask
|
50 thilo.boehm 1.43 the user configured components.
51
52 Please ensure that no more than 64 Trace Component ID's are specified.
|
53 kumpf 1.41 */
54 enum TraceComponentId
55 {
|
56 thilo.boehm 1.45 TRC_XML,
|
57 kumpf 1.41 TRC_XML_IO,
58 TRC_HTTP,
59 TRC_REPOSITORY,
60 TRC_DISPATCHER,
61 TRC_OS_ABSTRACTION,
62 TRC_CONFIG,
63 TRC_IND_HANDLER,
64 TRC_AUTHENTICATION,
65 TRC_AUTHORIZATION,
66 TRC_USER_MANAGER,
67 TRC_SHUTDOWN,
68 TRC_SERVER,
69 TRC_INDICATION_SERVICE,
70 TRC_MESSAGEQUEUESERVICE,
71 TRC_PROVIDERMANAGER,
72 TRC_OBJECTRESOLUTION,
73 TRC_WQL,
74 TRC_CQL,
|
75 karl 1.56 TRC_FQL,
|
76 kumpf 1.41 TRC_THREAD,
77 TRC_EXP_REQUEST_DISP,
78 TRC_SSL,
79 TRC_CONTROLPROVIDER,
80 TRC_CIMOM_HANDLE,
81 TRC_L10N,
82 TRC_EXPORT_CLIENT,
83 TRC_LISTENER,
84 TRC_DISCARDED_DATA,
85 TRC_PROVIDERAGENT,
86 TRC_IND_FORMATTER,
87 TRC_STATISTICAL_DATA,
88 TRC_CMPIPROVIDER,
89 TRC_INDICATION_GENERATION,
90 TRC_INDICATION_RECEIPT,
91 TRC_CMPIPROVIDERINTERFACE,
92 TRC_WSMSERVER,
|
93 lawrence.luo 1.55 TRC_RSSERVER,
94 #ifdef PEGASUS_ENABLE_PROTOCOL_WEB
95 TRC_WEBSERVER,
96 #endif /* PEGASUS_ENABLE_PROTOCOL_WEB */
|
97 a.rachapudi 1.49 TRC_LOGMSG,
|
98 marek 1.51 TRC_WMI_MAPPER_CONSUMER,
99 TRC_INTERNALPROVIDER
|
100 kumpf 1.41 };
101
|
102 karl 1.25 /** Token used for tracing functions.
103 */
104 struct TracerToken
105 {
|
106 kumpf 1.41 TraceComponentId component;
|
107 karl 1.25 const char* method;
108 };
109
|
110 mike 1.2 /** Tracer implements tracing of messages to a defined file
111 */
112 class PEGASUS_COMMON_LINKAGE Tracer
113 {
114 public:
115
|
116 karl 1.52 /** Trace Components list defines the strings repesenting each
117 TraceComponentId entry. Externalized to allow display of the
118 possible list of trace components. The size of this list is
119 defined in _NUM_COMPONENTS variable.
120 */
121 static char const* TRACE_COMPONENT_LIST[];
122
|
123 r.kieninger 1.35 /** Trace facilities
124 File - tracing occurs to the trace file
125 Log - tracing occurs through the Pegasus Logger class
126 Keep the TRACE_FACILITY_LIST in sync with the TRACE_FACILITY_INDEX,
127 so that the index matches the according string in the list.
128 */
129 static char const* TRACE_FACILITY_LIST[];
130
131 enum TRACE_FACILITY_INDEX
132 {
133 TRACE_FACILITY_FILE = 0,
|
134 thilo.boehm 1.39 TRACE_FACILITY_LOG = 1,
135 TRACE_FACILITY_MEMORY = 2
|
136 r.kieninger 1.35 };
137
138
|
139 mike 1.2 /** Levels of trace
140 Trace messages are written to the trace file only if they are at or
141 above a given trace level
|
142 marek 1.34 LEVEL1 - Severe and log messages
|
143 mike 1.2 LEVEL2 - Basic flow trace messages, low data detail
144 LEVEL3 - Inter-function logic flow, medium data detail
145 LEVEL4 - High data detail
146 */
147 static const Uint32 LEVEL1;
148 static const Uint32 LEVEL2;
149 static const Uint32 LEVEL3;
150 static const Uint32 LEVEL4;
|
151 r.kieninger 1.20
|
152 marek 1.28 /** Traces the given character string.
153 Overloaded to include the filename
154 and line number of trace origin.
|
155 kumpf 1.27 @param fileName filename of the trace originator
156 @param lineNum line number of the trace originator
157 @param traceComponent component being traced
|
158 marek 1.28 @param cstring the character string to be traced
|
159 karl 1.25 */
|
160 marek 1.28 static void traceCString(
161 const char* fileName,
162 const Uint32 lineNum,
|
163 kumpf 1.41 const TraceComponentId traceComponent,
|
164 marek 1.28 const char* cstring);
|
165 karl 1.25
166 /** Traces the message in the given CIMException object. The message
|
167 kumpf 1.27 written to the trace file will include the source filename and
168 line number of the CIMException originator.
169 @param traceComponent component being traced
170 @param level trace level of the trace message
|
171 kumpf 1.33 @param cimException the CIMException to be traced.
|
172 karl 1.25 */
173 static void traceCIMException(
|
174 kumpf 1.41 const TraceComponentId traceComponent,
|
175 kumpf 1.27 const Uint32 level,
176 const CIMException& cimException);
|
177 karl 1.25
|
178 marek 1.50 /** Formats the message given in data as hex dump if binary is true
179 @param data Message to be formatted
180 @param binary flag indicating if message is binary or not
181 */
182 static SharedArrayPtr<char> traceFormatChars(
183 const Buffer& data,
184 bool binary);
185
|
186 sushma.fernandes 1.30 /** Gets an HTTP request message.
|
187 kumpf 1.40
|
188 marek 1.50 Given a binary HTTP request message(application/x-openpegasus
189 this method returns the request message formatted in hex dump format
190 and returns.
191
|
192 sushma.fernandes 1.30 Given an HTTP request message, this method checks if the
|
193 kumpf 1.40 message contains a "Basic" authorization header.
194
|
195 sushma.fernandes 1.30 If true, the username/passwd is suppressed and returned.
196 Otherwise the request message is returned without any changes.
197
198 @param requestMessage requestMessage to be checked
|
199 kumpf 1.40
|
200 sushma.fernandes 1.30 @return request message
|
201 kumpf 1.40
|
202 sushma.fernandes 1.30 */
203 static SharedArrayPtr<char> getHTTPRequestMessage(
204 const Buffer& requestMessage);
205
|
206 karl 1.25 /** Set the trace file to the given file
|
207 kumpf 1.27 @param traceFile full path of the trace file
208 @return 0 if the filepath is valid
209 1 if the traceFile is an empty string or
210 if an error occurs while opening the file
211 in append mode
|
212 karl 1.25 */
213 static Uint32 setTraceFile(const char* traceFile);
214
215 /** Set the trace level to the given level
|
216 kumpf 1.27 @param level trace level to be set
217 @return 0 if trace level is valid
218 1 if trace level is invalid
|
219 karl 1.25 */
220 static Uint32 setTraceLevel(const Uint32 level);
221
222 /** Set components to be traced
|
223 kumpf 1.27 @param traceComponents list of components to be traced,
224 components should be separated by ','
|
225 karl 1.25 */
226 static void setTraceComponents(
227 const String& traceComponents);
|
228 r.kieninger 1.20
|
229 r.kieninger 1.35 /** Set trace facility to be used
230 @param traceFacility facility to be used for tracing,
|
231 kumpf 1.40 for example Log or File.
|
232 r.kieninger 1.35 @return 0 if trace facility is valid
233 1 if trace facility is invalid
234 */
235 static Uint32 setTraceFacility(const String& traceFacility);
236
|
237 marek 1.37 /** Get trace facility currently in use
238 @return TRACE_FACILITY_FILE - if trace facility is file
239 TRACE_FACILITY_LOG - if trace facility is the log
|
240 thilo.boehm 1.42 TRACE_FACILITY_MEMORY - if trace facility is memory tracing
|
241 marek 1.37 */
242 static Uint32 getTraceFacility();
243
|
244 thilo.boehm 1.39 /** Set buffer size to be used for the memory tracing facility
245 @param bufferSize buffer size in Kbyte to be used for memory tracing
246 @return true if function was successfully.
247 */
248 static Boolean setTraceMemoryBufferSize(Uint32 bufferSize);
249
|
250 lawrence.luo 1.54 /** Set the Max trace File Size and used for the File tracing
|
251 amit99shah 1.53 @param maxLogFileSizeBytes size of cimserver.trc
252 */
|
253 lawrence.luo 1.54 static void setMaxTraceFileSize (const String &size);
|
254 amit99shah 1.53
255 /** Set the Max trace File number
256 @param maxLogFileNumber number of cimserver.trc in trace folder
257 */
|
258 lawrence.luo 1.54 static void setMaxTraceFileNumber(const String &numberOfFiles);
|
259 amit99shah 1.53
|
260 thilo.boehm 1.39 /** Flushes the trace buffer to traceFilePath. This method will only
261 have an effect when traceFacility=Memory.
262 */
263 static void flushTrace();
264
|
265 karl 1.25 /** Traces method entry.
|
266 kumpf 1.27 @param token TracerToken
267 @param fileName filename of the trace originator
268 @param lineNum line number of the trace originator
269 @param traceComponent component being traced
270 @param methodName method being traced
|
271 mike 1.2 */
|
272 karl 1.25 static void traceEnter(
|
273 kumpf 1.27 TracerToken& token,
274 const char* file,
275 size_t line,
|
276 kumpf 1.41 TraceComponentId traceComponent,
|
277 kumpf 1.27 const char* method);
|
278 r.kieninger 1.20
279 /** Traces method exit.
|
280 kumpf 1.27 @param token TracerToken containing component and method
281 @param fileName filename of the trace originator
282 @param lineNum line number of the trace originator
|
283 mike 1.2 */
|
284 karl 1.25 static void traceExit(
|
285 kumpf 1.27 TracerToken& token,
286 const char* file,
287 size_t line);
|
288 mike 1.2
289 /** Validates the File Path for the trace File
|
290 kumpf 1.27 @param filePath full path of the file
291 @return 1 if the file path is valid
292 0 if the file path is invalid
|
293 mike 1.2 */
|
294 kumpf 1.7 static Boolean isValidFileName(const char* filePath);
295
296 /** Validates the trace components
|
297 kumpf 1.27 @param traceComponents comma separated list of trace components
298 @return 1 if the components are valid
299 0 if one or more components are invalid
|
300 kumpf 1.7 */
|
301 kumpf 1.15 static Boolean isValidComponents(const String& traceComponents);
|
302 mike 1.2
303 /** Validates the trace components
|
304 kumpf 1.27 @param traceComponents comma separated list of trace components
305 @param invalidComponents comma separated list of invalid components
306 @return 1 if the components are valid
307 0 if one or more components are invalid
|
308 mike 1.2 */
|
309 kumpf 1.7 static Boolean isValidComponents(
|
310 kumpf 1.15 const String& traceComponents,
|
311 kumpf 1.7 String& invalidComponents);
|
312 mike 1.2
|
313 r.kieninger 1.35 /** Validates the trace facility string value
314 @param traceFacility The trace facility as string
315 @return 1 if the trace facility is valid
316 0 if the trace facility is invalid
317 */
318 static Boolean isValidTraceFacility( const String& traceFacility );
|
319 kumpf 1.40
|
320 kumpf 1.48 /** Signals the trace to be running OOP and provides the file name
|
321 thilo.boehm 1.42 extension of the trace file. If non-empty, this
|
322 kumpf 1.15 value is used as an extension to the name of the trace file.
|
323 thilo.boehm 1.42 @param oopTraceFileExtension Trace file extension.
|
324 kumpf 1.15 */
|
325 thilo.boehm 1.42 static void setOOPTraceFileExtension(const String& oopTraceFileExtension);
|
326 kumpf 1.15
|
327 karl 1.25 /**
328 */
|
329 david.dillard 1.23 static Boolean isTraceOn() { return _traceOn; }
|
330 mike 1.21
|
331 marek 1.31 // Checks if trace is enabled for the given component and trace level
332 // @param traceComponent component being traced
333 // @param level level of the trace message
334 // @return 0 if the component and level are not enabled
335 // 1 if the component and level are enabled
336 static Boolean isTraceEnabled(
|
337 kumpf 1.41 const TraceComponentId traceComponent,
|
338 thilo.boehm 1.43 const Uint32 traceLevel)
|
339 kumpf 1.48 {
340 return ((traceLevel & _traceLevelMask) &&
341 (_traceComponentMask & ((Uint64)1 << traceComponent)));
342 }
|
343 marek 1.31
|
344 lawrence.luo 1.54 //
345 //Converts a given string representation of a trace property into Uint32.
346 //If the string reperesantation is not valid, the returnd bufferSize is 0.
347 //@param traceProperty The trace property value as string
348 //@param valueInUint32 Returns the value as Uint32.
349 //@return Boolean True if specified size is a
350 // valid string representaion of a Uint32.
351 static Boolean tracePropertyToUint32( const String& traceProperty,
352 Uint32& valueInUint32 );
353
|
354 mike 1.2 private:
355
|
356 r.kieninger 1.20 /** A static single indicator if tracing is turned on allowing to
357 determine the state of trace quickly without many instructions.
358 Used to wrap the public static trace interface methods to avoid
359 obsolete calls when tracing is turned off.
360 */
|
361 david.dillard 1.23 static Boolean _traceOn;
|
362 r.kieninger 1.20
|
363 marek 1.34 /** Internal only Levels of trace
364 These cannot be used in any of the trace calls directly, but are set
365 by methods of the Tracer class for specific purposes, such as trace
366 Enter and traceExit.
367 LEVEL0 - Trace is switched off
368 LEVEL5 - used for method enter & exit
369 */
370 static const Uint32 LEVEL0;
371 static const Uint32 LEVEL5;
372
|
373 mike 1.2 static const char _COMPONENT_SEPARATOR;
374 static const Uint32 _NUM_COMPONENTS;
375 static const Uint32 _STRLEN_MAX_UNSIGNED_INT;
|
376 kumpf 1.4 static const Uint32 _STRLEN_MAX_PID_TID;
|
377 thilo.boehm 1.43 static Uint64 _traceComponentMask;
378 static Uint32 _traceLevelMask;
379 static Tracer* _tracerInstance;
|
380 thilo.boehm 1.39 Uint32 _traceMemoryBufferSize;
|
381 r.kieninger 1.35 Uint32 _traceFacility;
|
382 kumpf 1.48 Boolean _runningOOP;
|
383 thilo.boehm 1.39 TraceHandler* _traceHandler;
|
384 thilo.boehm 1.42 String _traceFile;
385 String _oopTraceFileExtension;
|
386 kumpf 1.48
|
387 mike 1.2
|
388 kumpf 1.10 // Message Strings for function Entry and Exit
|
389 r.kieninger 1.20 static const char _METHOD_ENTER_MSG[];
390 static const char _METHOD_EXIT_MSG[];
|
391 mike 1.2
|
392 marek 1.50 // Function formats size bytes of binary data given in data in a nicely
393 // readable hex format and writes the output to targetBuffer
394 // Return value: Pointer to one byte behind last position that was written
395 static char* _formatHexDump(
396 char* targetBuffer,
397 const char* data,Uint32 size);
398
|
399 r.kieninger 1.35 // Factory function to create an instance of the matching trace handler
400 // for the given type of traceFacility.
401 // @param traceFacility type of trace handler to create
|
402 thilo.boehm 1.39 void _setTraceHandler( Uint32 traceFacility );
|
403 r.kieninger 1.35
|
404 thilo.boehm 1.42 // Validates if the given file path if it is eligible for writing traces.
405 // @param fileName a file intended to be used to write traces
406 static Boolean _isValidTraceFile(String fileName);
407
|
408 mike 1.2 // Traces the given message. Overloaded to include the file name and the
409 // line number as one of the parameters.
410 // @param traceComponent component being traced
411 // @param message message header (file name:line number)
412 // @param *fmt printf style format string
413 // @param argList variable argument list
414 static void _trace(
|
415 kumpf 1.27 const char* fileName,
416 const Uint32 lineNum,
|
417 kumpf 1.41 const TraceComponentId traceComponent,
|
418 kumpf 1.27 const char* fmt,
419 va_list argList);
|
420 mike 1.2
|
421 kumpf 1.6 // Traces the message in the given CIMException object. The message
|
422 r.kieninger 1.20 // to be written to the trace file will include the source filename and
|
423 kumpf 1.6 // line number of the CIMException originator.
424 // @param traceComponent component being traced
425 // @param CIMException the CIMException to be traced.
426 //
427 static void _traceCIMException(
|
428 kumpf 1.41 const TraceComponentId traceComponent,
|
429 kumpf 1.27 const CIMException& cimException);
|
430 r.kieninger 1.20
|
431 marek 1.28 // Called by all the trace interfaces to log message
432 // consisting of a single character string to the trace file
|
433 kumpf 1.40 // @param traceComponent component being traced
|
434 marek 1.28 // @param cstring the string to be traced
435 static void _traceCString(
|
436 kumpf 1.41 const TraceComponentId traceComponent,
|
437 marek 1.28 const char* message,
438 const char* cstring);
|
439 kumpf 1.40
|
440 marek 1.28 // Called by all the trace interfaces to log message
441 // with variable number of arguments to the trace file
|
442 mike 1.2 // @param traceComponent component being traced
443 // @param *fmt printf style format string
444 // @param argList variable argument list
445 static void _trace(
|
446 kumpf 1.41 const TraceComponentId traceComponent,
|
447 kumpf 1.27 const char* message,
448 const char* fmt,
449 va_list argList);
|
450 mike 1.2
|
451 marek 1.28 // Traces method enter/exit
|
452 mike 1.2 // @param fileName filename of the trace originator
453 // @param lineNum line number of the trace originator
454 // @param traceComponent component being traced
|
455 marek 1.28 // @param method name of the method
456 static void _traceMethod(
|
457 kumpf 1.27 const char* fileName,
458 const Uint32 lineNum,
|
459 kumpf 1.41 const TraceComponentId traceComponent,
|
460 marek 1.28 const char* methodEntryExit,
461 const char* method);
|
462 mike 1.2
463 // Tracer constructor
464 // Constructor is private to prevent construction of Tracer objects
465 // Single Instance of Tracer is maintained for each process.
466 Tracer();
467
468 // Tracer destructor
469 ~Tracer();
470
471 // Returns the Singleton instance of the Tracer
|
472 r.kieninger 1.20 // @return Tracer* Instance of Tracer
|
473 mike 1.2 static Tracer* _getInstance();
|
474 marek 1.31
475 friend class TraceCallFrame;
|
476 marek 1.34 friend class TracePropertyOwner;
|
477 thilo.boehm 1.42 friend class TraceMemoryHandler;
478 friend class TraceFileHandler;
|
479 mike 1.2 };
480
|
481 karl 1.25 //==============================================================================
482 //
483 // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
484 // interfaces. If defined the interfaces map to empty functions.
485 //
486 //==============================================================================
487
|
488 mike 1.2 #ifdef PEGASUS_REMOVE_TRACE
|
489 karl 1.25
|
490 marek 1.28 inline void Tracer::traceCString(
491 const char* fileName,
492 const Uint32 lineNum,
|
493 kumpf 1.41 const TraceComponentId traceComponent,
|
494 marek 1.28 const char* cstring)
|
495 karl 1.25 {
496 // empty function
497 }
498
499 inline void Tracer::traceCIMException(
|
500 kumpf 1.41 const TraceComponentId traceComponent,
|
501 kumpf 1.27 const Uint32 level,
502 const CIMException& cimException)
|
503 karl 1.25 {
504 // empty function
505 }
506
|
507 sushma.fernandes 1.30 static SharedArrayPtr<char> getHTTPRequestMessage(
508 const Buffer& requestMessage)
509 {
510 //empty function
511 return SharedArrayPtr<char>();
512 }
513
|
514 karl 1.25 inline Uint32 Tracer::setTraceFile(const char* traceFile)
515 {
516 // empty function
517 return 0;
518 }
519
|
520 kumpf 1.26 inline Uint32 Tracer::setTraceLevel(const Uint32 level)
521 {
522 // empty function
523 return 0;
524 }
525
526 inline void Tracer::setTraceComponents(const String& traceComponents)
527 {
528 // empty function
529 }
530
|
531 thilo.boehm 1.42 inline Uint32 Tracer::setTraceFacility(const String& traceFacility)
|
532 r.kieninger 1.35 {
533 // empty function
|
534 marek 1.37 return 0;
535 }
536
537 inline Uint32 Tracer::getTraceFacility()
538 {
539 // empty function
540 return 0;
|
541 r.kieninger 1.35 }
542
|
543 kumpf 1.40 inline Boolean Tracer::setTraceMemoryBufferSize(Uint32 bufferSize)
|
544 thilo.boehm 1.39 {
545 // empty function
546 return true;
547 }
548
549 inline void Tracer::flushTrace()
550 {
551 // empty function
552 return;
553 }
554
|
555 lawrence.luo 1.54
556
|
557 karl 1.25 #endif /* PEGASUS_REMOVE_TRACE */
558
559 //==============================================================================
560 //
561 // Tracing macros
562 //
563 //==============================================================================
564
565 // Defines a variable that bypasses inclusion of line and filename in output.
566 // #define PEGASUS_NO_FILE_LINE_TRACE=1 to exclude file names and line numbers
567 #ifdef PEGASUS_NO_FILE_LINE_TRACE
568 # define PEGASUS_COMMA_FILE_LINE /* empty */
569 # define PEGASUS_FILE_LINE_COMMA /* empty */
|
570 mike 1.2 #else
|
571 karl 1.25 # define PEGASUS_COMMA_FILE_LINE ,__FILE__,__LINE__
572 # define PEGASUS_FILE_LINE_COMMA __FILE__,__LINE__,
573 #endif
574
575 #ifdef PEGASUS_REMOVE_TRACE
576
577 # define PEG_METHOD_ENTER(comp,meth)
578 # define PEG_METHOD_EXIT()
579 # define PEG_TRACE(VAR_ARGS)
|
580 marek 1.28 # define PEG_TRACE_CSTRING(comp,level,chars)
|
581 karl 1.25
582 #else /* PEGASUS_REMOVE_TRACE */
583
|
584 marek 1.36 // remover trace code for method enter/exit
585 # ifdef PEGASUS_REMOVE_METHODTRACE
586 # define PEG_METHOD_ENTER(comp,meth)
587 # define PEG_METHOD_EXIT()
|
588 kumpf 1.40 # else
|
589 marek 1.36 # define PEG_METHOD_ENTER(comp, meth) \
|
590 karl 1.25 TracerToken __tracerToken; \
|
591 dave.sudlik 1.32 __tracerToken.method = 0; \
|
592 marek 1.28 do \
593 { \
594 if (Tracer::isTraceOn()) \
|
595 kumpf 1.29 Tracer::traceEnter( \
596 __tracerToken PEGASUS_COMMA_FILE_LINE, comp, meth); \
|
597 marek 1.28 } \
598 while (0)
|
599 karl 1.25
600 # define PEG_METHOD_EXIT() \
|
601 marek 1.28 do \
602 { \
603 if (Tracer::isTraceOn()) \
604 Tracer::traceExit(__tracerToken PEGASUS_COMMA_FILE_LINE); \
605 } \
606 while (0)
|
607 kumpf 1.40 # endif
|
608 karl 1.25
|
609 marek 1.28 // Macro to trace character lists. the do construct allows this to appear
610 // as a single statement.
611 # define PEG_TRACE_CSTRING(comp, level, chars) \
612 do \
613 { \
614 if (Tracer::isTraceOn()) \
|
615 marek 1.31 { \
616 if (Tracer::isTraceEnabled(comp, level)) \
617 { \
618 Tracer::traceCString(PEGASUS_FILE_LINE_COMMA comp, chars); \
619 } \
620 } \
|
621 karl 1.25 } \
622 while (0)
623
|
624 marek 1.31 //
625 // This class is constructed with the same arguments passed to PEG_TRACE().
626 // The constructor saves all the fixed arguments and calls va_start() on
627 // the varying arguments (wherein the va_list argument is the ap member of
628 // this class). The PEG_TRACE() macro eventually calls invoke() with the
629 // file and line macros in order to write the trace entry. For more details,
630 // see the comments below on the PEG_TRACE() macro.
631 //
632 class TraceCallFrame
633 {
634 public:
635
636 const char* file;
637 Uint32 line;
|
638 kumpf 1.40
|
639 marek 1.31 TraceCallFrame(const char* file_, Uint32 line_) : file(file_), line(line_)
640 {
641 }
|
642 kumpf 1.40
|
643 marek 1.31 PEGASUS_FORMAT(4, 5)
644 inline void invoke(
|
645 kumpf 1.41 const TraceComponentId component,
|
646 marek 1.31 const Uint32 level,
647 const char* format,
|
648 kumpf 1.40 ...)
|
649 marek 1.31 {
650 if (Tracer::isTraceEnabled(component, level))
651 {
652 va_list ap;
653 va_start(ap, format);
654 Tracer::_trace(file, line, component, format, ap);
655 va_end(ap);
656 }
657 }
658
659 ~TraceCallFrame()
660 {
661 }
662 };
663 //
|
664 kumpf 1.40 // This macro is a wrapper for calling the printf-style form of the
665 // Tracer::trace() function. Since macros cannot have a varying number of
|
666 marek 1.31 // arguments, PEG_TRACE() must be invoked with double parentheses. For
667 // example:
668 //
669 // PEG_TRACE((TRC_HTTP, Tracer::LEVEL1, "Oops: %d", 999));
670 //
671 // This macro offers two advantages over the calling trace() directly.
672 //
673 // 1. It eliminates the call to trace() if isTraceOn() returns false.
674 // This has proven to reduce the expense of servicing a request
675 // (when tracing is off) by as much as 3%.
676 //
677 // 2. It implicitly injects the __FILE__ and __LINE__ macros, relieving
678 // the caller of this burden.
679 //
|
680 karl 1.25 # define PEG_TRACE(VAR_ARGS) \
681 do \
682 { \
|
683 kumpf 1.27 if (Tracer::isTraceOn()) \
|
684 marek 1.31 { \
685 TraceCallFrame frame(__FILE__, __LINE__); \
686 frame.invoke VAR_ARGS; \
687 } \
|
688 karl 1.25 } \
689 while (0)
|
690 mike 1.22
|
691 karl 1.25 #endif /* !PEGASUS_REMOVE_TRACE */
|
692 mike 1.2
693 PEGASUS_NAMESPACE_END
694
695 #endif /* Pegasus_Tracer_h */
|