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 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)
33 //
|
34 kumpf 1.6 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
|
35 a.arora 1.14 // Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
|
36 kumpf 1.15 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
37 david.dillard 1.23 // David Dillard, Symantec Corp. (david_dillard@symantec.com)
|
38 mike 1.2 //
39 //%/////////////////////////////////////////////////////////////////////////////
40
41 #ifndef Pegasus_Tracer_h
42 #define Pegasus_Tracer_h
43
44 #include <stdarg.h>
45 #include <Pegasus/Common/String.h>
46 #include <Pegasus/Common/System.h>
47 #include <Pegasus/Common/Logger.h>
|
48 kumpf 1.12 #include <Pegasus/Common/InternalException.h>
|
49 mike 1.2 #include <Pegasus/Common/TraceComponents.h>
50 #include <Pegasus/Common/TraceFileHandler.h>
|
51 kumpf 1.11 #include <Pegasus/Common/Linkage.h>
|
52 a.arora 1.14 #include <Pegasus/Common/AutoPtr.h>
|
53 mike 1.2
54 PEGASUS_NAMESPACE_BEGIN
55
56 /** Tracer implements tracing of messages to a defined file
57 */
58
59 class PEGASUS_COMMON_LINKAGE Tracer
60 {
61 public:
62
63 /** Levels of trace
64 Trace messages are written to the trace file only if they are at or
65 above a given trace level
66 LEVEL1 - Function Entry/Exit
67 LEVEL2 - Basic flow trace messages, low data detail
68 LEVEL3 - Inter-function logic flow, medium data detail
69 LEVEL4 - High data detail
70 */
71 static const Uint32 LEVEL1;
72 static const Uint32 LEVEL2;
73 static const Uint32 LEVEL3;
74 mike 1.2 static const Uint32 LEVEL4;
|
75 r.kieninger 1.20
76 // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
|
77 mike 1.2 // interfaces. If defined the interfaces map to empty functions
|
78 r.kieninger 1.20
|
79 mike 1.2 #ifdef PEGASUS_REMOVE_TRACE
|
80 r.kieninger 1.20
|
81 mike 1.2 inline static void traceBuffer(
82 const char* fileName,
83 const Uint32 lineNum,
84 const Uint32 traceComponent,
85 const Uint32 traceLevel,
86 const char* data,
87 const Uint32 size)
88 {
89 // empty function
90 }
91 inline static void traceBuffer(
92 const Uint32 traceComponent,
93 const Uint32 traceLevel,
94 const char* data,
95 const Uint32 size)
96 {
97 // empty function
98 }
|
99 r.kieninger 1.20
|
100 mike 1.2 inline static void trace(
101 const Uint32 traceComponent,
102 const Uint32 traceLevel,
103 const char *fmt,
104 ...)
105 {
106 // empty function
107 }
|
108 r.kieninger 1.20
|
109 mike 1.2 inline static void trace(
110 const char* fileName,
111 const Uint32 lineNum,
112 const Uint32 traceComponent,
113 const Uint32 traceLevel,
114 const char* fmt,
115 ...)
116 {
117 // empty function
118 }
119
|
120 kumpf 1.6 inline static void trace(
121 const char* fileName,
122 const Uint32 lineNum,
123 const Uint32 traceComponent,
124 const Uint32 traceLevel,
125 const String& traceString)
126 {
127 // empty function
128 }
129
130 inline static void traceCIMException(
131 const Uint32 traceComponent,
132 const Uint32 traceLevel,
133 CIMException cimException)
134 {
135 // empty function
136 }
137
|
138 mike 1.2 static Uint32 setTraceFile(const char* traceFile)
139 {
140 // empty function
141 return 0;
142 }
143
144 static Uint32 setTraceLevel(const Uint32 traceLevel)
145 {
146 // empty function
147 return 0;
148 }
149
150 static void setTraceComponents(
|
151 kumpf 1.15 const String& traceComponents)
|
152 mike 1.2 {
153 // empty function
154 }
|
155 r.kieninger 1.20
|
156 mike 1.2
157 #else
|
158 r.kieninger 1.20 /** Traces the specified number of bytes in a given buffer
|
159 mike 1.2 @param traceComponent component being traced
160 @param traceLevel trace level of the trace message
161 @param data buffer to be traced
|
162 r.kieninger 1.20 @param size number of bytes to be traced
|
163 mike 1.2 */
164 inline static void traceBuffer(
165 const Uint32 traceComponent,
166 const Uint32 traceLevel,
167 const char* data,
168 const Uint32 size)
169 {
|
170 r.kieninger 1.20 if (_traceOn)
171 {
172 _traceBuffer( traceComponent, traceLevel, data, size );
173 }
|
174 mike 1.2 }
|
175 r.kieninger 1.20
176 /** Traces the specified number of bytes in a given buffer
177 Overloaded to include the filename and the line number
178 of trace origin.
|
179 mike 1.2 @param fileName filename of the trace originator
180 @param lineNum line number of the trace originator
181 @param traceComponent component being traced
182 @param traceLevel trace level of the trace message
183 @param data buffer to be traced
184 @param size size of the buffer
185 */
186 inline static void traceBuffer(
187 const char* fileName,
188 const Uint32 lineNum,
189 const Uint32 traceComponent,
190 const Uint32 traceLevel,
191 const char* data,
192 const Uint32 size)
193 {
|
194 r.kieninger 1.20 if (_traceOn)
195 {
196 _traceBuffer( fileName, lineNum,
197 traceComponent, traceLevel, data, size );
198 }
|
199 mike 1.2 }
|
200 r.kieninger 1.20
201
202 /** Traces the given message
|
203 mike 1.2 @param traceComponent component being traced
204 @param traceLevel trace level of the trace message
205 @param *fmt printf style format string
206 @param ... variable argument list
207 */
208 inline static void trace(
209 const Uint32 traceComponent,
210 const Uint32 traceLevel,
211 const char *fmt,
212 ...)
213 {
|
214 r.kieninger 1.20 if (_traceOn)
215 {
216 va_list argList;
217
218 va_start(argList,fmt);
219 _trace(traceComponent,traceLevel,fmt,argList);
220 va_end(argList);
221 }
222 }
223
224 /** Traces the given message. Overloaded to include the filename and
225 the line number of trace origin.
|
226 mike 1.2 @param fileName filename of the trace originator
227 @param lineNum line number of the trace originator
228 @param traceComponent component being traced
229 @param traceLevel trace level of the trace message
230 @param *fmt printf style format string
231 @param ... variable argument list
232 */
233 inline static void trace(
234 const char* fileName,
235 const Uint32 lineNum,
236 const Uint32 traceComponent,
237 const Uint32 traceLevel,
238 const char* fmt,
239 ...)
240 {
|
241 r.kieninger 1.20 if (_traceOn)
242 {
243 va_list argList;
244
245 va_start(argList,fmt);
246 _trace(fileName,lineNum,traceComponent,traceLevel,fmt,argList);
247 va_end(argList);
248 }
|
249 mike 1.2 }
250
|
251 kumpf 1.6 /** Traces the given string. Overloaded to include the filename
252 and line number of trace origin.
253 @param fileName filename of the trace originator
254 @param lineNum line number of the trace originator
255 @param traceComponent component being traced
256 @param traceLevel trace level of the trace message
257 @param traceString the string to be traced
258 */
259 inline static void trace(
260 const char* fileName,
261 const Uint32 lineNum,
262 const Uint32 traceComponent,
263 const Uint32 traceLevel,
264 const String& traceString)
265 {
|
266 r.kieninger 1.20 if (_traceOn)
267 {
268 _traceString( fileName, lineNum, traceComponent, traceLevel,
269 traceString );
270 }
|
271 kumpf 1.6 }
272
273 /** Traces the message in the given CIMException object. The message
274 written to the trace file will include the source filename and
275 line number of the CIMException originator.
276 @param traceComponent component being traced
277 @param traceLevel trace level of the trace message
278 @param CIMException the CIMException to be traced.
279 */
280 inline static void traceCIMException(
281 const Uint32 traceComponent,
282 const Uint32 traceLevel,
283 CIMException cimException)
284 {
|
285 r.kieninger 1.20 if (_traceOn)
286 {
287 _traceCIMException( traceComponent, traceLevel, cimException );
288 }
|
289 kumpf 1.6 }
290
|
291 mike 1.2 /** Set the trace file to the given file
292 @param traceFile full path of the trace file
|
293 r.kieninger 1.20 @return 0 if the filepath is valid
|
294 kumpf 1.17 1 if the traceFile is an empty string or
295 if an error occurs while opening the file
|
296 mike 1.2 in append mode
297 */
298 static Uint32 setTraceFile(const char* traceFile);
299
300 /** Set the trace level to the given level
301 @param traceLevel trace level to be set
302 @return 0 if trace level is valid
303 1 if trace level is invalid
304 */
305 static Uint32 setTraceLevel(const Uint32 traceLevel);
306
307 /** Set components to be traced
|
308 r.kieninger 1.20 @param traceComponents list of components to be traced,
|
309 mike 1.2 components should be separated by ','
310 */
311 static void setTraceComponents(
|
312 kumpf 1.15 const String& traceComponents);
|
313 r.kieninger 1.20
314 #endif
|
315 mike 1.2
316 // End of PEGASUS_REMOVE_TRACE
|
317 r.kieninger 1.20
318 /** Traces method entry.
|
319 mike 1.2 @param fileName filename of the trace originator
320 @param lineNum line number of the trace originator
321 @param traceComponent component being traced
322 @param methodName method being traced
323 */
324 inline static void traceEnter(
325 const char* fileName,
326 const Uint32 lineNum,
327 const Uint32 traceComponent,
328 const char* methodName)
329 {
|
330 r.kieninger 1.20 if (_traceOn)
331 {
332 _traceEnter( fileName, lineNum, traceComponent, "%s %s",
333 _METHOD_ENTER_MSG, methodName);
334 }
|
335 mike 1.2 }
|
336 r.kieninger 1.20
337 /** Traces method exit.
|
338 mike 1.2 @param fileName filename of the trace originator
339 @param lineNum line number of the trace originator
340 @param traceComponent component being traced
341 @param methodName method being traced
342 */
343 inline static void traceExit(
344 const char* fileName,
345 const Uint32 lineNum,
346 const Uint32 traceComponent,
347 const char* methodName)
348 {
|
349 r.kieninger 1.20 if (_traceOn)
350 {
351 _traceExit( fileName, lineNum, traceComponent, "%s %s",
352 _METHOD_EXIT_MSG, methodName);
353 }
|
354 mike 1.2 }
355
356 /** Validates the File Path for the trace File
|
357 r.kieninger 1.20 @param filePath full path of the file
|
358 mike 1.2 @return 1 if the file path is valid
359 0 if the file path is invalid
360 */
|
361 kumpf 1.7 static Boolean isValidFileName(const char* filePath);
362
363 /** Validates the trace components
364 @param traceComponents comma separated list of trace components
365 @return 1 if the components are valid
366 0 if one or more components are invalid
367 */
|
368 kumpf 1.15 static Boolean isValidComponents(const String& traceComponents);
|
369 mike 1.2
370 /** Validates the trace components
371 @param traceComponents comma separated list of trace components
372 @param invalidComponents comma separated list of invalid components
373 @return 1 if the components are valid
374 0 if one or more components are invalid
375 */
|
376 kumpf 1.7 static Boolean isValidComponents(
|
377 kumpf 1.15 const String& traceComponents,
|
378 kumpf 1.7 String& invalidComponents);
|
379 mike 1.2
|
380 kumpf 1.15 /** Specify the name of the module being traced. If non-empty, this
381 value is used as an extension to the name of the trace file.
382 @param moduleName Name of the module being traced.
383 */
384 static void setModuleName(const String& moduleName);
385
|
386 david.dillard 1.23 static Boolean isTraceOn() { return _traceOn; }
|
387 mike 1.21
|
388 mike 1.2 private:
389
|
390 r.kieninger 1.20 /** A static single indicator if tracing is turned on allowing to
391 determine the state of trace quickly without many instructions.
392 Used to wrap the public static trace interface methods to avoid
393 obsolete calls when tracing is turned off.
394 */
|
395 david.dillard 1.23 static Boolean _traceOn;
|
396 r.kieninger 1.20
|
397 mike 1.2 static const char _COMPONENT_SEPARATOR;
398 static const Uint32 _NUM_COMPONENTS;
399 static const Uint32 _STRLEN_MAX_UNSIGNED_INT;
|
400 kumpf 1.4 static const Uint32 _STRLEN_MAX_PID_TID;
|
401 mike 1.2 static const Boolean _SUCCESS;
402 static const Boolean _FAILURE;
|
403 kumpf 1.15 AutoArrayPtr<Boolean> _traceComponentMask;
|
404 mike 1.2 Uint32 _traceLevelMask;
|
405 kumpf 1.15 AutoPtr<TraceFileHandler> _traceHandler;
406 String _moduleName;
|
407 mike 1.2 static Tracer* _tracerInstance;
408
|
409 kumpf 1.10 // Message Strings for function Entry and Exit
|
410 r.kieninger 1.20 static const char _METHOD_ENTER_MSG[];
411 static const char _METHOD_EXIT_MSG[];
|
412 mike 1.2
413 // Message Strings for Logger
|
414 r.kieninger 1.20 static const char _LOG_MSG[];
|
415 mike 1.2
416 // Checks if trace is enabled for the given component and trace level
417 // @param traceComponent component being traced
418 // @param traceLevel level of the trace message
|
419 r.kieninger 1.20 // @return 0 if the component and level are not enabled
420 // 1 if the component and level are enabled
|
421 mike 1.2 static Boolean _isTraceEnabled(
422 const Uint32 traceComponent,
423 const Uint32 traceLevel);
424
|
425 r.kieninger 1.20 // Traces the given message
|
426 mike 1.2 // @param traceComponent component being traced
427 // @param traceLevel level of the trace message
428 // @param *fmt printf style format string
429 // @param argList variable argument list
430 static void _trace(
431 const Uint32 traceComponent,
432 const Uint32 traceLevel,
433 const char* fmt,
434 va_list argList);
435
436 // Traces the given message. Overloaded to include the file name and the
437 // line number as one of the parameters.
438 // @param traceComponent component being traced
439 // @param traceLevel level of the trace message
440 // @param message message header (file name:line number)
441 // @param *fmt printf style format string
442 // @param argList variable argument list
443 static void _trace(
444 const char* fileName,
445 const Uint32 lineNum,
446 const Uint32 traceComponent,
447 mike 1.2 const Uint32 traceLevel,
448 const char* fmt,
449 va_list argList);
450
451 // Traces the specified number of bytes in a given buffer
452 // @param traceComponent component being traced
453 // @param traceLevel trace level of the trace message
454 // @param data buffer to be traced
455 // @param size number of bytes to be traced
456 static void _traceBuffer(
457 const Uint32 traceComponent,
458 const Uint32 traceLevel,
459 const char* data,
460 const Uint32 size);
461
462 // Traces the specified number of bytes in a given buffer
463 // Overloaded to include the filename and the line number
464 // of trace origin.
465 // @param fileName filename of the trace originator
466 // @param lineNum line number of the trace originator
467 // @param traceComponent component being traced
468 mike 1.2 // @param traceLevel trace level of the trace message
469 // @param data buffer to be traced
470 // @param size size of the buffer
471 static void _traceBuffer(
472 const char* fileName,
473 const Uint32 lineNum,
474 const Uint32 traceComponent,
475 const Uint32 traceLevel,
476 const char* data,
477 const Uint32 size);
478
|
479 kumpf 1.6 // Traces the given string.
480 // @param traceComponent component being traced
481 // @param traceLevel trace level of the trace message
482 // @param traceString the string to be traced
483 //
484 static void _traceString(
485 const Uint32 traceComponent,
486 const Uint32 traceLevel,
487 const String& traceString);
488
489 // Traces a given string. Overloaded to include the filename
490 // and line number of trace origin.
491 // @param fileName filename of the trace originator
492 // @param lineNum line number of the trace originator
493 // @param traceComponent component being traced
494 // @param traceLevel trace level of the trace message
495 // @param traceString the string to be traced
496 //
497 static void _traceString(
498 const char* fileName,
499 const Uint32 lineNum,
500 kumpf 1.6 const Uint32 traceComponent,
501 const Uint32 traceLevel,
502 const String& traceString);
503
504 // Traces the message in the given CIMException object. The message
|
505 r.kieninger 1.20 // to be written to the trace file will include the source filename and
|
506 kumpf 1.6 // line number of the CIMException originator.
507 // @param traceComponent component being traced
508 // @param traceLevel trace level of the trace message
509 // @param CIMException the CIMException to be traced.
510 //
511 static void _traceCIMException(
512 const Uint32 traceComponent,
513 const Uint32 traceLevel,
514 CIMException cimException);
|
515 r.kieninger 1.20
516 // Called by all the trace interfaces to log message to the
|
517 mike 1.2 // trace file
518 // @param fileName filename of the trace originator
519 // @param lineNum line number of the trace originator
520 // @param traceComponent component being traced
521 // @param *fmt printf style format string
522 // @param argList variable argument list
523 static void _trace(
524 const Uint32 traceComponent,
525 const char* message,
526 const char* fmt,
527 va_list argList);
528
529 // Traces method enter
530 // @param fileName filename of the trace originator
531 // @param lineNum line number of the trace originator
532 // @param traceComponent component being traced
533 // @param *fmt printf style format string
534 // @param ... variable argument list
535 static void _traceEnter(
536 const char* fileName,
537 const Uint32 lineNum,
538 mike 1.2 const Uint32 traceComponent,
539 const char* fmt,
540 ...);
541
542 // Traces method exit
543 // @param fileName filename of the trace originator
544 // @param traceComponent component being traced
545 // @param *fmt printf style format string
546 // @param ... variable argument list
547 static void _traceExit(
548 const char* fileName,
549 const Uint32 lineNum,
550 const Uint32 traceComponent,
551 const char* fmt,
552 ...);
553
554 // Tracer constructor
555 // Constructor is private to prevent construction of Tracer objects
556 // Single Instance of Tracer is maintained for each process.
557 Tracer();
558
559 mike 1.2 // Tracer destructor
560 ~Tracer();
561
562 // Returns the Singleton instance of the Tracer
|
563 r.kieninger 1.20 // @return Tracer* Instance of Tracer
|
564 mike 1.2 static Tracer* _getInstance();
565 };
566
|
567 kumpf 1.6 // Define the macros for method entry/exit, and tracing a given string
|
568 mike 1.2 #ifdef PEGASUS_REMOVE_TRACE
|
569 mike 1.22 # define PEG_METHOD_ENTER(traceComponent,methodName)
570 # define PEG_METHOD_EXIT()
571 # define PEG_TRACE_STRING(traceComponent,traceLevel,traceString)
572 # define PEG_TRACE(VAR_ARGS)
|
573 mike 1.2 #else
|
574 kumpf 1.5 /** Macro for tracing method entry
575 @param traceComponent component being traced
576 @param methodName name of the method
577 */
|
578 mike 1.22 # define PEG_METHOD_ENTER(traceComponent,methodName) \
579 static const char *PEG_METHOD_NAME = methodName; \
580 static const Uint32 PEG_TRACE_COMPONENT = traceComponent; \
581 if (Tracer::isTraceOn()) \
582 { \
583 Tracer::traceEnter( \
584 __FILE__,__LINE__,PEG_TRACE_COMPONENT,PEG_METHOD_NAME); \
585 } \
|
586 kumpf 1.5
587 /** Macro for tracing method exit
588 */
|
589 mike 1.22 # define PEG_METHOD_EXIT() \
590 do \
591 { \
592 if (Tracer::isTraceOn()) \
593 Tracer::traceExit( \
594 __FILE__,__LINE__,PEG_TRACE_COMPONENT,PEG_METHOD_NAME); \
595 } \
596 while (0)
|
597 kumpf 1.6
598 /** Macro for tracing a string
599 @param traceComponent component being traced
600 @param traceLevel trace level of the trace message
601 @param traceString the string to be traced
602 */
|
603 mike 1.22 # define PEG_TRACE_STRING(traceComponent,traceLevel,traceString) \
|
604 mike 1.21 do \
605 { \
606 if (Tracer::isTraceOn()) \
607 Tracer::trace( \
608 __FILE__, __LINE__,traceComponent,traceLevel,traceString); \
609 } \
610 while (0)
|
611 mday 1.8
|
612 mike 1.22 # define PEG_TRACE(VAR_ARGS) \
613 do \
614 { \
615 if (Tracer::isTraceOn()) \
616 Tracer::trace VAR_ARGS; \
617 } \
618 while (0)
619
|
620 mike 1.2 #endif
621
622 PEGASUS_NAMESPACE_END
623
624 #endif /* Pegasus_Tracer_h */
|