CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
dqm-mbProfile Namespace Reference

Classes

class  Profile
 

Functions

def build_process_list
 
def find_and_write_html
 
def get_children
 
def handle_alarm
 
def read_procfs
 
def run_and_monitor
 

Variables

 ALARM_P_OBJECT = None
 
int ALARM_TIMER = 1
 
tuple args = parser.parse_args()
 
tuple log = logging.getLogger("mbProfile")
 
string LOG_FORMAT = '%(asctime)s: %(name)-20s - %(levelname)-8s - %(message)s'
 
tuple p = os.path.dirname(args.file)
 
tuple parser = argparse.ArgumentParser(description="Profile child processes and produce data for rss and such graphs.")
 

Function Documentation

def dqm-mbProfile.build_process_list ( )

Definition at line 56 of file dqm-mbProfile.py.

References read_procfs().

Referenced by get_children().

56 
57 def build_process_list():
58  lst = os.listdir("/proc/")
59  for f in lst:
60  if not f.isdigit(): continue
61 
62  proc = read_procfs(os.path.join("/proc", f))
63  if proc:
64  yield proc
def build_process_list
def dqm-mbProfile.find_and_write_html (   p,
  args 
)

Definition at line 244 of file dqm-mbProfile.py.

245 def find_and_write_html(p, args):
246  # create the dir if necessary
247  if p and not os.path.exists(p):
248  os.makedirs(p)
249 
250  html_paths = [
251  os.path.join(os.getenv("CMSSW_BASE"),"src/DQMServices/Components/data/html"),
252  os.path.join(os.getenv("CMSSW_RELEASE_BASE"), "src/DQMServices/Components/data/html"),
253  ]
254 
255  def find_file(f):
256  fails = []
257  for p in html_paths:
258  x = os.path.join(p, f)
259  if os.path.exists(x):
260  return x
261  else:
262  fails.append(x)
263 
264  log.warning("Could not find html file: %s (%s)", f, fails)
265 
266  for f in ['mbGraph.js', 'mbGraph.html']:
267  target_fn = os.path.join(p, f)
268  source_fn = find_file(f)
269  if source_fn:
270  log.info("Copying %s to %s", source_fn, target_fn)
271  shutil.copyfile(source_fn, target_fn)
272 
273  # create json file
274  target_fn = os.path.join(p, "mbGraph.json")
275  log.info("Creating %s", target_fn)
276  with open(target_fn, "w") as fp:
277  dct = {
278  "file": os.path.basename(args.file),
279  "interval": args.i,
280  "env": {
281  "CMSSW_GIT_HASH": os.getenv("CMSSW_GIT_HASH"),
282  "CMSSW_RELEASE_BASE": os.getenv("CMSSW_RELEASE_BASE"),
283  "SCRAM_ARCH": os.getenv("SCRAM_ARCH"),
284  },
285  }
286 
287  json.dump(dct, fp, indent=2)
288 
def dqm-mbProfile.get_children (   ppid)
Select all processes which are descendant from ppid (exclusive). 

Definition at line 65 of file dqm-mbProfile.py.

References bitset_utilities.append(), and build_process_list().

Referenced by dqm-mbProfile.Profile.update_proc().

65 
66 def get_children(ppid):
67  """ Select all processes which are descendant from ppid (exclusive). """
68 
69  pid_dct = {}
70  for proc in build_process_list():
71  proc["_children"] = []
72  pid_dct[proc["pid"]] = proc
73 
74  # fill in children array
75  for pid in list(pid_dct.keys()):
76  parent_pid = pid_dct[pid]["parent_pid"]
77 
78  if parent_pid in pid_dct:
79  pid_dct[parent_pid]["_children"].append(pid)
80 
81  # now just walk down the tree
82  if ppid is None or ppid not in pid_dct:
83  # process has quit, we exit
84  return []
85 
86  accepted = []
87  to_accept = collections.deque([ppid, ])
88 
89  while to_accept:
90  head = pid_dct[to_accept.popleft()]
91 
92  # do not include the monitoring pid
93  if head["pid"] != ppid:
94  accepted.append(head)
95 
96  to_accept.extend(head.get("_children", []))
97  head["children"] = head["_children"]
98  del head["_children"]
99 
100  # deleting children breaks infinite loops
101  # but Dima, can a process tree contain a loop? yes - via race-condition in reading procfs
102 
103  return accepted
def build_process_list
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
def dqm-mbProfile.handle_alarm (   num,
  frame 
)

Definition at line 223 of file dqm-mbProfile.py.

224 def handle_alarm(num, frame):
225  if ALARM_P_OBJECT:
226  ALARM_P_OBJECT.update()
227 
228  signal.alarm(ALARM_TIMER)
def dqm-mbProfile.read_procfs (   ppath,
  only_ppid = True 
)

Definition at line 20 of file dqm-mbProfile.py.

References SiPixelLorentzAngle_cfi.read, python.rootplot.root2matplotlib.replace(), and digitizers_cfi.strip.

Referenced by build_process_list().

20 
21 def read_procfs(ppath, only_ppid=True):
22  def read(f):
23  fp = os.path.join(ppath, f)
24  with open(fp) as fd:
25  return fd.read()
26 
27  def read_status():
28  st = {}
29 
30  fp = os.path.join(ppath, "status")
31  with open(fp) as fd:
32  for line in fd.readlines():
33  if not line: continue
34 
35  key, value = line.split(":", 1)
36  st[key] = value.strip()
37 
38  return st
39 
40  try:
41  dct = {}
42 
43  dct["statm"] = read("statm").strip()
44  dct["stat"] = read("stat").strip()
45  dct["cmdline"] = read("cmdline").strip().replace("\0", " ")
46 
47  status = read_status()
48  dct["status"] = status
49  dct["pid"] = int(status["Pid"])
50  dct["parent_pid"] = int(status["PPid"])
51 
52  return dct
53  except:
54  log.warning("Exception in read_procfs.", exc_info=True)
55  pass
def dqm-mbProfile.run_and_monitor (   args)

Definition at line 229 of file dqm-mbProfile.py.

230 def run_and_monitor(args):
231  profile = Profile(args)
232 
233  proc = subprocess.Popen(args.pargs)
234  profile.pid = proc.pid
235 
236  global ALARM_P_OBJECT
237  ALARM_P_OBJECT = profile
238 
239  signal.signal(signal.SIGALRM, handle_alarm)
240  signal.alarm(ALARM_TIMER)
241 
242  proc.wait()
243  profile.finish()

Variable Documentation

dqm-mbProfile.ALARM_P_OBJECT = None

Definition at line 221 of file dqm-mbProfile.py.

dqm-mbProfile.ALARM_TIMER = 1

Definition at line 220 of file dqm-mbProfile.py.

tuple dqm-mbProfile.args = parser.parse_args()

Definition at line 297 of file dqm-mbProfile.py.

tuple dqm-mbProfile.log = logging.getLogger("mbProfile")

Definition at line 17 of file dqm-mbProfile.py.

string dqm-mbProfile.LOG_FORMAT = '%(asctime)s: %(name)-20s - %(levelname)-8s - %(message)s'

Definition at line 15 of file dqm-mbProfile.py.

tuple dqm-mbProfile.p = os.path.dirname(args.file)

Definition at line 312 of file dqm-mbProfile.py.

tuple dqm-mbProfile.parser = argparse.ArgumentParser(description="Profile child processes and produce data for rss and such graphs.")

Definition at line 290 of file dqm-mbProfile.py.