CMS 3D CMS Logo

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

#include <Vulture.h>

Inheritance diagram for evf::Vulture:

Public Member Functions

int hasStarted ()
 
int hasStopped ()
 
pid_t kill ()
 
pid_t makeProcess ()
 
void retrieve_corefile (char *, char *, uint64_t)
 
int start (std::string, int=0)
 
int stop ()
 
 Vulture (bool)
 
virtual ~Vulture ()
 

Private Member Functions

void analyze ()
 
bool control (toolbox::task::WorkLoop *)
 
bool prowling (toolbox::task::WorkLoop *)
 
void startProwling ()
 

Private Attributes

toolbox::task::ActionSignature * asCtrl_
 
toolbox::task::ActionSignature * asProwl_
 
std::vector< std::string > currentCoreList_
 
bool handicapped_
 
std::string iDieUrl_
 
time_t lastUpdate_
 
MasterQueuemq_
 
unsigned int newCores_
 
CurlPosterposter_
 
bool prowling_
 
bool running_
 
SlaveQueuesq_
 
int started_
 
int stopped_
 
DIR * tmp_
 
bool updateMode_
 
pid_t vulturePid_
 
toolbox::task::WorkLoop * wlCtrl_
 
toolbox::task::WorkLoop * wlProwl_
 

Static Private Attributes

static const std::string FS ="/tmp"
 
static const int vulture_queue_offset = 400
 

Detailed Description

Definition at line 36 of file Vulture.h.

Constructor & Destructor Documentation

evf::Vulture::Vulture ( bool  push)

Definition at line 116 of file Vulture.cc.

117  : wlCtrl_(0)
118  , asCtrl_(0)
119  , running_(false)
120  , wlProwl_(0)
121  , asProwl_(0)
122  , prowling_(false)
123  , iDieUrl_("")
124  , updateMode_(push)
125  , vulturePid_(0)
126  , tmp_(0)
127  , newCores_(0)
128  , poster_(0)
129  , mq_(new MasterQueue(vulture_queue_offset))
130  , sq_(0) // this is only defined in the forked process
131  , started_(-1)
132  , stopped_(-1)
133  , handicapped_(false)
134  {
135  // create command file for gdb
136  FILE *outf = fopen("/tmp/vulture.cmd","w");
137  fprintf(outf,"where\n");
138  fclose(outf);
139  }
bool running_
Definition: Vulture.h:62
toolbox::task::WorkLoop * wlProwl_
Definition: Vulture.h:63
SlaveQueue * sq_
Definition: Vulture.h:75
bool updateMode_
Definition: Vulture.h:67
DIR * tmp_
Definition: Vulture.h:69
toolbox::task::ActionSignature * asCtrl_
Definition: Vulture.h:61
toolbox::task::ActionSignature * asProwl_
Definition: Vulture.h:64
toolbox::task::WorkLoop * wlCtrl_
Definition: Vulture.h:60
bool prowling_
Definition: Vulture.h:65
CurlPoster * poster_
Definition: Vulture.h:73
static const int vulture_queue_offset
Definition: Vulture.h:53
MasterQueue * mq_
Definition: Vulture.h:74
unsigned int newCores_
Definition: Vulture.h:72
bool handicapped_
Definition: Vulture.h:78
int stopped_
Definition: Vulture.h:77
int started_
Definition: Vulture.h:76
std::string iDieUrl_
Definition: Vulture.h:66
pid_t vulturePid_
Definition: Vulture.h:68
evf::Vulture::~Vulture ( )
virtual

Definition at line 141 of file Vulture.cc.

References mq_, poster_, and sq_.

142  {
143  delete mq_;
144  if(sq_ != 0) delete sq_;
145  if(poster_ != 0) delete poster_;
146  }
SlaveQueue * sq_
Definition: Vulture.h:75
CurlPoster * poster_
Definition: Vulture.h:73
MasterQueue * mq_
Definition: Vulture.h:74

Member Function Documentation

void evf::Vulture::analyze ( void  )
private

Definition at line 387 of file Vulture.cc.

