CMS 3D CMS Logo

Classes | Functions
dqm-mbProfile Namespace Reference

Classes

class  Profile
 

Functions

def build_process_list ()
 
def find_and_write_html (p, args)
 
def get_children (ppid)
 
def handle_alarm (num, frame)
 
def read_procfs (ppath, only_ppid=True)
 
def run_and_monitor (args)
 

Function Documentation

def dqm-mbProfile.build_process_list ( )

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

References read_procfs().

Referenced by get_children().

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

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

References run_and_monitor().

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

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

65 def get_children(ppid):
66  """ Select all processes which are descendant from ppid (exclusive). """
67 
68  pid_dct = {}
69  for proc in build_process_list():
70  proc["_children"] = []
71  pid_dct[proc["pid"]] = proc
72 
73  # fill in children array
74  for pid in list(pid_dct.keys()):
75  parent_pid = pid_dct[pid]["parent_pid"]
76 
77  if parent_pid in pid_dct:
78  pid_dct[parent_pid]["_children"].append(pid)
79 
80  # now just walk down the tree
81  if ppid is None or ppid not in pid_dct:
82  # process has quit, we exit
83  return []
84 
85  accepted = []
86  to_accept = collections.deque([ppid, ])
87 
88  while to_accept:
89  head = pid_dct[to_accept.popleft()]
90 
91  # do not include the monitoring pid
92  if head["pid"] != ppid:
93  accepted.append(head)
94 
95  to_accept.extend(head.get("_children", []))
96  head["children"] = head["_children"]
97  del head["_children"]
98 
99  # deleting children breaks infinite loops
100  # but Dima, can a process tree contain a loop? yes - via race-condition in reading procfs
101 
102  return accepted
103 
def get_children(ppid)
def build_process_list()
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def dqm-mbProfile.handle_alarm (   num,
  frame 
)

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

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

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

References createfilelist.int, python.rootplot.root2matplotlib.replace(), and digi_MixPreMix_cfi.strip.

Referenced by build_process_list().

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

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

Referenced by find_and_write_html().

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