LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
BlockTimingLog.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
29 #include <fstream>
30 
31 namespace lsst {
32 namespace pex {
33 namespace logging {
34 
36 
37 const std::string BlockTimingLog::STATUS("STATUS");
38 const std::string BlockTimingLog::START("start");
39 const std::string BlockTimingLog::END("end");
40 
41 BlockTimingLog::BlockTimingLog(const Log& parent, const std::string& name,
42  int tracelev, int usageFlags,
43  const std::string& funcName)
44  : Log(parent, name), _tracelev(tracelev), _pusageFlags(0),
45  _usageFlags(usageFlags), _funcName(funcName), _usage()
46 
47 {
48  if (_funcName.length() == 0) _funcName = name;
49  const BlockTimingLog *p = dynamic_cast<const BlockTimingLog*>(&parent);
51  if (p) {
53  }
54  else {
56  }
57  }
58  if (_usageFlags == PARENTUDATA) {
59  if (p) addUsageFlags(p->getUsageFlags());
60  }
61 }
62 
64 
66  if (! _usage.get()) _usage.reset(new struct rusage());
67 
68  if (getrusage(RUSAGE_SELF, _usage.get()) == 0) {
69  double d = 0;
70  if (_usageFlags & UTIME) {
71  d = _usage->ru_utime.tv_sec + _usage->ru_utime.tv_usec/1.0e6;
72  rec.addProperty("usertime", d);
73  }
74  if (_usageFlags & STIME) {
75  d = _usage->ru_utime.tv_sec + _usage->ru_utime.tv_usec/1.0e6;
76  rec.addProperty("systemtime", d);
77  }
78  if (_usageFlags & MEMSZ) rec.addProperty("maxrss", _usage->ru_maxrss);
79  if (_usageFlags & MINFLT) rec.addProperty("minflt", _usage->ru_minflt);
80  if (_usageFlags & MAJFLT) rec.addProperty("majflt", _usage->ru_majflt);
81  if (_usageFlags & NSWAP) rec.addProperty("nswap", _usage->ru_nswap);
82  if (_usageFlags & BLKIN) rec.addProperty("blocksin", _usage->ru_inblock);
83  if (_usageFlags & BLKOUT) rec.addProperty("blocksout", _usage->ru_oublock);
84  }
85 }
86 
87 }}} // end lsst::pex::logging
definition of the BlockTimingLog class
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static const std::string START
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:99
static const int INHERIT_THRESHOLD
Definition: Log.h:183
static const std::string STATUS
static const int INFO
Definition: Log.h:171
void addProperty(const RecordProperty< T > &property)
Definition: LogRecord.h:327
boost::scoped_ptr< struct rusage > _usage
void addUsageProps(LogRecord &rec)
static const std::string END