CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

ProfilerService Class Reference

#include <ProfilerService.h>

List of all members.

Public Member Functions

bool active () const
 true if instrumentation is active
void beginEventI (const edm::EventID &, const edm::Timestamp &)
void beginPathI (std::string const &path)
bool doEvent () const
 true if the current event has to be instrumented
void dumpStat () const
 dump profiling information
void endEventI (const edm::Event &, const edm::EventSetup &)
void endPathI (std::string const &path, const edm::HLTPathStatus &)
bool forceStopInstrumentation ()
 forced stop instrumentation independenly of activity status; true if stopped now
bool pauseInstrumentation ()
void preSourceI ()
 ProfilerService (edm::ParameterSet const &pset, edm::ActivityRegistry &activity)
 Standard Service Constructor.
bool resumeInstrumentation ()
bool startInstrumentation ()
 start instrumentation if not active. true if started now
bool stopInstrumentation ()
 stop instrumentation if not active anymore; true if stopped now
 ~ProfilerService ()
 Destructor.

Private Member Functions

void beginEvent ()
void beginPath (std::string const &path)
void endEvent ()
void endPath (std::string const &path)
void fullEvent ()
void newEvent ()

Private Attributes

int m_active
std::string m_activePath
bool m_allPaths
int m_counts
bool m_doEvent
int m_dumpInterval
int m_evtCount
std::vector< std::string > m_excludedPaths
int m_firstEvent
int m_lastEvent
std::vector< std::string > m_paths
bool m_paused

Detailed Description

A Service to start and stop calgrind profiling on demand... act also as profiler watchdog (in the same service to avoid dependency between service)

Definition at line 18 of file ProfilerService.h.


Constructor & Destructor Documentation

ProfilerService::ProfilerService ( edm::ParameterSet const &  pset,
edm::ActivityRegistry activity 
)

Standard Service Constructor.

Definition at line 12 of file ProfilerService.cc.

References beginEventI(), beginPathI(), endEventI(), endPathI(), spr::find(), fullEvent(), m_allPaths, m_paths, preSourceI(), edm::ActivityRegistry::watchPostProcessEvent(), edm::ActivityRegistry::watchPostProcessPath(), edm::ActivityRegistry::watchPostSource(), edm::ActivityRegistry::watchPreProcessEvent(), and edm::ActivityRegistry::watchPreProcessPath().

                                                                  :
  
  m_firstEvent(pset.getUntrackedParameter<int>("firstEvent",0 )),
  m_lastEvent(pset.getUntrackedParameter<int>("lastEvent",std::numeric_limits<int>::max())),
  m_dumpInterval(pset.getUntrackedParameter<int>("dumpInterval",100)),
  m_paths(pset.getUntrackedParameter<std::vector<std::string> >("paths",std::vector<std::string>() )),
  m_excludedPaths(pset.getUntrackedParameter<std::vector<std::string> >("excludePaths",std::vector<std::string>() )),
  m_allPaths(false),
  m_evtCount(0),
  m_counts(0),
  m_doEvent(false),
  m_active(0),
  m_paused(false) {
  static std::string const allPaths("ALL");
  m_allPaths = std::find(m_paths.begin(),m_paths.end(),allPaths) != m_paths.end();
  
  // either FullEvent or selected path
  static std::string const fullEvent("FullEvent");
  if (std::find(m_paths.begin(),m_paths.end(),fullEvent) != m_paths.end())
    activity.watchPostSource(this,&ProfilerService::preSourceI);
  else {
    activity.watchPreProcessEvent(this,&ProfilerService::beginEventI);
    activity.watchPostProcessEvent(this,&ProfilerService::endEventI);
    activity.watchPreProcessPath(this,&ProfilerService::beginPathI);
    activity.watchPostProcessPath(this,&ProfilerService::endPathI);
  }
}
ProfilerService::~ProfilerService ( )

Destructor.

Definition at line 41 of file ProfilerService.cc.

References dumpStat().

                                 {
  dumpStat();
}

Member Function Documentation

bool ProfilerService::active ( void  ) const [inline]

true if instrumentation is active