References edmPickEvents::command, gather_cfg::cout, currentCoreList_, FS, i, newCores_, L1TEmulatorMonitor_cff::p, evf::utils::pid, poster_, evf::CurlPoster::postString(), asciidump::s, and evf::CurlPoster::stack.

Referenced by prowling().

388  {
389  // do a first analysis of the coredump
390  if(newCores_==0) return;
391  for(unsigned int i = currentCoreList_.size()-newCores_;
392  i < currentCoreList_.size();
393  i++){
394  std::string command = "gdb /opt/xdaq/bin/xdaq.exe -batch -x /tmp/vulture.cmd -c /tmp/";
395  std::string cmdout;
396  command += currentCoreList_[i];
397  std::string filePathAndName = FS + "/";
398  filePathAndName += currentCoreList_[i];
399  std::string pid =
400  currentCoreList_[i].substr(currentCoreList_[i].find_first_of(".")+1,
401  currentCoreList_[i].length());
402 
403  FILE *ps = popen(command.c_str(),"r");
404  size_t s = 256;
405  char *p=new char[s];
406  bool filter = false;
407  while(getline(&p,&s,ps) != -1){
408  if(strncmp("Core",p,4)==0) filter = true;
409  if(filter)cmdout += p;
410  }
411  delete[] p;
412  pclose(ps);
413  int errsv = 0;
414  int rch = chmod(filePathAndName.c_str(),0777);
415  if(rch != 0){
416  errsv = errno;
417  std::cout << "ERROR: couldn't change corefile access privileges -"
418  << strerror(errsv)<< std::endl;
419  }
420  unsigned int ipid = (unsigned int)atoi(pid.c_str());
421  poster_->postString(cmdout.c_str(),cmdout.length(),ipid, CurlPoster::stack);
422 
423  }
424  }
int i
Definition: DBlmapReader.cc:9
static const std::string FS
Definition: Vulture.h:59
void postString(const char *, size_t, unsigned int, mode, const std::string &=standard_post_method_)
Definition: CurlPoster.cc:104
std::vector< std::string > currentCoreList_
Definition: Vulture.h:70
CurlPoster * poster_
Definition: Vulture.h:73
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
tuple cout
Definition: gather_cfg.py:41
string s
Definition: asciidump.py:422
unsigned int newCores_
Definition: Vulture.h:72
bool evf::Vulture::control ( toolbox::task::WorkLoop *  wl)
private

Definition at line 289 of file Vulture.cc.

References evf::CurlPoster::check(), gather_cfg::cout, ExpressReco_HICollisions_FallBack::e, runTheMatrix::msg, MSQM_MESSAGE_TYPE_NOP, MSQM_VULTURE_TYPE_STA, MSQM_VULTURE_TYPE_STP, MSQS_VULTURE_TYPE_ACK, evf::SlaveQueue::post(), poster_, prowling_, evf::SlaveQueue::rcv(), evf::vulture_start_message::run_, sq_, startProwling(), and evf::vulture_start_message::url_.

Referenced by makeProcess().

