CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes | Private Attributes
dqm-mbProfile.Profile Class Reference
Inheritance diagram for dqm-mbProfile.Profile:

Public Member Functions

def __init__
 
def finish
 
def read_smaps
 
def to_dict
 
def update
 
def update_proc
 
def update_ru
 

Public Attributes

 final
 
 known_pids
 
 pid
 
 ru
 
 ru_diff
 
 time
 

Private Attributes

 _args
 
 _file
 
 _offset_ru
 

Detailed Description

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

Constructor & Destructor Documentation

def dqm-mbProfile.Profile.__init__ (   self,
  args 
)

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

106  def __init__(self, args):
107  self.time = time.time()
108  self.final = False
109  self.pid = None
110  self.known_pids = {}
112  self.ru = {}
113  self.ru_diff = {}
115  self._offset_ru = None
116  self._args = args
117 
118  if self._args.file:
119  self._file = open(self._args.file, "w")
120  else:
121  self._file = None
122 
123  self.update()

Member Function Documentation

def dqm-mbProfile.Profile.finish (   self)

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

References CommonAnalyzer._file, dqm-mbProfile.Profile._file, dqm-mbProfile.Profile.final, dqm-mbProfile.Profile.ru_diff, FastFedCablingTask.update(), ApvTimingTask.update(), FedTimingTask.update(), VpspScanTask.update(), OptoScanTask.update(), PedestalsTask.update(), FineDelayTask.update(), LatencyTask.update(), AlignableDet.update(), DaqScopeModeHistosUsingDb.update(), NoiseHistosUsingDb.update(), OptoScanHistosUsingDb.update(), PedestalsHistosUsingDb.update(), PedsFullNoiseHistosUsingDb.update(), PedsOnlyHistosUsingDb.update(), VpspScanHistosUsingDb.update(), ErrorCorrelation.update(), ApvTimingHistosUsingDb.update(), FedCablingTask.update(), AlignableDetUnit.update(), FastFedCablingHistosUsingDb.update(), edm::SubProcessParentageHelper.update(), AlignableGEMChamber.update(), AlignableGEMSuperChamber.update(), LatencyHistosUsingDb.update(), CalibrationScanTask.update(), CalibrationTask.update(), PedsOnlyTask.update(), CalibrationHistosUsingDb.update(), FineDelayHistosUsingDb.update(), PedsFullNoiseTask.update(), DaqScopeModeTask.update(), AlignableTracker.update(), AlignableCSCChamber.update(), NoiseTask.update(), AlignableComposite.update(), edm::ProductProvenanceLookup.update(), cond::persistency::GLOBAL_TAG::Table.update(), cond::persistency::ITagTable.update(), SiStripConfObject.update(), AlignableMuon.update(), cond::persistency::TAG::Table.update(), Alignable.update(), HcaluLUTTPGCoder.update(), LaserAlignmentSimulation.update(), ApvAnalysisFactory.update(), DTVDriftCalibration::cellInfo.update(), HLTScalersClient::CountLSFifo_t.update(), DTRecSegment2D.update(), DQMNet::Peer.update, DQMNet::AutoPeer.update, CommissioningTask.update(), cond::persistency::IGTTable.update(), dqm-mbProfile.Profile.update(), Folder.update(), crabFunctions.CrabTask.update(), and edmNew::DetSetVector< T >.update().

Referenced by progressbar.ProgressBar.__next__().

210  def finish(self):
211  self.final = True
212  self.update()
213 
214  if self._file:
215  self._file.close()
216  self._file = None
217  else:
218  log.info("ru_diff: %s", self.ru_diff)
219 
def dqm-mbProfile.Profile.read_smaps (   self,
  proc_dict 
)

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

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

144  def read_smaps(self, proc_dict):
145  Private, Shared, Pss = 0, 0, 0
146 
147  fp = os.path.join("/proc/%d" % proc_dict["pid"], "smaps")
148  with open(fp) as fd:
149  for line in fd.readlines():
150  if line.startswith("Shared"):
151  Shared += int(line.split()[1])
152  elif line.startswith("Private"):
153  Private += int(line.split()[1])
154  elif line.startswith("Pss"):
155  Pss += int(line.split()[1])
156 
157  proc_dict["smaps_shared"] = Shared * 1024
158  proc_dict["smaps_private"] = Private * 1024
159  proc_dict["smaps_pss"] = Pss * 1024
def dqm-mbProfile.Profile.to_dict (   self)

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

References dqm-mbProfile.Profile.final, dqm-mbProfile.Profile.known_pids, dqm-mbProfile.Profile.pid, dqm-mbProfile.Profile.ru, dqm-mbProfile.Profile.ru_diff, reco::HcalMuonRecHit.time, RPCStripNoises::NoiseItem.time, RPCObImon::I_Item.time, RPCObGas::Item.time, ecal::RecHit< StoragePolicy >.time, RPCObFebmap::Feb_Item.time, RecoObj.time, RPCObVmon::V_Item.time, classes.PedeDumpData.time, RPCObStatus::S_Item.time, DTTMax::InfoLayer.time, RPCObTemp::T_Item.time, dqm-mbProfile.Profile.time, and l1t::EMTFHit.time.

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