Definition at line 54 of file ProfilerService.h.

References m_active.

{ return m_active>0;}
void ProfilerService::beginEvent ( ) [private]

Definition at line 117 of file ProfilerService.cc.

References m_allPaths, newEvent(), and startInstrumentation().

Referenced by beginEventI().

                                  {
  newEvent();
  //  static std::string const fullEvent("FullEvent");
  //  if (std::find(m_paths.begin(),m_paths.end(),fullEvent) != m_paths.end())
  if (m_allPaths) 
    startInstrumentation();
}
void ProfilerService::beginEventI ( const edm::EventID ,
const edm::Timestamp  
) [inline]

Definition at line 63 of file ProfilerService.h.

References beginEvent().

Referenced by ProfilerService().

                                                           {
    beginEvent();
  }
void ProfilerService::beginPath ( std::string const &  path) [private]

Definition at line 131 of file ProfilerService.cc.

References doEvent(), spr::find(), m_activePath, m_excludedPaths, m_paths, getHLTPrescaleColumns::path, pauseInstrumentation(), and startInstrumentation().

Referenced by beginPathI().

                                                       {
  if (!doEvent()) return;
  // assume less than 5-6 path to instrument or to exclude
  if (std::find(m_excludedPaths.begin(),m_excludedPaths.end(),path) != m_excludedPaths.end()) {
    pauseInstrumentation();
    return; 
  }
  if (std::find(m_paths.begin(),m_paths.end(),path) == m_paths.end()) return; 
  m_activePath=path;
  startInstrumentation();
}
void ProfilerService::beginPathI ( std::string const &  path) [inline]

Definition at line 70 of file ProfilerService.h.

References beginPath().

Referenced by ProfilerService().

                                          {
    beginPath(path);
  }
bool ProfilerService::doEvent ( ) const [inline]

true if the current event has to be instrumented

Definition at line 51 of file ProfilerService.h.

References m_doEvent.

Referenced by beginPath(), and startInstrumentation().

{ return m_doEvent;}
void ProfilerService::dumpStat ( ) const

dump profiling information

Definition at line 94 of file ProfilerService.cc.

Referenced by fullEvent(), resumeInstrumentation(), startInstrumentation(), and ~ProfilerService().

                                     {
     CALLGRIND_DUMP_STATS;
}
void ProfilerService::endEvent ( ) [private]

Definition at line 125 of file ProfilerService.cc.

References forceStopInstrumentation(), and stopInstrumentation().

Referenced by endEventI().

                                {
  stopInstrumentation();
  // force, a nested instrumentation may fail to close in presence of filters
  forceStopInstrumentation();
}
void ProfilerService::endEventI ( const edm::Event ,
const edm::EventSetup  
) [inline]

Definition at line 67 of file ProfilerService.h.

References endEvent().

Referenced by ProfilerService().

                                                        {
    endEvent();
  }
void ProfilerService::endPath ( std::string const &  path) [private]

Definition at line 143 of file ProfilerService.cc.

References m_activePath, resumeInstrumentation(), and stopInstrumentation().

Referenced by endPathI().

                                                     {
  resumeInstrumentation();
  if (m_activePath==path) {
    stopInstrumentation();
    m_activePath.clear();
  }
  // do to force, a nested instrumentation may fail to close in presence of filters  
  // forceStopInstrumentation();
}
void ProfilerService::endPathI ( std::string const &  path,
const edm::HLTPathStatus  
) [inline]

Definition at line 73 of file ProfilerService.h.

References endPath().

Referenced by ProfilerService().

                                                                  {
    endPath(path);
  }
bool ProfilerService::forceStopInstrumentation ( )

forced stop instrumentation independenly of activity status; true if stopped now

Definition at line 70 of file ProfilerService.cc.

References m_active.

Referenced by endEvent(), and fullEvent().

                                               {
  if (m_active==0) return false;
  // FIXME report something if appens;
  CALLGRIND_STOP_INSTRUMENTATION;
  m_active=0;
  return true;
}
void ProfilerService::fullEvent ( ) [private]

Definition at line 105 of file ProfilerService.cc.

