ATLAS Offline Software
Classes | Typedefs | Functions
PMonSD Namespace Reference

Classes

class  CmpEntries
 
class  CompDataBasic
 
class  CompDataExtended
 
struct  CompDataStdSteps
 
struct  Count
 
struct  Entry
 
class  FastStrCmp
 
struct  Meas
 
class  SemiDetHelper
 
class  StepWrapper
 
class  StepWrapperOther
 
class  StepWrapperStd
 

Typedefs

typedef std::pair< std::string, std::string > OtherKey
 
typedef std::map< std::string, CompDataStdSteps, FastStrCmpMapStdSteps
 
typedef std::map< OtherKey, CompDataBasic, FastStrCmpMapOtherSteps
 

Functions

void get_vmem_rss_kb (double &vmem, double &rss, bool vmemonly=false)
 
double get_malloc_kb ATLAS_NOT_THREAD_SAFE ()
 
double get_vmem_kb ()
 
double get_rss_kb ()
 
double get_cpu_ms ()
 
double get_wall_ms ()
 
void setUTCTimeString (std::string &s, double offset_ms=0)
 
unsigned vmpeak ()
 
std::string get_field (const char *filename, const std::string &fieldname, char space='_')
 
int64_t clock_nooverflow ()
 
std::string cpu_model ()
 
int bogomips ()
 
const char * envvar (const char *e, const char *def="")
 
bool envvar_is_set (const char *e)
 
unsigned long system_boot_time_seconds ()
 
double get_absolute_wall_ms ()
 
double secs_per_jiffy ()
 
double jobstart_jiffy2unix_ms (const std::string &s)
 
const char * symb2lib (const char *symbol, const char *failstr="unknown")
 

Typedef Documentation

◆ MapOtherSteps

Definition at line 210 of file SemiDetMisc.h.

◆ MapStdSteps

typedef std::map<std::string,CompDataStdSteps,FastStrCmp> PMonSD::MapStdSteps

Definition at line 208 of file SemiDetMisc.h.

◆ OtherKey

typedef std::pair<std::string,std::string> PMonSD::OtherKey

Definition at line 191 of file SemiDetMisc.h.

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

double get_malloc_kb PMonSD::ATLAS_NOT_THREAD_SAFE ( )

◆ bogomips()

int PMonSD::bogomips ( )
inline

Definition at line 367 of file SemiDetMisc.h.

368  {
369  std::string bm=get_field("/proc/cpuinfo","bogomips",' ');
370  if (bm=="unknown")
371  return 0;
372  return int(atof(bm.c_str())+0.5);
373  }

◆ clock_nooverflow()

int64_t PMonSD::clock_nooverflow ( )
inline

Definition at line 523 of file SemiDetMisc.h.

523  {
524  //In gnu, clock_t is a long and CLOCKS_PER_SECOND 1000000 so clock()
525  //will overflow in 32bit builds after a few thousands of seconds. To
526  //avoid this, we have the following method instead which notices when
527  //overflow occurs and corrects for it (it won't notice if it doesn't
528  //get called for >4000ms, but this should be ok for almost all of our
529  //use cases):
530  assert(std::numeric_limits<clock_t>::is_integer);
531  if (sizeof(clock_t)>=sizeof(int64_t))
532  return clock();//64bit builds shouldn't have overflow issues.
533 
534  //not so clean with statics i guess:
535  static clock_t last=clock();
536  static int64_t offset=0;
537  clock_t c=clock();
538  if (c<last)
540  last=c;
541  return offset+c;
542 }

◆ cpu_model()

std::string PMonSD::cpu_model ( )
inline

Definition at line 361 of file SemiDetMisc.h.

362  {
363  std::stringstream s;
364  s<<get_field("/proc/cpuinfo","model name",'_')<<"/"<<get_field("/proc/cpuinfo","cache size",'_');
365  return s.str();
366  }

◆ envvar()

const char* PMonSD::envvar ( const char *  e,
const char *  def = "" 
)
inline

Definition at line 374 of file SemiDetMisc.h.

375  {
376  const char * c = getenv(e);
377  return c ? c : def;
378  }

◆ envvar_is_set()

bool PMonSD::envvar_is_set ( const char *  e)
inline

Definition at line 379 of file SemiDetMisc.h.

379  {
380  const char * c = getenv(e);
381  if (!c) return false;
382  return strncmp(c,"1",2)==0;
383  }

◆ get_absolute_wall_ms()

double PMonSD::get_absolute_wall_ms ( )
inline

Definition at line 402 of file SemiDetMisc.h.