199  def to_dict(self):
200  dct = collections.OrderedDict()
201  dct['time'] = self.time
202  dct['pid'] = self.pid
203  dct['final'] = self.final
204 
205  dct['ru_diff'] = dict(self.ru_diff)
206  dct['ru'] = dict((k, v) for k, v in inspect.getmembers(self.ru) if k.startswith('ru_'))
207  dct['known_pids'] = dict(self.known_pids)
208  return dct
def dqm-mbProfile.Profile.update (   self)

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

References CommonAnalyzer._file, dqm-mbProfile.Profile._file, reco::HcalMuonRecHit.time, RPCStripNoises::NoiseItem.time, RPCObImon::I_Item.time, RPCObGas::Item.time, ecal::RecHit< StoragePolicy >.time, RPCObFebmap::Feb_Item.time, RecoObj.time, RPCObVmon::V_Item.time, classes.PedeDumpData.time, RPCObStatus::S_Item.time, DTTMax::InfoLayer.time, RPCObTemp::T_Item.time, dqm-mbProfile.Profile.time, l1t::EMTFHit.time, dqm-mbProfile.Profile.to_dict(), dqm-mbProfile.Profile.update_proc(), and dqm-mbProfile.Profile.update_ru().

Referenced by progressbar.ProgressBar.__next__(), MatrixUtil.Matrix.__setitem__(), MatrixUtil.Steps.__setitem__(), dqm-mbProfile.Profile.finish(), progressbar.ProgressBar.finish(), and MatrixUtil.Steps.overwrite().

186  def update(self):
187  self.time = time.time()
188 
189  self.update_ru()
190  self.update_proc()
191 
192  if self._file:
193  json.dump(self.to_dict(), self._file)
194  self._file.write("\n")
195  self._file.flush()
196 
197  log.info("Written profile to: %s, took=%.03f", self._args.file, time.time() - self.time)
def dqm-mbProfile.Profile.update_proc (   self)

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

References dqm-mbProfile.get_children(), dqm-mbProfile.Profile.known_pids, and dqm-mbProfile.Profile.read_smaps().

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

161  def update_proc(self):
162  procs = get_children(os.getpid())
163 
164  # we can only do it here, permision-wise
165  # ie only for owned processes
166  for proc in procs:
167  try:
168  self.read_smaps(proc)
169  except:
170  log.warning("Exception in read_smaps.", exc_info=True)
171 
172  # we need to mark not-running ones as such
173  stopped = set(self.known_pids.keys())
174  for proc in procs:
175  proc["running"] = True
176 
177  pid = proc["pid"]
178  self.known_pids[pid] = proc
179 
180  if pid in stopped:
181  stopped.remove(pid)
182 
183  for pid in stopped:
184  self.known_pids[pid]["running"] = False
def dqm-mbProfile.Profile.update_ru (   self)

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

References dqm-mbProfile.Profile._offset_ru, dqm-mbProfile.Profile.ru, and dqm-mbProfile.Profile.ru_diff.

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

125  def update_ru(self):
126  fields_to_subtract = (
127  "ru_utime", "ru_stime", "ru_maxrss", "ru_minflt", "ru_majflt", "ru_nswap",
128  "ru_inblock", "ru_oublock", "ru_msgsnd", "ru_msgrcv", "ru_nsignals", "ru_nvcsw", "ru_nivcsw",
129  )
130 
131  rusage = resource.getrusage(resource.RUSAGE_CHILDREN)
132  self.ru = rusage
133 
134  if self._offset_ru is None:
135  self._offset_ru = rusage
136 
137  for field in fields_to_subtract:
138  current = getattr(self.ru, field)
139  base = getattr(self._offset_ru, field)
140 
141  self.ru_diff[field] = current - base

Member Data Documentation

dqm-mbProfile.Profile._args
private

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

dqm-mbProfile.Profile._file
private

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

Referenced by ntupleDataFormat.TrackingNtuple.file(), dqm-mbProfile.Profile.finish(), and dqm-mbProfile.Profile.update().

dqm-mbProfile.Profile._offset_ru
private

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

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

dqm-mbProfile.Profile.final

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

Referenced by dqm-mbProfile.Profile.finish(), and dqm-mbProfile.Profile.to_dict().

dqm-mbProfile.Profile.known_pids

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

Referenced by dqm-mbProfile.Profile.to_dict(), and dqm-mbProfile.Profile.update_proc().

dqm-mbProfile.Profile.pid

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

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

dqm-mbProfile.Profile.ru

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

Referenced by dqm-mbProfile.Profile.to_dict(), and dqm-mbProfile.Profile.update_ru().

dqm-mbProfile.Profile.ru_diff

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

Referenced by dqm-mbProfile.Profile.finish(), dqm-mbProfile.Profile.to_dict(), and dqm-mbProfile.Profile.update_ru().

dqm-mbProfile.Profile.time

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

Referenced by dqm-mbProfile.Profile.to_dict(), and dqm-mbProfile.Profile.update().