9
9
10
10
#include < cassert>
11
11
#include < cstdio>
12
+ #include < iostream>
12
13
#include < map>
13
14
#include < mutex>
14
15
#include < sstream>
@@ -113,10 +114,10 @@ class Subscribers {
113
114
// xptiTraceInit() and xptiTraceFinish() functions. If these are not
114
115
// present, then the plugin will be ruled an invalid plugin and unloaded
115
116
// 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" ) );
120
121
if (InitFunc && FiniFunc) {
121
122
// We appear to have loaded a valid plugin, so we will insert the
122
123
// plugin information into the two maps guarded by a lock
@@ -142,7 +143,7 @@ class Subscribers {
142
143
} else {
143
144
// Get error from errno
144
145
if (!Error.empty ())
145
- printf ( " [%s ]: %s \n " , Path, Error. c_str ()) ;
146
+ std::cout << ' [ ' << Path << " ]: " << Error << ' \n ' ;
146
147
}
147
148
return Handle;
148
149
}
@@ -215,7 +216,7 @@ class Subscribers {
215
216
auto SubscriberHandle = loadPlugin (Path.c_str ());
216
217
if (!SubscriberHandle) {
217
218
ValidSubscribers--;
218
- printf ( " Failed to load %s successfully... \n " , Path. c_str ()) ;
219
+ std::cout << " Failed to load " << Path << " successfully\n " ;
219
220
}
220
221
}
221
222
}
@@ -265,7 +266,7 @@ class Tracepoints {
265
266
#endif
266
267
267
268
Tracepoints (xpti::StringTable &st)
268
- : MUId(1 ), MInsertions( 0 ), MRetrievals (0 ), MStringTableRef(st ) {
269
+ : MUId(1 ), MStringTableRef(st ), MInsertions (0 ), MRetrievals( 0 ) {
269
270
// Nothing requires to be done at construction time
270
271
}
271
272
@@ -381,9 +382,9 @@ class Tracepoints {
381
382
//
382
383
void printStatistics () {
383
384
#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 " ;
387
388
MPayloadLUT.printStatistics ();
388
389
#endif
389
390
}
@@ -404,17 +405,19 @@ class Tracepoints {
404
405
if (Payload->flags == 0 )
405
406
return HashValue;
406
407
// 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) )
408
409
return Payload->internal ;
409
410
410
411
// Add the string information to the string table and use the string IDs
411
412
// (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))) {
413
415
// Add the kernel name to the string table; if the add() returns the
414
416
// address to the string in the string table, we can avoid a query [TBD]
415
417
Payload->name_sid = MStringTableRef.add (Payload->name , &Payload->name );
416
418
// 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)) {
418
421
// Add source file information ot string table
419
422
Payload->source_file_sid =
420
423
MStringTableRef.add (Payload->source_file , &Payload->source_file );
@@ -435,15 +438,20 @@ class Tracepoints {
435
438
// them. However, if we use the address, which would be the object
436
439
// address, they both will have different addresses even if they
437
440
// 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 );
439
444
uint16_t SrcFileNamePack =
440
- ( uint16_t ) (Payload->source_file_sid & 0x0000ffff );
445
+ static_cast < uint16_t > (Payload->source_file_sid & 0x0000ffff );
441
446
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 );
444
451
HashValue = XPTI_PACK32_RET64 (Address, KernelIDPack);
445
452
// 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);
447
455
Payload->internal = HashValue;
448
456
return HashValue;
449
457
} else {
@@ -454,10 +462,11 @@ class Tracepoints {
454
462
// will use 22 bits of the source file and kernel name ids and form a
455
463
// 64-bit value with the middle 22-bits being zero representing the
456
464
// 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 ;
459
467
// 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)) {
461
470
MiddlePart = Payload->line_no & Mask22Bits;
462
471
MiddlePart = MiddlePart << 22 ;
463
472
}
@@ -467,36 +476,40 @@ class Tracepoints {
467
476
// The rightmost 22-bits will represent the kernel name string id
468
477
RightPart = Payload->name_sid & Mask22Bits;
469
478
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);
471
481
Payload->internal = HashValue;
472
482
return HashValue;
473
483
}
474
484
} else if (Payload->flags &
475
- ( uint64_t ) payload_flag_t ::CodePointerAvailable) {
485
+ static_cast < uint64_t >( payload_flag_t ::CodePointerAvailable) ) {
476
486
// We have both kernel name and kernel address; we use bits 5-36 from
477
487
// 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 );
480
492
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) ;
482
494
Payload->internal = HashValue;
483
495
return HashValue;
484
496
} else {
485
497
// We only have kernel name and this is suspect if the kernel names are
486
498
// not unique and will replace any previously stored payload information
487
499
if (Payload->name_sid != xpti::invalid_id) {
488
500
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);
490
503
Payload->internal = HashValue;
491
504
return HashValue;
492
505
}
493
506
}
494
507
} else if (Payload->flags &
495
- ( uint64_t ) payload_flag_t ::CodePointerAvailable) {
508
+ static_cast < uint64_t >( payload_flag_t ::CodePointerAvailable) ) {
496
509
// We are only going to look at Kernel address when kernel name is not
497
510
// 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) ;
500
513
Payload->internal = HashValue;
501
514
return HashValue;
502
515
}
@@ -575,7 +588,7 @@ class Tracepoints {
575
588
#ifndef XPTI_USE_TBB
576
589
std::lock_guard<std::mutex> Lock (MCodePtrMutex);
577
590
#endif
578
- MCodePtrLUT[( uint64_t ) TempPayload.code_ptr_va ] = UId;
591
+ MCodePtrLUT[reinterpret_cast < uint64_t >( TempPayload.code_ptr_va ) ] = UId;
579
592
}
580
593
// We also want to query the payload by universal ID that has been
581
594
// generated
@@ -888,7 +901,7 @@ class Notifications {
888
901
class Framework {
889
902
public:
890
903
Framework ()
891
- : MTracepoints(MStringTableRef ), MUniversalIDs( 0 ), MTraceEnabled(false ) {
904
+ : MUniversalIDs( 0 ), MTracepoints(MStringTableRef ), MTraceEnabled(false ) {
892
905
// Load all subscribers on construction
893
906
MSubscribers.loadFromEnvironmentVariable ();
894
907
MTraceEnabled =
0 commit comments