403  {
404  timeval tv;
405  int err=gettimeofday(&tv, 0);
406  if (err!=0)
407  return 0.0;
408  uint64_t res_usec=uint64_t(tv.tv_sec)*1000000 + uint64_t(tv.tv_usec);
409  return 0.001*res_usec;
410  }

◆ get_cpu_ms()

double PMonSD::get_cpu_ms ( )
inline

Definition at line 544 of file SemiDetMisc.h.

544 { return clock_nooverflow()*(1000.0/CLOCKS_PER_SEC); }

◆ get_field()

std::string PMonSD::get_field ( const char *  filename,
const std::string &  fieldname,
char  space = '_' 
)
inline

Definition at line 318 of file SemiDetMisc.h.

319  {
320  //nb: not hyper-optimised
321  FILE* file = fopen(filename, "r");
322  if (!file)
323  return "unknown";
324  std::string result;
325  result.reserve(128);
326  result="unknown";
327  char line[256];
328  while (fgets(line, 256, file) != NULL){
329  if (strncmp(line, fieldname.c_str(), fieldname.size()) == 0) {
330  size_t pos = std::string(line).find( ':', fieldname.size() );
331  if (pos==std::string::npos) {
332  fclose(file);
333  return result;
334  }
335  result.clear();
336  bool ignore_nextspace=true;
337  ++pos;
338  for (;pos<256;++pos) {
339  if (line[pos]=='\n')
340  break;
341  if (line[pos]==' '||line[pos]=='\t') {
342  if (ignore_nextspace)
343  continue;
344  ignore_nextspace=true;
345  result+=space;
346  } else {
347  result+=line[pos];
348  ignore_nextspace=false;
349  }
350  }
351  break;
352  }
353  }
354  fclose(file);
355  //make sure there are no trailing "spaces":
356  while (!result.empty()&&result.at(result.size()-1)==space)
357  result.resize(result.size()-1);
358  return result;
359  }

◆ get_rss_kb()

double PMonSD::get_rss_kb ( )
inline

Definition at line 473 of file SemiDetMisc.h.

473 { double v,r;get_vmem_rss_kb(v,r); return r; }

◆ get_vmem_kb()

double PMonSD::get_vmem_kb ( )
inline

Definition at line 472 of file SemiDetMisc.h.

472 { double v,r;get_vmem_rss_kb(v,r,true); return v; }

◆ get_vmem_rss_kb()

void PMonSD::get_vmem_rss_kb ( double &  vmem,
double &  rss,
bool  vmemonly = false 
)
inline

Definition at line 447 of file SemiDetMisc.h.

447  {
448  vmem=rss=0.0;
449 #ifndef __linux
450  vmemonly=false;//avoid compile warning
451  return;
452 #else
453  //It would be a lot faster without this open call...
454  int fd = open("/proc/self/statm", O_RDONLY);
455  if (fd<0) return;
456  char data[32];
457  int l = read(fd, data, sizeof(data));
458  close(fd);
459  if (l<4) return;//Failure or suspiciously short
460  static const float pg_size_in_kb = sysconf(_SC_PAGESIZE)/1024.0;
461  //Assume that the first field is vmem and the second is rss.
462  vmem=atoi(data)*pg_size_in_kb;
463  if (vmemonly)
464  return;
465  for (unsigned i=0;i+1<sizeof(data);++i)
466  if (data[i]==' ') {
467  rss=atoi(&(data[i+1]))*pg_size_in_kb;
468  return;
469  }
470 #endif
471 }

◆ get_wall_ms()

double PMonSD::get_wall_ms ( )
inline

Definition at line 628 of file SemiDetMisc.h.

629 {
630  //don't care about timezone since we will just be doing differences
631  //(ignore daylight savings issues...). Like clock() it returns 0.0
632  //on first call in a process.
633  double t=get_absolute_wall_ms();
634  static const double offset = [&]() {
635  return t;
636  }();
637  return t-offset;
638 }

◆ jobstart_jiffy2unix_ms()

double PMonSD::jobstart_jiffy2unix_ms ( const std::string &  s)
inline

Definition at line 426 of file SemiDetMisc.h.

426  {
427  const double d=strtod(&(s[0]),0); if (d<=0.) return 0;
428  const unsigned long b=system_boot_time_seconds(); if (!b) return 0;
429  const double spj = secs_per_jiffy(); if (!spj) return 0;
430  return 1000.0*(d*spj+b);
431  }

◆ secs_per_jiffy()

double PMonSD::secs_per_jiffy ( )
inline

Definition at line 412 of file SemiDetMisc.h.

