The Gaudi Framework  master (37c0b60a)
PerfProfile Struct Referencefinal

Algorithm to enable/disable profiling with Linux perf at given events. More...

Inheritance diagram for PerfProfile:
Collaboration diagram for PerfProfile:

Public Member Functions

StatusCode initialize () override
 
StatusCode finalize () override
 
void operator() () const override
 

Private Member Functions

void fifo_write (std::string_view s) const
 

Private Attributes

std::atomic< long unsigned > m_eventNumber = 0
 
int m_fifo = -1
 
Gaudi::Property< std::stringm_fifoPath { this, "FIFOPath", "GaudiPerfProfile.fifo", "Path to perf control FIFO." }
 
Gaudi::Property< unsigned long > m_nStartFromEvent
 
Gaudi::Property< unsigned long > m_nStopAtEvent
 

Detailed Description

Algorithm to enable/disable profiling with Linux perf at given events.

Needs at least perf 5.9. To control perf record, start it as

perf record -D -1 –control fifo:GaudiPerfProfile.fifo ... gaudirun.py ...

The path to the control fifo (GaudiPerfProfile.fifo) is configurable with the FIFOPath property. The fifo must be created before running perf.

Definition at line 26 of file PerfProfile.cpp.

Member Function Documentation

◆ fifo_write()

void PerfProfile::fifo_write ( std::string_view  s) const
inlineprivate

Definition at line 61 of file PerfProfile.cpp.

61  {
62  if ( ::write( m_fifo, s.data(), s.size() ) < ssize_t( s.size() ) ) {
63  error() << "Write of \"" << s << "\" to FIFO failed: " << ::strerror( errno ) << endmsg;
64  }
65  }

◆ finalize()

StatusCode PerfProfile::finalize ( )
inlineoverride

Definition at line 40 of file PerfProfile.cpp.

40  {
41  if ( m_fifo != -1 ) { ::close( m_fifo ); }
42  return Consumer::finalize();
43  }

◆ initialize()

StatusCode PerfProfile::initialize ( )
inlineoverride

Definition at line 29 of file PerfProfile.cpp.

29  {
30  return Consumer::initialize().andThen( [this]() {
31  m_fifo = ::open( m_fifoPath.value().c_str(), O_WRONLY | O_NONBLOCK );
32  if ( m_fifo == -1 ) {
33  fatal() << "open(\"" << m_fifoPath.value() << "\"): " << ::strerror( errno ) << endmsg;
34  return StatusCode::FAILURE;
35  }
36  return StatusCode::SUCCESS;
37  } );
38  }

◆ operator()()

void PerfProfile::operator() ( ) const
inlineoverride

Definition at line 45 of file PerfProfile.cpp.

45  {
46  // We could use EventContext::evt(), however it is not always valid, as is the case with EvtSel="NONE". Instead, use
47  // an atomic counter.
48  auto eventNumber = m_eventNumber++;
49  if ( eventNumber == m_nStartFromEvent.value() ) {
50  warning() << "Starting perf profile at event " << eventNumber << endmsg;
51  fifo_write( "enable\n" );
52  }
53 
54  if ( m_nStopAtEvent > 0 && eventNumber == m_nStopAtEvent.value() ) {
55  warning() << "Stopping perf profile at event " << eventNumber << endmsg;
56  fifo_write( "disable\n" );
57  }
58  }

Member Data Documentation

◆ m_eventNumber

std::atomic<long unsigned> PerfProfile::m_eventNumber = 0
mutableprivate

Definition at line 67 of file PerfProfile.cpp.

◆ m_fifo

int PerfProfile::m_fifo = -1
private

Definition at line 68 of file PerfProfile.cpp.

◆ m_fifoPath

Gaudi::Property<std::string> PerfProfile::m_fifoPath { this, "FIFOPath", "GaudiPerfProfile.fifo", "Path to perf control FIFO." }
private

Definition at line 70 of file PerfProfile.cpp.

◆ m_nStartFromEvent

Gaudi::Property<unsigned long> PerfProfile::m_nStartFromEvent
private
Initial value:
{ this, "StartFromEventN", 1,
"After what event we start profiling." }

Definition at line 71 of file PerfProfile.cpp.

◆ m_nStopAtEvent

Gaudi::Property<unsigned long> PerfProfile::m_nStopAtEvent
private
Initial value:
{
this, "StopAtEventN", 0,
"After what event we stop profiling. If 0 than we also profile finalization stage. Default = 0." }

Definition at line 73 of file PerfProfile.cpp.


The documentation for this struct was generated from the following file:
gaudirun.s
string s
Definition: gaudirun.py:346
PerfProfile::m_fifo
int m_fifo
Definition: PerfProfile.cpp:68
PerfProfile::m_fifoPath
Gaudi::Property< std::string > m_fifoPath
Definition: PerfProfile.cpp:70
PerfProfile::m_nStopAtEvent
Gaudi::Property< unsigned long > m_nStopAtEvent
Definition: PerfProfile.cpp:73
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
PerfProfile::m_eventNumber
std::atomic< long unsigned > m_eventNumber
Definition: PerfProfile.cpp:67
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
PerfProfile::m_nStartFromEvent
Gaudi::Property< unsigned long > m_nStartFromEvent
Definition: PerfProfile.cpp:71
PerfProfile::fifo_write
void fifo_write(std::string_view s) const
Definition: PerfProfile.cpp:61