CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
SimpleProfiler Class Reference

#include <SimpleProfiler.h>

Public Types

typedef VoidVec::size_type size_type
 
typedef std::vector< void * > VoidVec
 

Public Member Functions

void commitFrame (void **first, void **last)
 
void * stackTop ()
 
void start ()
 
void stop ()
 
void ** tempStack ()
 
size_type tempStackSize ()
 

Static Public Member Functions

static SimpleProfilerinstance ()
 

Private Member Functions

void complete ()
 
void doWrite ()
 
 SimpleProfiler ()
 
 ~SimpleProfiler ()
 

Private Attributes

void ** curr_
 
int fd_
 
std::string filename_
 
VoidVec frame_data_
 
void ** high_water_
 
bool installed_
 
pthread_t owner_
 
bool running_
 
void * stacktop_
 
VoidVec tmp_stack_
 

Static Private Attributes

static SimpleProfilerinst_ = 0
 
static boost::mutex lock_
 

Detailed Description

Definition at line 12 of file SimpleProfiler.h.

Member Typedef Documentation

typedef VoidVec::size_type SimpleProfiler::size_type

Definition at line 16 of file SimpleProfiler.h.

typedef std::vector<void*> SimpleProfiler::VoidVec

Definition at line 15 of file SimpleProfiler.h.

Constructor & Destructor Documentation

SimpleProfiler::SimpleProfiler ( )
private

Definition at line 551 of file SimpleProfiler.cc.

References fd_, and filename_.

551  :
552  frame_data_(10*1000*1000),
553  tmp_stack_(1000),
554  high_water_(&frame_data_[10*1000*1000-10*1000]),
555  curr_(&frame_data_[0]),
557  fd_(open(filename_.c_str(),
558  O_RDWR|O_CREAT,
559  S_IRWXU|S_IRGRP|S_IROTH|S_IWGRP|S_IWOTH)),
560  installed_(false),
561  running_(false),
562  owner_(),
563  stacktop_(setStacktop()) {
564  if(fd_ < 0) {
565  std::ostringstream ost;
566  ost << "failed to open profiler output file " << filename_;
567  throw std::runtime_error(ost.str().c_str());
568  }
569  openCondFile();
570 }
std::string makeFileName(const std::string &base, int num)
Definition: TestConsumer.cc:18
pthread_t owner_
VoidVec frame_data_
VoidVec tmp_stack_
std::string filename_
void ** high_water_
SimpleProfiler::~SimpleProfiler ( )
private

Definition at line 572 of file SimpleProfiler.cc.

References dtNoiseDBValidation_cfg::cerr, filename_, and running_.

572  {
573  if(running_) {
574  std::cerr << "Warning: the profile timer was not stopped,\n"
575  << "profiling data in " << filename_
576  << " is probably incomplete and will not be processed\n";
577  }
578  closeCondFile();
579 }
std::string filename_

Member Function Documentation

void SimpleProfiler::commitFrame ( void **  first,
void **  last 
)

Definition at line 581 of file SimpleProfiler.cc.

References filterCSVwithJSON::copy, curr_, doWrite(), and high_water_.

Referenced by sigFunc().

581  {
582  void** cnt_ptr = curr_;
583  *cnt_ptr = reinterpret_cast<void*>(std::distance(first, last));
584  ++curr_;
586  if(curr_ > high_water_) doWrite();
587 }
void ** high_water_
bool first
Definition: L1TdeRCT.cc:94
void SimpleProfiler::complete ( )
private

Definition at line 663 of file SimpleProfiler.cc.

References dtNoiseDBValidation_cfg::cerr, doWrite(), fd_, filename_, edmtest::makeFileName(), and writeProfileData().

Referenced by stop().

663  {
664  doWrite();
665 
666  if(lseek(fd_, 0, SEEK_SET) < 0) {
667  std::cerr << "SimpleProfiler: could not seek to the start of the profile\n"
668  << " data file during completion. Data will be lost.\n";
669  return;
670  }
671 
673  write_maps();
674 
675  std::string totsname = makeFileName();
676  totsname += "_sample_info";
677  std::ofstream ost(totsname.c_str());
678 
679  ost << "samples_total " << samples_total << "\n"
680  << "samples_missing_framepointer " << samples_missing_framepointer << "\n" ;
681 }
std::string makeFileName(const std::string &base, int num)
Definition: TestConsumer.cc:18
std::string filename_
void writeProfileData(int fd, const std::string &prefix)
Definition: ProfParse.cc:159
void SimpleProfiler::doWrite ( )
private

Definition at line 589 of file SimpleProfiler.cc.

References curr_, fd_, frame_data_, start(), and TablePrint::write.

Referenced by commitFrame(), and complete().

589  {
590  void** start = &frame_data_[0];
591  if(curr_ == start) return;
592  unsigned int cnt = std::distance(start, curr_) * sizeof(void*);
593  unsigned int totwr = 0;
594 
595  while(cnt>0 && (totwr = write(fd_, start, cnt)) != cnt) {
596  if(totwr == 0)
597  throw std::runtime_error("SimpleProfiler::doWrite wrote zero bytes");
598  start += (totwr/sizeof(void*));
599  cnt -= totwr;
600  }
601 
602  curr_ = &frame_data_[0];
603 }
VoidVec frame_data_
SimpleProfiler * SimpleProfiler::instance ( )
static

