ATLAS Offline Software
DQProcMonitor.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 from __future__ import print_function
3 
4 #python 2.6 is buggy, it can't import modules in deamon threads one has to import them in to global
5 from resource import getrusage, RUSAGE_SELF, RUSAGE_CHILDREN
6 from time import sleep, time
7 
8 PROCMONVERSION="$Id: DQProcMonitor.py 359096 2011-04-15 13:25:36Z kama $"
9 
10 def formatRusage(rusage):
11  fieldnames=["utime","stime","maxrss","shrmem","ushrmem","ushrstk","minflt",
12  "majflt","nswap","inblock","oublock","msgsnd","msgrcv",
13  "nsignals","nvcontsw","nivcontsw"]
14  return ", ".join(["=".join([n,"%s"%v] if isinstance(v, int) else [n,"%f"%v]) for n,v in zip(fieldnames,rusage)])
15 
16 def DQProcMon(*args,**kwargs):
17  # from resource import getrusage, RUSAGE_SELF, RUSAGE_CHILDREN
18  # from pprint import pformat,pprint
19  # from time import sleep, time
20  pollPeriod = kwargs.pop("poll_period", 1.0)
21  if pollPeriod < 0.25:
22  pollPeriod=0.25 #min poll time
23  filename = kwargs.pop("file_name","DQResourceUtilization.txt")
24  print("Monitoring thread poll period=",pollPeriod,"seconds, output file name=\"%s\""%filename)
25  with open(filename,'w') as resoutfile:
26  while True:
27  try:
28  ru=getrusage(RUSAGE_SELF)
29  cru=getrusage(RUSAGE_CHILDREN)
30  except Exception:
31  pass
32  #self_info="[utime=%f, stime=%f, maxrss=%s, minflt=%s, majflt=%s, nvcsw=%s, nivcsw=%s]" % (ru.ru_utime,
33  #ru.ru_stime, ru.ru_maxrss, ru.ru_minflt, ru.ru_majflt, ru.ru_)
34  resoutfile.write(str(time())+" <self> "+formatRusage(ru)+" <children> "+formatRusage(cru)+"\n")
35  #pprint(rusage,resoutfile)
36  resoutfile.flush()
37  sleep(pollPeriod)
38 
39 def startProcMonThread(pollPeriod=1,file_name="DQResourceUtilization.txt"):
40  from threading import Thread
41  ResMon=Thread(target=DQProcMon,args=[],kwargs={'poll_period':pollPeriod,
42  'file_name':file_name})
43  #ResMon.setDaemon(True)
44  ResMon.start()
45  print("========Starting DQProcMonThread==============")
46 
python.DQProcMonitor.formatRusage
def formatRusage(rusage)
Definition: DQProcMonitor.py:10
python.DQProcMonitor.startProcMonThread
def startProcMonThread(pollPeriod=1, file_name="DQResourceUtilization.txt")
Definition: DQProcMonitor.py:39
python.DQProcMonitor.DQProcMon
def DQProcMon(*args, **kwargs)
Definition: DQProcMonitor.py:16
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
str
Definition: BTagTrackIpAccessor.cxx:11