290  {
291 
292  MsgBuf msg;
293  unsigned long mtype = MSQM_MESSAGE_TYPE_NOP;
294  try{mtype = sq_->rcv(msg);}catch(evf::Exception &e){
295  std::cout << "Vulture::exception on msgrcv for control, bailing out of control workloop - good bye" << std::endl;
296  return false;
297  }
298  mtype = msg->mtype;
299  switch(mtype){
301  {
302 
303  vulture_start_message *sta = (vulture_start_message*)msg->mtext;
304  if(poster_ == 0) poster_ = new CurlPoster(sta->url_);
305  if(poster_->check(sta->run_)){
306  try{
307  startProwling();
308  MsgBuf msg1(0,MSQS_VULTURE_TYPE_ACK) ;
309  sq_->post(msg1);
310  }
311  catch(evf::Exception &e)
312  {
313  std::cout << "Vulture::start - exception in starting prowling workloop " << e.what() << std::endl;
314  //@EM ToDo generate some message here
315  }
316  }else{
317  std::cout << "Vulture::start - could not contact iDie - chech Url - will not start prowling loop" << std::endl;
318  prowling_ = false;
319  }
320 
321  break;
322  }
324  {
325  prowling_ = false;
326  break;
327  }
328  default:
329  {
330  // do nothing @EM ToDo generate an appropriate error message
331  }
332  }
333  return true;
334 
335  }
bool check(int)
Definition: CurlPoster.cc:117
#define MSQS_VULTURE_TYPE_ACK
Definition: queue_defs.h:32
SlaveQueue * sq_
Definition: Vulture.h:75
#define MSQM_MESSAGE_TYPE_NOP
Definition: queue_defs.h:15
bool prowling_
Definition: Vulture.h:65
void startProwling()
Definition: Vulture.cc:266
int post(MsgBuf &ptr)
Definition: SlaveQueue.h:35
CurlPoster * poster_
Definition: Vulture.h:73
#define MSQM_VULTURE_TYPE_STP
Definition: queue_defs.h:22
unsigned long rcv(MsgBuf &ptr)
Definition: SlaveQueue.h:45
tuple cout
Definition: gather_cfg.py:41
#define MSQM_VULTURE_TYPE_STA
Definition: queue_defs.h:21
int evf::Vulture::hasStarted ( )

Definition at line 209 of file Vulture.cc.

References ExpressReco_HICollisions_FallBack::e, MAX_MSG_SIZE, mq_, MSQS_VULTURE_TYPE_ACK, evf::MasterQueue::rcvNonBlocking(), and started_.

Referenced by evf::FUEventProcessor::updater().

209  {
210  if(started_<0){
211  MsgBuf msg2(MAX_MSG_SIZE,MSQS_VULTURE_TYPE_ACK);
212  try{
213  mq_->rcvNonBlocking(msg2);
214  started_ = 0;
215  }
216  catch(evf::Exception &e){
217  }
218  } else {started_ = 1;}
219  return started_;
220  }
#define MSQS_VULTURE_TYPE_ACK
Definition: queue_defs.h:32
#define MAX_MSG_SIZE
Definition: queue_defs.h:10
unsigned long rcvNonBlocking(MsgBuf &ptr)
Definition: MasterQueue.h:68
MasterQueue * mq_
Definition: Vulture.h:74
int started_
Definition: Vulture.h:76
int evf::Vulture::hasStopped ( )

Definition at line 222 of file Vulture.cc.

References ExpressReco_HICollisions_FallBack::e, MAX_MSG_SIZE, mq_, MSQS_VULTURE_TYPE_ACK, evf::MasterQueue::rcvNonBlocking(), and stopped_.

222  {
223  if(stopped_<0){
224  MsgBuf msg2(MAX_MSG_SIZE,MSQS_VULTURE_TYPE_ACK);
225  try{
226  mq_->rcvNonBlocking(msg2);
227  stopped_ = 0;
228  }
229  catch(evf::Exception &e){
230  }
231  } else {stopped_ = 1;}
232  return stopped_;
233  }
#define MSQS_VULTURE_TYPE_ACK
Definition: queue_defs.h:32
#define MAX_MSG_SIZE
Definition: queue_defs.h:10
unsigned long rcvNonBlocking(MsgBuf &ptr)
Definition: MasterQueue.h:68
MasterQueue * mq_
Definition: Vulture.h:74
int stopped_
Definition: Vulture.h:77
pid_t evf::Vulture::kill ( )

Definition at line 257 of file Vulture.cc.

References vulturePid_.

258  {
259  ::kill (vulturePid_, SIGKILL);
260  int sl;
261  pid_t killedOrNot = waitpid(vulturePid_,&sl,WNOHANG);
262  vulturePid_ = 0;
263  return killedOrNot;
264  }
pid_t kill()
Definition: Vulture.cc:257
pid_t vulturePid_
Definition: Vulture.h:68
pid_t evf::Vulture::makeProcess ( )

Definition at line 148 of file Vulture.cc.