413  {
414 #ifdef __linux
415  //tick will almost certainly be one of 100, 250, 300 or 1000
416  //depending on the kernel configuration (USER_HZ).
417  long tick=sysconf(_SC_CLK_TCK);
418  if (tick>=1&&tick<1000000)
419  return 1.0/tick;
420 #endif
421  //Fall-back to getting it the hard way:
422  clock_t t0=clock(); clock_t t1=t0; while (t1==t0) t1=clock();
423  return double(t1-t0)/CLOCKS_PER_SEC;
424  }

◆ setUTCTimeString()

void PMonSD::setUTCTimeString ( std::string &  s,
double  offset_ms = 0 
)
inline

Definition at line 611 of file SemiDetMisc.h.

612 {
613  //Encoded in ISO 8601 UTC time format. It can be decoded in python
614  //(in a "naive" timezone unaware datetime object) with:
615  //datetime.strptime(input,'%Y-%m-%dT%H:%M:%S+0000')
616  time_t t = time(NULL);//unixtime in seconds
617  if (offset_ms)
618  t+=static_cast<time_t>(0.5+0.001*offset_ms);
619  struct tm ptm;
620  gmtime_r(&t, &ptm);
621  s.clear();
622  s.resize(26);
623  size_t r = strftime(&(s[0]),25,"%Y-%m-%dT%H:%M:%S+0000",&ptm);
624  if (r>0&&r<25) s.resize(r);
625  else s="0000-00-00T00:00:00+0000";
626 }

◆ symb2lib()

const char* PMonSD::symb2lib ( const char *  symbol,
const char *  failstr = "unknown" 
)
inline

Definition at line 433 of file SemiDetMisc.h.

433  {
434  void * addr = dlsym(RTLD_DEFAULT,symbol);
435  if (!addr) return failstr;
436  Dl_info di;
437  if (!dladdr(addr, &di)) return failstr;
438  if (!di.dli_fname) return failstr;
439  return di.dli_fname;
440  }

◆ system_boot_time_seconds()

unsigned long PMonSD::system_boot_time_seconds ( )
inline

Definition at line 384 of file SemiDetMisc.h.

385  {
386  FILE* file = fopen("/proc/stat", "r");
387  if (!file)
388  return 0;
389  char line[32];
390  while (fgets(line, 32, file) != NULL){
391  if (strncmp(line, "btime ", 6) == 0) {
392  unsigned long l;
393  sscanf(&(line[6]),"%80lu",&l);
394  fclose(file);
395  return l;
396  }
397  }
398  fclose(file);
399  return 0;
400  }

◆ vmpeak()

unsigned PMonSD::vmpeak ( )
inline

Definition at line 302 of file SemiDetMisc.h.

303  {
304  FILE* file = fopen("/proc/self/status", "r");
305  if (!file)
306  return 0;
307  unsigned result = 0;
308  char line[256];
309  while (fgets(line, 256, file) != NULL){
310  if (strncmp(line, "VmPeak:", 7) == 0) {
311  result=atoi(&(line[7]));
312  break;
313  }
314  }
315  fclose(file);
316  return result;
317  }
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
beamspotman.r
def r
Definition: beamspotman.py:676
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
get_generator_info.result
result
Definition: get_generator_info.py:21
max
#define max(a, b)
Definition: cfImp.cxx:41
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
PMonSD::get_absolute_wall_ms
double get_absolute_wall_ms()
Definition: SemiDetMisc.h:402
hist_file_dump.d
d
Definition: hist_file_dump.py:137
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
PMonSD::system_boot_time_seconds
unsigned long system_boot_time_seconds()
Definition: SemiDetMisc.h:384
PMonSD::secs_per_jiffy
double secs_per_jiffy()
Definition: SemiDetMisc.h:412
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
PMonSD::get_field
std::string get_field(const char *filename, const std::string &fieldname, char space='_')
Definition: SemiDetMisc.h:318
lumiFormat.i
int i
Definition: lumiFormat.py:92
file
TFile * file
Definition: tile_monitor.h:29
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
min
#define min(a, b)
Definition: cfImp.cxx:40
ReadFromCoolCompare.fd
fd
Definition: ReadFromCoolCompare.py:196
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::open
@ open
Definition: BinningType.h:40
python.PyAthena.v
v
Definition: PyAthena.py:157
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
PMonSD::get_vmem_rss_kb
void get_vmem_rss_kb(double &vmem, double &rss, bool vmemonly=false)
Definition: SemiDetMisc.h:447
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
python.compressB64.c
def c
Definition: compressB64.py:93
PMonSD::clock_nooverflow
int64_t clock_nooverflow()
Definition: SemiDetMisc.h:523