CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
dqmservices::DQMMonitoringService Class Reference

#include <DQMMonitoringService.h>

Public Member Functions

 DQMMonitoringService (const edm::ParameterSet &, edm::ActivityRegistry &)
 
void registerExtra (std::string name, ptree data)
 
void reportEvents (int nevts)
 
void reportLumiSection (int run, int lumi)
 
 ~DQMMonitoringService ()
 

Private Member Functions

void fillProcessInfoCmdline ()
 
void fillProcessInfoStatus ()
 
std::string hackoutTheStdErr ()
 
void reportLumiSectionUnsafe (int run, int lumi)
 

Private Attributes

ptree extra_
 
int fseq_
 
std::string hostname_
 
boost::filesystem::path json_path_
 
long last_report_nevents_
 
std::chrono::high_resolution_clock::time_point last_report_time_
 
long nevents_
 
ptree ps_info_
 
std::string tag_
 

Detailed Description

Definition at line 37 of file DQMMonitoringService.h.

Constructor & Destructor Documentation

dqmservices::DQMMonitoringService::DQMMonitoringService ( const edm::ParameterSet pset,
edm::ActivityRegistry  
)

Definition at line 18 of file DQMMonitoringService.cc.

References edm::hlt::Exception, fillProcessInfoCmdline(), fseq_, edm::ParameterSet::getUntrackedParameter(), query::host, hostname_, json_path_, last_report_nevents_, last_report_time_, nevents_, fileCollector::now, AlCaHLTBitMon_QueryRunRegistry::string, and tag_.

18  {
19  json_path_ = pset.getUntrackedParameter<std::string>("jsonPath");
20 
21  char host[128];
22  if (gethostname(host ,sizeof(host)) == -1) {
23  throw cms::Exception("DQMMonitoringService")
24  << "Internal error, cannot get host name";
25  }
26 
27  hostname_ = host;
28  fseq_ = 0;
29  tag_ = "";
30  nevents_ = 0;
33 
34  try {
36  } catch (...) {
37  // pass
38  }
39 }
T getUntrackedParameter(std::string const &, T const &) const
string host
Definition: query.py:114
std::chrono::high_resolution_clock::time_point last_report_time_
dqmservices::DQMMonitoringService::~DQMMonitoringService ( )

Definition at line 41 of file DQMMonitoringService.cc.

41  {
42 }

Member Function Documentation

void dqmservices::DQMMonitoringService::fillProcessInfoCmdline ( )
private

Definition at line 130 of file DQMMonitoringService.cc.

References end, AlCaHLTBitMon_ParallelJobs::p, ps_info_, SiPixelLorentzAngle_cfi::read, AlCaHLTBitMon_QueryRunRegistry::string, and tag_.

Referenced by DQMMonitoringService().

130  {
131  int fd = open("/proc/self/cmdline", O_RDONLY);
132  ptree cmdline;
133 
134  if (fd != -1) {
135  unsigned char buf[1024];
136  int nbytesread = read(fd, buf, 1024);
137 
138  // make last character zero
139  // in case we have read less than buf
140  if (nbytesread > 0)
141  buf[nbytesread-1] = 0;
142 
143  unsigned char *end = buf + nbytesread;
144  for (unsigned char *p = buf; p < end; ) {
145  std::string token((char *)p);
146  ptree child;
147  child.put("", token);
148  cmdline.push_back(std::make_pair("", child));
149 
150  if ((tag_.size() == 0) &&
151  (token.find(".py") != std::string::npos)) {
152 
153  // a hack to set the tag until we figure
154  // out how to set it properly
155  tag_ = token;
156  boost::replace_last(tag_, ".py", "");
157  boost::replace_last(tag_, "_cfg", "");
158 
159  size_t pos = tag_.rfind("/");
160  if (pos != std::string::npos) {
161  tag_ = tag_.substr(pos + 1);
162  }
163  }
164 
165  while (*p++); // skip until start of next 0-terminated section
166  }
167  close(fd);
168  }
169 
170  ps_info_.put_child("cmdline", cmdline);
171 }
#define end
Definition: vmac.h:37
void dqmservices::DQMMonitoringService::fillProcessInfoStatus ( )
private