References asCtrl_, control(), gather_cfg::cout, ExpressReco_HICollisions_FallBack::e, edm::hlt::Exception, FS, handicapped_, sq_, summarizeEdmComparisonLogfiles::success, tmp_, vulture_queue_offset, vulturePid_, and wlCtrl_.

Referenced by evf::FUEventProcessor::configuring().

148  {
149 
150  pid_t retval = fork();
151  if(retval==0){ // we are in the forked process
152  int success = -1;
153 #ifdef linux
154  success = prctl( PR_SET_DUMPABLE, 0 );
155 #endif
156  if(success != 0){
157  std::cout << "Vulture::could not set process undumpable" << std::endl;
158  handicapped_ = true;
159  }
160 #ifdef linux
161  success = prctl( PR_SET_PDEATHSIG, SIGKILL );
162 #endif
163  if(success != 0){
164  std::cout << "Vulture::could not set process death signal" << std::endl;
165  handicapped_ = true;
166  }
167  tmp_ = opendir(FS.c_str());
168 #ifdef linux
169  success = prctl ( PR_SET_NAME , "vulture");
170 #endif
171  if(success != 0){
172  std::cout << "Vulture::could not set process name" << std::endl;
173  handicapped_ = true;
174  }
175 
176  try{
177  pt::PeerTransport * ptr =
178  pt::getPeerTransportAgent()->getPeerTransport("http","soap",pt::Receiver);
179  delete ptr;
180  }
181  catch (pt::exception::PeerTransportNotFound & e ){
182  //do nothing here since we don't know what to do... ?
183  }
184  // freopen("/dev/null","w",stderr);
185  sq_ = new SlaveQueue(vulture_queue_offset);
186  // start the ctrl workloop
187  try {
188  wlCtrl_=
189  toolbox::task::getWorkLoopFactory()->getWorkLoop("Ctrll",
190  "waiting");
191  if (!wlCtrl_->isActive()) wlCtrl_->activate();
192 
193  asCtrl_ = toolbox::task::bind(this,&Vulture::control,
194  "Ctrl");
195  wlCtrl_->submit(asCtrl_);
196  }
197  catch (xcept::Exception& e) {
198  std::cout << "Vulture:constructor - could not start workloop 'Ctrl' for process " << retval << std::endl;
199  }
200  }
201  else{
202  vulturePid_ = retval;
203  }
204  return retval;
205 
206 
207  }
SlaveQueue * sq_
Definition: Vulture.h:75
static const std::string FS
Definition: Vulture.h:59
DIR * tmp_
Definition: Vulture.h:69
toolbox::task::ActionSignature * asCtrl_
Definition: Vulture.h:61
toolbox::task::WorkLoop * wlCtrl_
Definition: Vulture.h:60
bool control(toolbox::task::WorkLoop *)
Definition: Vulture.cc:289
static const int vulture_queue_offset
Definition: Vulture.h:53
tuple cout
Definition: gather_cfg.py:41
bool handicapped_
Definition: Vulture.h:78
pid_t vulturePid_
Definition: Vulture.h:68
bool evf::Vulture::prowling ( toolbox::task::WorkLoop *  wl)
private

Definition at line 337 of file Vulture.cc.

References analyze(), gather_cfg::cout, currentCoreList_, ExpressReco_HICollisions_FallBack::e, lastUpdate_, newCores_, cmsPerfSuiteHarvest::now, poster_, evf::CurlPoster::postString(), prowling_, stor::utils::sleep(), evf::CurlPoster::stack, and tmp_.

Referenced by startProwling().

