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