99
1010#include < cassert>
1111#include < cstdio>
12+ #include < iostream>
1213#include < map>
1314#include < mutex>
1415#include < sstream>
@@ -113,10 +114,10 @@ class Subscribers {
113114 // xptiTraceInit() and xptiTraceFinish() functions. If these are not
114115 // present, then the plugin will be ruled an invalid plugin and unloaded
115116 // from the process.
116- xpti::plugin_init_t InitFunc =
117- (xpti:: plugin_init_t ) g_helper.findFunction (Handle, " xptiTraceInit" );
118- xpti::plugin_fini_t FiniFunc =
119- (xpti:: plugin_fini_t ) g_helper.findFunction (Handle, " xptiTraceFinish" );
117+ xpti::plugin_init_t InitFunc = reinterpret_cast <xpti:: plugin_init_t >(
118+ g_helper.findFunction (Handle, " xptiTraceInit" ) );
119+ xpti::plugin_fini_t FiniFunc = reinterpret_cast <xpti:: plugin_fini_t >(
120+ g_helper.findFunction (Handle, " xptiTraceFinish" ) );
120121 if (InitFunc && FiniFunc) {
121122 // We appear to have loaded a valid plugin, so we will insert the
122123 // plugin information into the two maps guarded by a lock
@@ -142,7 +143,7 @@ class Subscribers {
142143 } else {
143144 // Get error from errno
144145 if (!Error.empty ())
145- printf ( " [%s ]: %s \n " , Path, Error. c_str ()) ;
146+ std::cout << ' [ ' << Path << " ]: " << Error << ' \n ' ;
146147 }
147148 return Handle;
148149 }
@@ -215,7 +216,7 @@ class Subscribers {
215216 auto SubscriberHandle = loadPlugin (Path.c_str ());
216217 if (!SubscriberHandle) {
217218 ValidSubscribers--;
218- printf ( " Failed to load %s successfully... \n " , Path. c_str ()) ;
219+ std::cout << " Failed to load " << Path << " successfully\n " ;
219220 }
220221 }
221222 }
@@ -265,7 +266,7 @@ class Tracepoints {
265266#endif
266267
267268 Tracepoints (xpti::StringTable &st)
268- : MUId(1 ), MInsertions( 0 ), MRetrievals (0 ), MStringTableRef(st ) {
269+ : MUId(1 ), MStringTableRef(st ), MInsertions (0 ), MRetrievals( 0 ) {
269270 // Nothing requires to be done at construction time
270271 }
271272
@@ -381,9 +382,9 @@ class Tracepoints {
381382 //
382383 void printStatistics () {
383384#ifdef XPTI_STATISTICS
384- printf ( " Tracepoint inserts : [%lu] \n " , MInsertions.load ()) ;
385- printf ( " Tracepoint lookups : [%lu] \n " , MRetrievals.load ()) ;
386- printf ( " Tracepoint Hashmap :\n " ) ;
385+ std::cout << " Tracepoint inserts : " << MInsertions.load () << ' \n ' ;
386+ std::cout << " Tracepoint lookups : " << MRetrievals.load () << ' \n ' ;
387+ std::cout << " Tracepoint Hashmap :\n " ;
387388 MPayloadLUT.printStatistics ();
388389#endif
389390 }
@@ -404,17 +405,19 @@ class Tracepoints {
404405 if (Payload->flags == 0 )
405406 return HashValue;
406407 // If the hash value has been cached, return and bail early
407- if (Payload->flags & ( uint64_t ) payload_flag_t ::HashAvailable)
408+ if (Payload->flags & static_cast < uint64_t >( payload_flag_t ::HashAvailable) )
408409 return Payload->internal ;
409410
410411 // Add the string information to the string table and use the string IDs
411412 // (in addition to any unique addresses) to create a hash value
412- if ((Payload->flags & (uint64_t )payload_flag_t ::NameAvailable)) {
413+ if ((Payload->flags &
414+ static_cast <uint64_t >(payload_flag_t ::NameAvailable))) {
413415 // Add the kernel name to the string table; if the add() returns the
414416 // address to the string in the string table, we can avoid a query [TBD]
415417 Payload->name_sid = MStringTableRef.add (Payload->name , &Payload->name );
416418 // Payload->name = MStringTableRef.query(Payload->name_sid);
417- if (Payload->flags & (uint64_t )payload_flag_t ::SourceFileAvailable) {
419+ if (Payload->flags &
420+ static_cast <uint64_t >(payload_flag_t ::SourceFileAvailable)) {
418421 // Add source file information ot string table
419422 Payload->source_file_sid =
420423 MStringTableRef.add (Payload->source_file , &Payload->source_file );
@@ -435,15 +438,20 @@ class Tracepoints {
435438 // them. However, if we use the address, which would be the object
436439 // address, they both will have different addresses even if they
437440 // happen to be on the same line.
438- uint16_t NamePack = (uint16_t )(Payload->name_sid & 0x0000ffff );
441+ // TODO think of a more portable way to do the same thing.
442+ uint16_t NamePack =
443+ static_cast <uint16_t >(Payload->name_sid & 0x0000ffff );
439444 uint16_t SrcFileNamePack =
440- ( uint16_t ) (Payload->source_file_sid & 0x0000ffff );
445+ static_cast < uint16_t > (Payload->source_file_sid & 0x0000ffff );
441446 uint32_t KernelIDPack = XPTI_PACK16_RET32 (SrcFileNamePack, NamePack);
442- uint32_t Address = (uint32_t )(
443- ((uint64_t )Payload->code_ptr_va & 0x0000000ffffffff0 ) >> 4 );
447+ uint32_t Address = static_cast <uint32_t >(
448+ (reinterpret_cast <uint64_t >(Payload->code_ptr_va ) &
449+ 0x0000000ffffffff0 ) >>
450+ 4 );
444451 HashValue = XPTI_PACK32_RET64 (Address, KernelIDPack);
445452 // Cache the hash once it is computed
446- Payload->flags |= (uint64_t )payload_flag_t ::HashAvailable;
453+ Payload->flags |=
454+ static_cast <uint64_t >(payload_flag_t ::HashAvailable);
447455 Payload->internal = HashValue;
448456 return HashValue;
449457 } else {
@@ -454,10 +462,11 @@ class Tracepoints {
454462 // will use 22 bits of the source file and kernel name ids and form a
455463 // 64-bit value with the middle 22-bits being zero representing the
456464 // line number.
457- uint64_t LeftPart = 0 , MiddlePart = 0 , RightPart = 0 ,
458- Mask22Bits = 0x00000000003fffff ;
465+ uint64_t LeftPart = 0 , MiddlePart = 0 , RightPart = 0 ;
466+ constexpr uint64_t Mask22Bits = 0x00000000003fffff ;
459467 // If line number info is available, extract 22-bits of it
460- if (Payload->flags & (uint64_t )payload_flag_t ::LineInfoAvailable) {
468+ if (Payload->flags &
469+ static_cast <uint64_t >(payload_flag_t ::LineInfoAvailable)) {
461470 MiddlePart = Payload->line_no & Mask22Bits;
462471 MiddlePart = MiddlePart << 22 ;
463472 }
@@ -467,36 +476,40 @@ class Tracepoints {
467476 // The rightmost 22-bits will represent the kernel name string id
468477 RightPart = Payload->name_sid & Mask22Bits;
469478 HashValue = LeftPart | MiddlePart | RightPart;
470- Payload->flags |= (uint64_t )payload_flag_t ::HashAvailable;
479+ Payload->flags |=
480+ static_cast <uint64_t >(payload_flag_t ::HashAvailable);
471481 Payload->internal = HashValue;
472482 return HashValue;
473483 }
474484 } else if (Payload->flags &
475- ( uint64_t ) payload_flag_t ::CodePointerAvailable) {
485+ static_cast < uint64_t >( payload_flag_t ::CodePointerAvailable) ) {
476486 // We have both kernel name and kernel address; we use bits 5-36 from
477487 // the address and combine it with the kernel name string ID
478- uint32_t Address = (uint32_t )(
479- ((uint64_t )Payload->code_ptr_va & 0x0000000ffffffff0 ) >> 4 );
488+ uint32_t Address = static_cast <uint32_t >(
489+ (reinterpret_cast <uint64_t >(Payload->code_ptr_va ) &
490+ 0x0000000ffffffff0 ) >>
491+ 4 );
480492 HashValue = XPTI_PACK32_RET64 (Address, Payload->name_sid );
481- Payload->flags |= ( uint64_t ) payload_flag_t ::HashAvailable;
493+ Payload->flags |= static_cast < uint64_t >( payload_flag_t ::HashAvailable) ;
482494 Payload->internal = HashValue;
483495 return HashValue;
484496 } else {
485497 // We only have kernel name and this is suspect if the kernel names are
486498 // not unique and will replace any previously stored payload information
487499 if (Payload->name_sid != xpti::invalid_id) {
488500 HashValue = XPTI_PACK32_RET64 (0 , Payload->name_sid );
489- Payload->flags |= (uint64_t )payload_flag_t ::HashAvailable;
501+ Payload->flags |=
502+ static_cast <uint64_t >(payload_flag_t ::HashAvailable);
490503 Payload->internal = HashValue;
491504 return HashValue;
492505 }
493506 }
494507 } else if (Payload->flags &
495- ( uint64_t ) payload_flag_t ::CodePointerAvailable) {
508+ static_cast < uint64_t >( payload_flag_t ::CodePointerAvailable) ) {
496509 // We are only going to look at Kernel address when kernel name is not
497510 // available.
498- HashValue = ( uint64_t ) Payload->code_ptr_va ;
499- Payload->flags |= ( uint64_t ) payload_flag_t ::HashAvailable;
511+ HashValue = reinterpret_cast < uint64_t >( Payload->code_ptr_va ) ;
512+ Payload->flags |= static_cast < uint64_t >( payload_flag_t ::HashAvailable) ;
500513 Payload->internal = HashValue;
501514 return HashValue;
502515 }
@@ -575,7 +588,7 @@ class Tracepoints {
575588#ifndef XPTI_USE_TBB
576589 std::lock_guard<std::mutex> Lock (MCodePtrMutex);
577590#endif
578- MCodePtrLUT[( uint64_t ) TempPayload.code_ptr_va ] = UId;
591+ MCodePtrLUT[reinterpret_cast < uint64_t >( TempPayload.code_ptr_va ) ] = UId;
579592 }
580593 // We also want to query the payload by universal ID that has been
581594 // generated
@@ -888,7 +901,7 @@ class Notifications {
888901class Framework {
889902public:
890903 Framework ()
891- : MTracepoints(MStringTableRef ), MUniversalIDs( 0 ), MTraceEnabled(false ) {
904+ : MUniversalIDs( 0 ), MTracepoints(MStringTableRef ), MTraceEnabled(false ) {
892905 // Load all subscribers on construction
893906 MSubscribers.loadFromEnvironmentVariable ();
894907 MTraceEnabled =
0 commit comments