References dumpStat(), forceStopInstrumentation(), m_active, m_doEvent, newEvent(), startInstrumentation(), and stopInstrumentation().

Referenced by preSourceI(), and ProfilerService().

                                {
  newEvent();
  if(m_doEvent&&m_active==0)
    startInstrumentation();
  if ( (!m_doEvent) && m_active!=0) {
    stopInstrumentation();
    // force, a nested instrumentation may fail to close in presence of filters
    forceStopInstrumentation();
    dumpStat();
  }
}
void ProfilerService::newEvent ( ) [private]

Definition at line 99 of file ProfilerService.cc.

References m_doEvent, m_evtCount, m_firstEvent, and m_lastEvent.

Referenced by beginEvent(), and fullEvent().

bool ProfilerService::pauseInstrumentation ( )

Definition at line 78 of file ProfilerService.cc.

References m_active, and m_paused.

Referenced by beginPath().

                                           {
   if (m_active==0) return false;
   CALLGRIND_STOP_INSTRUMENTATION;
   m_paused=true;
   return true;
}   
void ProfilerService::preSourceI ( ) [inline]

Definition at line 59 of file ProfilerService.h.

References fullEvent().

Referenced by ProfilerService().

                    {
    fullEvent();
  }
bool ProfilerService::resumeInstrumentation ( )

Definition at line 85 of file ProfilerService.cc.

References dumpStat(), m_active, m_counts, m_dumpInterval, and m_paused.

Referenced by endPath().

                                            {
  if (m_active==0 || (!m_paused)) return false;
  CALLGRIND_START_INSTRUMENTATION;
  if (m_counts%m_dumpInterval==0) dumpStat();
  ++m_counts;
  m_paused=false;
  return true;
}
bool ProfilerService::startInstrumentation ( )

start instrumentation if not active. true if started now

Definition at line 47 of file ProfilerService.cc.

References doEvent(), dumpStat(), m_active, m_counts, and m_dumpInterval.

Referenced by beginEvent(), beginPath(), and fullEvent().

                                          {
  // FIXME here or in client?
  if (!doEvent()) return false;


  if (m_active==0) {
    CALLGRIND_START_INSTRUMENTATION;
    if (m_counts%m_dumpInterval==0) dumpStat();
    ++m_counts;
  }
  // support nested start/stop
  ++m_active;
  return m_active==1;
}
bool ProfilerService::stopInstrumentation ( )

stop instrumentation if not active anymore; true if stopped now

Definition at line 62 of file ProfilerService.cc.

References m_active.

Referenced by endEvent(), endPath(), and fullEvent().

                                          {
  if (m_active==0) return false;
  --m_active;
  if (m_active==0)
    CALLGRIND_STOP_INSTRUMENTATION;
  return m_active==0;
}

Member Data Documentation

std::string ProfilerService::m_activePath [private]

Definition at line 103 of file ProfilerService.h.

Referenced by beginPath(), and endPath().

Definition at line 95 of file ProfilerService.h.

Referenced by beginEvent(), and ProfilerService().

Definition at line 99 of file ProfilerService.h.

Referenced by resumeInstrumentation(), and startInstrumentation().

Definition at line 100 of file ProfilerService.h.

Referenced by doEvent(), fullEvent(), and newEvent().

Definition at line 92 of file ProfilerService.h.

Referenced by resumeInstrumentation(), and startInstrumentation().

Definition at line 98 of file ProfilerService.h.

Referenced by newEvent().

std::vector<std::string> ProfilerService::m_excludedPaths [private]

Definition at line 94 of file ProfilerService.h.

Referenced by beginPath().

Definition at line 90 of file ProfilerService.h.

Referenced by newEvent().

Definition at line 91 of file ProfilerService.h.

Referenced by newEvent().

std::vector<std::string> ProfilerService::m_paths [private]

Definition at line 93 of file ProfilerService.h.

Referenced by beginPath(), and ProfilerService().

bool ProfilerService::m_paused [private]

Definition at line 102 of file ProfilerService.h.

Referenced by pauseInstrumentation(), and resumeInstrumentation().