338  {
339 
340  if(!prowling_){
341  char messageDie[5];
342  sprintf(messageDie,"Dead");
343 
344  try{
345  poster_->postString(messageDie,5,0,CurlPoster::stack);
346  }
347  catch(evf::Exception &e){
348  //do nothing just swallow the exception
349  }
350  delete poster_;
351  poster_=0;
352 
353  return false;
354  }
355 
356  newCores_ = 0;
357 
358  struct stat filestat;
359 
360  timeval now;
361  gettimeofday(&now,0);
362 
363  // examine /tmp looking for new coredumps
364  dirent *dirp;
365  while((dirp = readdir(tmp_))!=0){
366  if(strncmp(dirp->d_name,"core",4)==0){
367  stat(dirp->d_name,&filestat);
368  if(filestat.st_mtime > lastUpdate_){
369  currentCoreList_.push_back(dirp->d_name);
370  newCores_++;
371  }
372  }
373  }
374  rewinddir(tmp_);
375  lastUpdate_ = now.tv_sec;
376  try{
377  analyze();
378  }
379  catch(evf::Exception &e){
380  std::cout << "Vulture cannot send to iDie server, bail out " << std::endl;
381  return false;
382  }
383  ::sleep(60);
384  return true;
385  }
time_t lastUpdate_
Definition: Vulture.h:71
void postString(const char *, size_t, unsigned int, mode, const std::string &=standard_post_method_)
Definition: CurlPoster.cc:104
void sleep(Duration_t)
Definition: Utils.h:163
std::vector< std::string > currentCoreList_
Definition: Vulture.h:70
DIR * tmp_
Definition: Vulture.h:69
bool prowling_
Definition: Vulture.h:65
void analyze()
Definition: Vulture.cc:387
CurlPoster * poster_
Definition: Vulture.h:73
tuple cout
Definition: gather_cfg.py:41
unsigned int newCores_
Definition: Vulture.h:72
void evf::Vulture::retrieve_corefile ( char *  ,
char *  ,
uint64_t   
)
pid_t evf::Vulture::start ( std::string  url,
int  run = 0 
)

Definition at line 235 of file Vulture.cc.

References mq_, MSQM_VULTURE_TYPE_STA, evf::MasterQueue::post(), CrabTask::run, evf::vulture_start_message::run_, stopped_, evf::vulture_start_message::url_, and vulturePid_.

Referenced by Types.LuminosityBlockRange::cppID(), Types.EventRange::cppID(), and evf::FUEventProcessor::enabling().

235  {
236 
237  //communicate start-of-run to Vulture
238  vulture_start_message stamsg;
239  strcpy(stamsg.url_,url.c_str());
240  stamsg.run_ = run;
241  MsgBuf msg1(sizeof(vulture_start_message),MSQM_VULTURE_TYPE_STA);
242  memcpy(msg1->mtext,&stamsg,sizeof(vulture_start_message));
243  mq_->post(msg1);
244  stopped_ = -1;
245  return vulturePid_;
246  }
MasterQueue * mq_
Definition: Vulture.h:74
#define MSQM_VULTURE_TYPE_STA
Definition: queue_defs.h:21
int post(MsgBuf &ptr)
Definition: MasterQueue.h:45
int stopped_
Definition: Vulture.h:77
pid_t vulturePid_
Definition: Vulture.h:68
void evf::Vulture::startProwling ( )
private

Definition at line 266 of file Vulture.cc.

References asProwl_, ExpressReco_HICollisions_FallBack::e, edm::hlt::Exception, lastUpdate_, runTheMatrix::msg, cmsPerfSuiteHarvest::now, prowling(), prowling_, and wlProwl_.

Referenced by control().

267  {
268  timeval now;
269  gettimeofday(&now,0);
270  lastUpdate_ = now.tv_sec;
271  prowling_ = true;
272  try {
273  wlProwl_=
274  toolbox::task::getWorkLoopFactory()->getWorkLoop("Prowl",
275  "waiting");
276  if (!wlProwl_->isActive()) wlProwl_->activate();
277 
278  asProwl_ = toolbox::task::bind(this,&Vulture::prowling,
279  "Prowl");
280  wlProwl_->submit(asProwl_);
281  }
282  catch (xcept::Exception& e) {
283  std::string msg = "Failed to start workloop 'Prowl'.";
284  XCEPT_RETHROW(evf::Exception,msg,e);
285  }
286 
287  }
toolbox::task::WorkLoop * wlProwl_
Definition: Vulture.h:63
time_t lastUpdate_
Definition: Vulture.h:71
bool prowling(toolbox::task::WorkLoop *)
Definition: Vulture.cc:337
toolbox::task::ActionSignature * asProwl_
Definition: Vulture.h:64
bool prowling_
Definition: Vulture.h:65
pid_t evf::Vulture::stop ( )