Definition at line 173 of file DQMMonitoringService.cc.

References data, recoMuon::in, geometryCSVtoXML::line, ps_info_, AlCaHLTBitMon_QueryRunRegistry::string, and relativeConstraints::value.

Referenced by reportLumiSectionUnsafe().

173  {
174  ptree data;
175 
176  std::ifstream in("/proc/self/status");
178 
179  if (in) {
180  while (std::getline(in, line)) {
181  size_t pos = line.find(':');
182  if (pos == std::string::npos)
183  continue;
184 
185  std::string value = line.substr(pos+1);
186  boost::trim(value); // value
187  line.resize(pos); // key
188 
189  data.put(line, value);
190  }
191 
192  in.close();
193  }
194 
195  ps_info_.put_child("status", data);
196 }
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::string dqmservices::DQMMonitoringService::hackoutTheStdErr ( )
private

Definition at line 198 of file DQMMonitoringService.cc.

References MAX_LOG_SIZE, NULL, SiPixelLorentzAngle_cfi::read, run_regression::ret, findQualityFiles::size, dqm_diff::start, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by reportLumiSectionUnsafe().

198  {
199  // magic
200  char buf[MAX_LOG_SIZE + 1];
201  ssize_t ret = readlink("/proc/self/fd/2", buf, MAX_LOG_SIZE);
202  if (ret > 0) {
203  buf[ret] = 0;
204  } else {
205  return "error: can't read the stderr link.";
206  }
207 
208  if (strstr(buf, "/dev/") != NULL) {
209  // can't read this weird file
210  return "error: stderr is a special file.";
211  }
212 
213  // try to open
214  FILE *sr = fopen(buf , "rb");
215  if (sr == NULL)
216  return "error: can't open the stderr (deleted?).";
217 
218  // try to get the last position
219  // if this is an ordinary it will succeed
220  fseek(sr, 0, SEEK_END);
221  long size = ftell(sr);
222  if (size > 0) {
223  long from = size - (MAX_LOG_SIZE);
224  if (from < 0)
225  from = 0;
226 
227  fseek(sr, from, SEEK_SET);
228  size_t read = fread(buf, 1, MAX_LOG_SIZE, sr);
229  buf[read] = 0;
230 
231  // If "from" was not zero, discard the first line.
232  // Since it will be corrupted anyway.
233  char *start = buf;
234 
235  if (from != 0) {
236  start = strchr(start, '\n');
237  if (start == NULL) {
238  // should not happen
239  // return an empty string
240  start = buf + read;
241  } else {
242  start = start + 1;
243  }
244  }
245 
246  return std::string(start);
247  }
248 
249  fclose(sr);
250  return "error: stderr is not a seek-able file.";
251 }
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
#define NULL
Definition: scimark2.h:8
#define MAX_LOG_SIZE
tuple size
Write out results.
void dqmservices::DQMMonitoringService::registerExtra ( std::string  name,
ptree  data 
)

Definition at line 44 of file DQMMonitoringService.cc.

References extra_.

44  {
45  extra_.put_child(name, data);
46 }
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void dqmservices::DQMMonitoringService::reportEvents ( int  nevts)

Definition at line 56 of file DQMMonitoringService.cc.

References nevents_, and jetmet_cfg::nevts.

void dqmservices::DQMMonitoringService::reportLumiSection ( int  run,
int  lumi 
)

Definition at line 48 of file DQMMonitoringService.cc.

References reportLumiSectionUnsafe().

48  {
49  try {
51  } catch (...) {
52  // pass
53  }
54 }
tuple lumi
Definition: fjr2json.py:35
void reportLumiSectionUnsafe(int run, int lumi)
void dqmservices::DQMMonitoringService::reportLumiSectionUnsafe ( int  run,
int  lumi 
)
private

