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