LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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 
39 #include <memory>
40 #include <string>
41 
42 namespace lsst {
43 namespace pex {
44 namespace logging {
45 
61 class BlockTimingLog : public Log {
62 public:
63 
67  enum usageData {
71  NOUDATA = 0,
72 
76  UTIME = 1,
77 
81  STIME = 2,
82 
87  SUTIME = 3,
88 
93  MEMSZ = 4,
94 
98  NSWAP = 16,
99 
103  BLKIN = 32,
104 
108  BLKOUT = 64,
109 
114  BLKIO = 96,
115 
120  MINFLT = 128,
121 
126  MAJFLT = 256,
127 
132  LINUXUDATA = 387,
133 
137  ALLUDATA = 511,
138 
143  PARENTUDATA = 8192
144  };
145 
149  static const int INSTRUM; // = Log::INFO - 3
150 
155  static const std::string STATUS;
156 
161  static const std::string START;
162 
167  static const std::string END;
168 
182  BlockTimingLog(const Log& parent, const std::string& name,
183  int tracelev=BlockTimingLog::INSTRUM,
184  int usageFlags=PARENTUDATA, const std::string& funcName="");
185 
190  : Log(*this), _tracelev(that._tracelev), _funcName(that._funcName)
191  { }
192 
197  Log::operator=(that);
198  _tracelev = that._tracelev;
199  _funcName = that._funcName;
200  return *this;
201  }
202 
207  int getUsageFlags() const { return _usageFlags; }
208 
216  void setUsageFlags(int flags) {
217  _usageFlags = flags;
218  if ((flags & PARENTUDATA) > 0) _usageFlags |= _pusageFlags;
219  }
220 
229  void addUsageFlags(int flags) {
230  _usageFlags |= flags;
231  if ((flags & PARENTUDATA) > 0) _usageFlags |= _pusageFlags;
232  }
233 
248  BlockTimingLog *createForBlock(const std::string& name,
249  int tracelev=Log::INHERIT_THRESHOLD,
250  const std::string& funcName="")
251  {
252  BlockTimingLog *out = new BlockTimingLog(*this, name, tracelev,
253  PARENTUDATA, funcName);
254  // out->setShowAll(true);
255  out->start();
256  return out;
257  }
258 
262  BlockTimingLog *timeBlock(const std::string& name,
263  int tracelev=Log::INHERIT_THRESHOLD,
264  const std::string& funcName="")
265  {
266  return createForBlock(name, tracelev, funcName);
267  }
268 
272  virtual ~BlockTimingLog();
273 
278  void start() {
279  if (sends(_tracelev)) {
280  std::string msg("Starting ");
281  msg += _funcName;
282 
284  willShowAll());
285  rec.addComment(msg);
286  rec.addProperty(STATUS, START);
287  if (_usageFlags) addUsageProps(rec);
288  send(rec);
289  }
290  }
291 
296  void start(const std::string& funcName) {
297  if (funcName.length() > 0) _funcName = funcName;
298  start();
299  }
300 
305  void done() {
306  if (sends(_tracelev)) {
307  std::string msg("Ending ");
308  msg += _funcName;
309 
311  willShowAll());
312  rec.addComment(msg);
313  rec.addProperty(STATUS, END);
314  if (_usageFlags) addUsageProps(rec);
315  send(rec);
316  }
317  }
318 
323  int getInstrumentationLevel() const { return _tracelev; }
324 
329  const std::string& getFunctionName() const { return _funcName; }
330 
335  void addUsageProps(LogRecord& rec);
336 
337 private:
340  std::string _funcName;
341  std::unique_ptr<struct rusage> _usage;
342 };
343 
344 }}} // end lsst::pex::logging
345 #endif // end LSST_PEX_BLOCKTIMINGLOG_H
void start(const std::string &funcName)
bool sends(int importance) const
Definition: Log.h:302
void addProperty(const RecordProperty< T > &property)
Definition: LogRecord.h:328
table::Key< std::string > name
Definition: ApCorrMap.cc:71
BlockTimingLog * createForBlock(const std::string &name, int tracelev=Log::INHERIT_THRESHOLD, const std::string &funcName="")
Log & operator=(const Log &that)
void send(const LogRecord &record)
BlockTimingLog(const Log &parent, const std::string &name, int tracelev=BlockTimingLog::INSTRUM, int usageFlags=PARENTUDATA, const std::string &funcName="")
a place to record messages and descriptions of the state of processing.
Definition: Log.h:154
a container for constructing a single Log record
Definition: LogRecord.h:100
definition of the LogRecord, RecordProperty and Prop classes
BlockTimingLog & operator=(const BlockTimingLog &that)
void addComment(const std::string &comment)
Definition: LogRecord.h:166
const lsst::daf::base::PropertySet & getPreamble()
Definition: Log.h:588
int getThreshold() const
Definition: Log.h:281
static const std::string START
bool willShowAll() const
Definition: Log.h:335
static const std::string STATUS
const std::string & getFunctionName() const
static const int INHERIT_THRESHOLD
Definition: Log.h:183
BlockTimingLog * timeBlock(const std::string &name, int tracelev=Log::INHERIT_THRESHOLD, const std::string &funcName="")
static const std::string END
std::unique_ptr< struct rusage > _usage
void addUsageProps(LogRecord &rec)
BlockTimingLog(const BlockTimingLog &that)