Definition at line 248 of file Vulture.cc.

References mq_, MSQM_VULTURE_TYPE_STP, NUMERIC_MESSAGE_SIZE, evf::MasterQueue::post(), started_, and vulturePid_.

Referenced by evf::FUEventProcessor::stopping().

249  {
250 
252  mq_->post(msg1);
253  started_ = -1;
254  return vulturePid_;
255  }
#define NUMERIC_MESSAGE_SIZE
Definition: queue_defs.h:35
#define MSQM_VULTURE_TYPE_STP
Definition: queue_defs.h:22
MasterQueue * mq_
Definition: Vulture.h:74
int post(MsgBuf &ptr)
Definition: MasterQueue.h:45
int started_
Definition: Vulture.h:76
pid_t vulturePid_
Definition: Vulture.h:68

Member Data Documentation

toolbox::task::ActionSignature* evf::Vulture::asCtrl_
private

Definition at line 61 of file Vulture.h.

Referenced by makeProcess().

toolbox::task::ActionSignature* evf::Vulture::asProwl_
private

Definition at line 64 of file Vulture.h.

Referenced by startProwling().

std::vector<std::string> evf::Vulture::currentCoreList_
private

Definition at line 70 of file Vulture.h.

Referenced by analyze(), and prowling().

const std::string evf::Vulture::FS ="/tmp"
staticprivate

Definition at line 59 of file Vulture.h.

Referenced by analyze(), and makeProcess().

bool evf::Vulture::handicapped_
private

Definition at line 78 of file Vulture.h.

Referenced by makeProcess().

std::string evf::Vulture::iDieUrl_
private

Definition at line 66 of file Vulture.h.

time_t evf::Vulture::lastUpdate_
private

Definition at line 71 of file Vulture.h.

Referenced by prowling(), and startProwling().

MasterQueue* evf::Vulture::mq_
private

Definition at line 74 of file Vulture.h.

Referenced by hasStarted(), hasStopped(), start(), stop(), and ~Vulture().

unsigned int evf::Vulture::newCores_
private

Definition at line 72 of file Vulture.h.

Referenced by analyze(), and prowling().

CurlPoster* evf::Vulture::poster_
private

Definition at line 73 of file Vulture.h.

Referenced by analyze(), control(), prowling(), and ~Vulture().

bool evf::Vulture::prowling_
private

Definition at line 65 of file Vulture.h.

Referenced by control(), prowling(), and startProwling().

bool evf::Vulture::running_
private

Definition at line 62 of file Vulture.h.

SlaveQueue* evf::Vulture::sq_
private

Definition at line 75 of file Vulture.h.

Referenced by control(), makeProcess(), and ~Vulture().

int evf::Vulture::started_
private

Definition at line 76 of file Vulture.h.

Referenced by hasStarted(), and stop().

int evf::Vulture::stopped_
private

Definition at line 77 of file Vulture.h.

Referenced by hasStopped(), and start().

DIR* evf::Vulture::tmp_
private

Definition at line 69 of file Vulture.h.

Referenced by makeProcess(), and prowling().

bool evf::Vulture::updateMode_
private

Definition at line 67 of file Vulture.h.

const int evf::Vulture::vulture_queue_offset = 400
staticprivate

Definition at line 53 of file Vulture.h.

Referenced by makeProcess().

pid_t evf::Vulture::vulturePid_
private

Definition at line 68 of file Vulture.h.

Referenced by kill(), makeProcess(), start(), and stop().

toolbox::task::WorkLoop* evf::Vulture::wlCtrl_
private

Definition at line 60 of file Vulture.h.

Referenced by makeProcess().

toolbox::task::WorkLoop* evf::Vulture::wlProwl_
private

Definition at line 63 of file Vulture.h.

Referenced by startProwling().