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