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