#include <FWCore/Services/src/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 SimpleProfiler * | instance () |
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 SimpleProfiler * | inst_ = 0 |
static boost::mutex | lock_ |
Definition at line 12 of file SimpleProfiler.h.
Definition at line 16 of file SimpleProfiler.h.
typedef std::vector<void*> SimpleProfiler::VoidVec |
Definition at line 15 of file SimpleProfiler.h.
SimpleProfiler::SimpleProfiler | ( | ) | [private] |
Definition at line 576 of file SimpleProfiler.cc.
References fd_, filename_, and openCondFile().
00576 : 00577 frame_data_(10*1000*1000), 00578 tmp_stack_(1000), 00579 high_water_(&frame_data_[10*1000*1000-10*1000]), 00580 curr_(&frame_data_[0]), 00581 filename_(makeFileName()), 00582 fd_(open(filename_.c_str(), 00583 O_RDWR|O_CREAT, 00584 S_IRWXU|S_IRGRP|S_IROTH|S_IWGRP|S_IWOTH)), 00585 installed_(false), 00586 running_(false), 00587 owner_(), 00588 stacktop_(setStacktop()) 00589 { 00590 if (fd_ < 0) { 00591 std::ostringstream ost; 00592 ost << "failed to open profiler output file " << filename_; 00593 throw std::runtime_error(ost.str().c_str()); 00594 } 00595 00596 openCondFile(); 00597 }
SimpleProfiler::~SimpleProfiler | ( | ) | [private] |
Definition at line 599 of file SimpleProfiler.cc.
References TestMuL1L2Filter_cff::cerr, closeCondFile(), filename_, and running_.
00600 { 00601 if (running_) 00602 std::cerr << "Warning: the profile timer was not stopped,\n" 00603 << "profiling data in " << filename_ 00604 << " is probably incomplete and will not be processed\n"; 00605 00606 closeCondFile(); 00607 }
Definition at line 609 of file SimpleProfiler.cc.
References edmNew::copy(), curr_, doWrite(), and high_water_.
Referenced by sigFunc().
00610 { 00611 void** cnt_ptr = curr_; 00612 *cnt_ptr = reinterpret_cast<void*>(std::distance(first,last)); 00613 ++curr_; 00614 curr_ = std::copy(first,last,curr_); 00615 if(curr_ > high_water_) doWrite(); 00616 }
void SimpleProfiler::complete | ( | ) | [private] |
Definition at line 698 of file SimpleProfiler.cc.
References TestMuL1L2Filter_cff::cerr, doWrite(), fd_, filename_, makeFileName(), samples_missing_framepointer, samples_total, write_maps(), and writeProfileData().
Referenced by stop().
00699 { 00700 doWrite(); 00701 00702 if(lseek(fd_,0,SEEK_SET)<0) 00703 { 00704 std::cerr << "SimpleProfiler: could not seek to the start of the profile\n" 00705 << " data file during completion. Data will be lost.\n"; 00706 return; 00707 } 00708 00709 writeProfileData(fd_,filename_); 00710 write_maps(); 00711 00712 std::string totsname = makeFileName(); 00713 totsname += "_sample_info"; 00714 std::ofstream ost(totsname.c_str()); 00715 00716 ost << "samples_total " << samples_total << "\n" 00717 << "samples_missing_framepointer " << samples_missing_framepointer << "\n" ; 00718 }
void SimpleProfiler::doWrite | ( | ) | [private] |
Definition at line 618 of file SimpleProfiler.cc.
References curr_, fd_, frame_data_, and start().
Referenced by commitFrame(), and complete().
00619 { 00620 void** start = &frame_data_[0]; 00621 if(curr_ == start) return; 00622 unsigned int cnt = std::distance(start,curr_) * sizeof(void*); 00623 unsigned int totwr=0; 00624 00625 while (cnt>0 && (totwr=write(fd_,start,cnt)) != cnt) { 00626 if(totwr==0) 00627 throw std::runtime_error("SimpleProfiler::doWrite wrote zero bytes"); 00628 start+=(totwr/sizeof(void*)); 00629 cnt-=totwr; 00630 } 00631 00632 curr_ = &frame_data_[0]; 00633 }
SimpleProfiler * SimpleProfiler::instance | ( | void | ) | [static] |
Definition at line 562 of file SimpleProfiler.cc.
Referenced by edm::service::SimpleProfiling::postBeginJob(), edm::service::SimpleProfiling::postEndJob(), and sigFunc().
00563 { 00564 if(SimpleProfiler::inst_ == 0) 00565 { 00566 boost::mutex::scoped_lock sl(lock_); 00567 if(SimpleProfiler::inst_ == 0) 00568 { 00569 static SimpleProfiler p; 00570 SimpleProfiler::inst_ = &p; 00571 } 00572 } 00573 return SimpleProfiler::inst_; 00574 }
void* SimpleProfiler::stackTop | ( | ) | [inline] |
Definition at line 635 of file SimpleProfiler.cc.
References TestMuL1L2Filter_cff::cerr, installed_, lock_, owner_, running_, setupTimer(), and sl.
Referenced by doWrite(), and edm::service::SimpleProfiling::postBeginJob().
00636 { 00637 #if defined(__x86_64__) || defined(__LP64__) || defined(_LP64) 00638 throw std::logic_error("SimpleProfiler not available on 64 bit platform"); 00639 #endif 00640 { 00641 boost::mutex::scoped_lock sl(lock_); 00642 00643 if (installed_) { 00644 std::cerr << "Warning: second thread " << pthread_self() 00645 << " requested the profiler timer and another thread\n" 00646 << owner_ << "has already started it.\n" 00647 << "Only one thread can do profiling at a time.\n" 00648 << "This second thread will not be profiled.\n"; 00649 return; 00650 } 00651 00652 installed_ = true; 00653 } 00654 00655 owner_ = pthread_self(); 00656 setupTimer(); 00657 running_ = true; 00658 }
void SimpleProfiler::stop | ( | ) |
Definition at line 660 of file SimpleProfiler.cc.
References TestMuL1L2Filter_cff::cerr, complete(), installed_, owner_, and running_.
Referenced by edm::service::SimpleProfiling::postEndJob().
00661 { 00662 if(!installed_) 00663 { 00664 std::cerr << "SimpleProfiler::stop - no timer installed to stop\n"; 00665 return; 00666 } 00667 00668 if(owner_ != pthread_self()) 00669 { 00670 std::cerr << "SimpleProfiler::stop - only owning thread can stop the timer\n"; 00671 return; 00672 } 00673 00674 if(!running_) 00675 { 00676 std::cerr << "SimpleProfiler::stop - no timer is running\n"; 00677 return; 00678 } 00679 00680 struct itimerval newval; 00681 00682 newval.it_interval.tv_sec = 0; 00683 newval.it_interval.tv_usec = 0; 00684 newval.it_value.tv_sec = 0; 00685 newval.it_value.tv_usec = 0; 00686 00687 if(setitimer(ITIMER_PROF,&newval,0)!=0) 00688 { 00689 perror("setitimer call failed - could not stop the timer"); 00690 } 00691 00692 running_=false; 00693 complete(); 00694 }
void** SimpleProfiler::tempStack | ( | ) | [inline] |
Definition at line 24 of file SimpleProfiler.h.
References tmp_stack_.
Referenced by sigFunc().
00024 { return &tmp_stack_[0]; }
size_type SimpleProfiler::tempStackSize | ( | ) | [inline] |
Definition at line 25 of file SimpleProfiler.h.
References tmp_stack_.
Referenced by sigFunc().
00025 { return tmp_stack_.size(); }
void** SimpleProfiler::curr_ [private] |
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] |
void** SimpleProfiler::high_water_ [private] |
SimpleProfiler * SimpleProfiler::inst_ = 0 [static, private] |
Definition at line 36 of file SimpleProfiler.h.
bool SimpleProfiler::installed_ [private] |
boost::mutex SimpleProfiler::lock_ [static, private] |
pthread_t SimpleProfiler::owner_ [private] |
bool SimpleProfiler::running_ [private] |
Definition at line 45 of file SimpleProfiler.h.
Referenced by start(), stop(), and ~SimpleProfiler().
void* SimpleProfiler::stacktop_ [private] |
VoidVec SimpleProfiler::tmp_stack_ [private] |