LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
BlockTimingLog.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
30 #ifndef LSST_PEX_LOGGING_BLOCKTIMINGLOG_H
31 #define LSST_PEX_LOGGING_BLOCKTIMINGLOG_H
32 
34 #include "lsst/pex/logging/Log.h"
35 
36 #include <sys/time.h>
37 #include <sys/resource.h>
38 #include <boost/scoped_ptr.hpp>
39 
40 namespace lsst {
41 namespace pex {
42 namespace logging {
43 
59 class BlockTimingLog : public Log {
60 public:
61 
65  enum usageData {
69  NOUDATA = 0,
70 
74  UTIME = 1,
75 
79  STIME = 2,
80 
85  SUTIME = 3,
86 
91  MEMSZ = 4,
92 
96  NSWAP = 16,
97 
101  BLKIN = 32,
102 
106  BLKOUT = 64,
107 
112  BLKIO = 96,
113 
118  MINFLT = 128,
119 
124  MAJFLT = 256,
125 
130  LINUXUDATA = 387,
131 
135  ALLUDATA = 511,
136 
141  PARENTUDATA = 8192
142  };
143 
147  static const int INSTRUM; // = Log::INFO - 3
148 
153  static const std::string STATUS;
154 
159  static const std::string START;
160 
165  static const std::string END;
166 
180  BlockTimingLog(const Log& parent, const std::string& name,
181  int tracelev=BlockTimingLog::INSTRUM,
182  int usageFlags=PARENTUDATA, const std::string& funcName="");
183 
188  : Log(*this), _tracelev(that._tracelev), _funcName(that._funcName)
189  { }
190 
195  Log::operator=(that);
196  _tracelev = that._tracelev;
197  _funcName = that._funcName;
198  return *this;
199  }
200 
205  int getUsageFlags() const { return _usageFlags; }
206 
214  void setUsageFlags(int flags) {
215  _usageFlags = flags;
216  if ((flags & PARENTUDATA) > 0) _usageFlags |= _pusageFlags;
217  }
218 
227  void addUsageFlags(int flags) {
228  _usageFlags |= flags;
229  if ((flags & PARENTUDATA) > 0) _usageFlags |= _pusageFlags;
230  }
231 
246  BlockTimingLog *createForBlock(const std::string& name,
247  int tracelev=Log::INHERIT_THRESHOLD,
248  const std::string& funcName="")
249  {
250  BlockTimingLog *out = new BlockTimingLog(*this, name, tracelev,
251  PARENTUDATA, funcName);
252  // out->setShowAll(true);
253  out->start();
254  return out;
255  }
256 
260  BlockTimingLog *timeBlock(const std::string& name,
261  int tracelev=Log::INHERIT_THRESHOLD,
262  const std::string& funcName="")
263  {
264  return createForBlock(name, tracelev, funcName);
265  }
266 
270  virtual ~BlockTimingLog();
271 
276  void start() {
277  if (sends(_tracelev)) {
278  std::string msg("Starting ");
279  msg += _funcName;
280 
282  willShowAll());
283  rec.addComment(msg);
284  rec.addProperty(STATUS, START);
285  if (_usageFlags) addUsageProps(rec);
286  send(rec);
287  }
288  }
289 
294  void start(const std::string& funcName) {
295  if (funcName.length() > 0) _funcName = funcName;
296  start();
297  }
298 
303  void done() {
304  if (sends(_tracelev)) {
305  std::string msg("Ending ");
306  msg += _funcName;
307 
309  willShowAll());
310  rec.addComment(msg);
311  rec.addProperty(STATUS, END);
312  if (_usageFlags) addUsageProps(rec);
313  send(rec);
314  }
315  }
316 
321  int getInstrumentationLevel() const { return _tracelev; }
322 
327  const std::string& getFunctionName() const { return _funcName; }
328 
333  void addUsageProps(LogRecord& rec);
334 
335 private:
338  std::string _funcName;
339  boost::scoped_ptr<struct rusage> _usage;
340 };
341 
342 }}} // end lsst::pex::logging
343 #endif // end LSST_PEX_BLOCKTIMINGLOG_H
table::Key< std::string > name
Definition: ApCorrMap.cc:71
void addComment(const std::string &comment)
Definition: LogRecord.h:165
int getThreshold() const
Definition: Log.h:281
static const std::string START
BlockTimingLog(const Log &parent, const std::string &name, int tracelev=BlockTimingLog::INSTRUM, int usageFlags=PARENTUDATA, const std::string &funcName="")
Log & operator=(const Log &that)
void send(const LogRecord &record)
const std::string & getFunctionName() const
a place to record messages and descriptions of the state of processing.
Definition: Log.h:154
void start(const std::string &funcName)
BlockTimingLog * createForBlock(const std::string &name, int tracelev=Log::INHERIT_THRESHOLD, const std::string &funcName="")
a container for constructing a single Log record
Definition: LogRecord.h:99
definition of the LogRecord, RecordProperty and Prop classes
static const int INHERIT_THRESHOLD
Definition: Log.h:183
BlockTimingLog & operator=(const BlockTimingLog &that)
static const std::string STATUS
bool willShowAll() const
Definition: Log.h:335
BlockTimingLog * timeBlock(const std::string &name, int tracelev=Log::INHERIT_THRESHOLD, const std::string &funcName="")
void addProperty(const RecordProperty< T > &property)
Definition: LogRecord.h:327
bool sends(int importance) const
Definition: Log.h:302
boost::scoped_ptr< struct rusage > _usage
void addUsageProps(LogRecord &rec)
BlockTimingLog(const BlockTimingLog &that)
const lsst::daf::base::PropertySet & getPreamble()
Definition: Log.h:580
static const std::string END