Definition at line 60 of file DQMMonitoringService.cc.

References prof2calltree::count, extra_, mergeVDriftHistosByStation::file, fillProcessInfoStatus(), cmsPerfStripChart::format, fseq_, hackoutTheStdErr(), hostname_, json_path_, last_report_nevents_, last_report_time_, fff_deleter::log, nevents_, fileCollector::now, NULL, sysUtil::pid, ps_info_, RecoTauCleanerPlugins::pt, RPCpg::rate(), seconds(), AlCaHLTBitMon_QueryRunRegistry::string, tag_, and cond::rpcobgas::time.

Referenced by reportLumiSection().

60  {
61  using std::chrono::duration_cast;
62  using std::chrono::milliseconds;
64 
65  int pid = getpid();
66  ++fseq_;
67 
68  if (! fs::is_directory(json_path_)) {
69  extra_.clear();
70  return; // no directory present, quit
71  }
72 
74 
75  // document unique id
76  std::string id =
77  str(boost::format("dqm-source-state-run%06d-host%s-pid%06d") % run % hostname_ % pid);
78 
79  // output jsn file
80  std::string path_id;
81 
82  // check for debug fn
83  if (fs::exists(json_path_ / ".debug")) {
84  path_id = str(boost::format("%d.%08d+%s.jsn") % std::time(NULL) % fseq_ % id);
85  } else {
86  path_id = id + ".jsn";
87  }
88 
89  std::string tmp_path = (json_path_ / (path_id + ".tmp")).string();
90  std::string final_path = (json_path_ / path_id).string();
91 
93  rate = rate / duration_cast<seconds>(now - last_report_time_).count();
94 
95  ptree pt;
96  pt.put("_id", id);
97  pt.put("pid", pid);
98  pt.put("tag", tag_);
99  pt.put("hostname", hostname_);
100  pt.put("sequence", fseq_);
101  pt.put("type", "dqm-source-state");
102  pt.put("run", run);
103  pt.put("lumi", lumi);
104 
105  pt.put("events_total", nevents_);
106  pt.put("events_rate", rate);
107 
108  pt.put("report_timestamp", std::time(NULL));
109 
110  // add some additional per-lumi information
112  pt.put("stderr", log);
113 
115 
116  // these are predefined
117  pt.add_child("extra", extra_);
118  pt.add_child("ps_info", ps_info_);
119 
120  std::ofstream file(tmp_path);
121  write_json(file, pt, true);
122  file.close();
123 
126 
127  rename(tmp_path.c_str(), final_path.c_str());
128 }
double seconds()
tuple lumi
Definition: fjr2json.py:35
#define NULL
Definition: scimark2.h:8
string format
Some error handling for the usage.
std::chrono::high_resolution_clock::time_point last_report_time_
tuple pid
Definition: sysUtil.py:22
double rate(double x)
Definition: Constants.cc:3

Member Data Documentation

ptree dqmservices::DQMMonitoringService::extra_
private

Definition at line 53 of file DQMMonitoringService.h.

Referenced by registerExtra(), and reportLumiSectionUnsafe().

int dqmservices::DQMMonitoringService::fseq_
private

Definition at line 50 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), and reportLumiSectionUnsafe().

std::string dqmservices::DQMMonitoringService::hostname_
private

Definition at line 48 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), and reportLumiSectionUnsafe().

boost::filesystem::path dqmservices::DQMMonitoringService::json_path_
private

Definition at line 47 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), and reportLumiSectionUnsafe().

long dqmservices::DQMMonitoringService::last_report_nevents_
private

Definition at line 56 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), and reportLumiSectionUnsafe().

std::chrono::high_resolution_clock::time_point dqmservices::DQMMonitoringService::last_report_time_
private

Definition at line 57 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), and reportLumiSectionUnsafe().

long dqmservices::DQMMonitoringService::nevents_
private
ptree dqmservices::DQMMonitoringService::ps_info_
private
std::string dqmservices::DQMMonitoringService::tag_
private