Definition at line 540 of file SimpleProfiler.cc.

References inst_, lock_, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by edm::service::SimpleProfiling::postBeginJob(), edm::service::SimpleProfiling::postEndJob(), and sigFunc().

540  {
541  if(SimpleProfiler::inst_ == 0) {
542  boost::mutex::scoped_lock sl(lock_);
543  if(SimpleProfiler::inst_ == 0) {
544  static SimpleProfiler p;
546  }
547  }
548  return SimpleProfiler::inst_;
549 }
static SimpleProfiler * inst_
static boost::mutex lock_
void* SimpleProfiler::stackTop ( )
inline

Definition at line 23 of file SimpleProfiler.h.

References stacktop_.

23 { return stacktop_; }
void SimpleProfiler::start ( void  )

Definition at line 610 of file SimpleProfiler.cc.

References dtNoiseDBValidation_cfg::cerr, installed_, lock_, owner_, and running_.

Referenced by progressbar.ProgressBar::__next__(), doWrite(), and edm::service::SimpleProfiling::postBeginJob().

610  {
611  {
612  boost::mutex::scoped_lock sl(lock_);
613 
614  if(installed_) {
615  std::cerr << "Warning: second thread " << pthread_self()
616  << " requested the profiler timer and another thread\n"
617  << owner_ << "has already started it.\n"
618  << "Only one thread can do profiling at a time.\n"
619  << "This second thread will not be profiled.\n";
620  return;
621  }
622 
623  installed_ = true;
624  }
625 
626  owner_ = pthread_self();
627  setupTimer();
628  running_ = true;
629 }
pthread_t owner_
static boost::mutex lock_
void SimpleProfiler::stop ( )

Definition at line 632 of file SimpleProfiler.cc.

References dtNoiseDBValidation_cfg::cerr, complete(), installed_, owner_, and running_.

Referenced by edm::service::SimpleProfiling::postEndJob().

632  {
633  if(!installed_) {
634  std::cerr << "SimpleProfiler::stop - no timer installed to stop\n";
635  return;
636  }
637 
638  if(owner_ != pthread_self()) {
639  std::cerr << "SimpleProfiler::stop - only owning thread can stop the timer\n";
640  return;
641  }
642 
643  if(!running_) {
644  std::cerr << "SimpleProfiler::stop - no timer is running\n";
645  return;
646  }
647 
648  struct itimerval newval;
649 
650  newval.it_interval.tv_sec = 0;
651  newval.it_interval.tv_usec = 0;
652  newval.it_value.tv_sec = 0;
653  newval.it_value.tv_usec = 0;
654 
655  if(setitimer(ITIMER_PROF, &newval, 0) != 0) {
656  perror("setitimer call failed - could not stop the timer");
657  }
658 
659  running_ = false;
660  complete();
661 }
pthread_t owner_
void** SimpleProfiler::tempStack ( )
inline

Definition at line 24 of file SimpleProfiler.h.

References tmp_stack_.

Referenced by sigFunc().

24 { return &tmp_stack_[0]; }
VoidVec tmp_stack_
size_type SimpleProfiler::tempStackSize ( )
inline

Definition at line 25 of file SimpleProfiler.h.

References tmp_stack_.

Referenced by sigFunc().

25 { return tmp_stack_.size(); }
VoidVec tmp_stack_

Member Data Documentation

void** SimpleProfiler::curr_
private

Definition at line 41 of file SimpleProfiler.h.

Referenced by commitFrame(), and doWrite().

int SimpleProfiler::fd_
private

Definition at line 43 of file SimpleProfiler.h.

Referenced by complete(), doWrite(), and SimpleProfiler().

std::string SimpleProfiler::filename_
private

Definition at line 42 of file SimpleProfiler.h.

Referenced by complete(), SimpleProfiler(), and ~SimpleProfiler().

VoidVec SimpleProfiler::frame_data_
private

Definition at line 38 of file SimpleProfiler.h.

Referenced by doWrite().

void** SimpleProfiler::high_water_
private

Definition at line 40 of file SimpleProfiler.h.

Referenced by commitFrame().

SimpleProfiler * SimpleProfiler::inst_ = 0
staticprivate

Definition at line 36 of file SimpleProfiler.h.

Referenced by instance().

bool SimpleProfiler::installed_
private

Definition at line 44 of file SimpleProfiler.h.

Referenced by start(), and stop().

boost::mutex SimpleProfiler::lock_
staticprivate

Definition at line 37 of file SimpleProfiler.h.

Referenced by instance(), and start().

pthread_t SimpleProfiler::owner_
private

Definition at line 46 of file SimpleProfiler.h.

Referenced by start(), and stop().

bool SimpleProfiler::running_
private

Definition at line 45 of file SimpleProfiler.h.

Referenced by start(), stop(), and ~SimpleProfiler().

void* SimpleProfiler::stacktop_
private

Definition at line 47 of file SimpleProfiler.h.

Referenced by stackTop().

VoidVec SimpleProfiler::tmp_stack_
private

Definition at line 39 of file SimpleProfiler.h.

Referenced by tempStack(), and tempStackSize().