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
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
lsst::pex::logging::BlockTimingLog Class Reference

#include <BlockTimingLog.h>

Inheritance diagram for lsst::pex::logging::BlockTimingLog:
lsst::pex::logging::Log

Public Types

enum  usageData {
  NOUDATA = 0, UTIME = 1, STIME = 2, SUTIME = 3,
  MEMSZ = 4, NSWAP = 16, BLKIN = 32, BLKOUT = 64,
  BLKIO = 96, MINFLT = 128, MAJFLT = 256, LINUXUDATA = 387,
  ALLUDATA = 511, PARENTUDATA = 8192
}
 

Public Member Functions

 BlockTimingLog (const Log &parent, const std::string &name, int tracelev=BlockTimingLog::INSTRUM, int usageFlags=PARENTUDATA, const std::string &funcName="")
 
 BlockTimingLog (const BlockTimingLog &that)
 
BlockTimingLogoperator= (const BlockTimingLog &that)
 
int getUsageFlags () const
 
void setUsageFlags (int flags)
 
void addUsageFlags (int flags)
 
BlockTimingLogcreateForBlock (const std::string &name, int tracelev=Log::INHERIT_THRESHOLD, const std::string &funcName="")
 
BlockTimingLogtimeBlock (const std::string &name, int tracelev=Log::INHERIT_THRESHOLD, const std::string &funcName="")
 
virtual ~BlockTimingLog ()
 
void start ()
 
void start (const std::string &funcName)
 
void done ()
 
int getInstrumentationLevel () const
 
const std::string & getFunctionName () const
 
void addUsageProps (LogRecord &rec)
 
- Public Member Functions inherited from lsst::pex::logging::Log
 Log (const int threshold=INFO, const std::string &name="")
 
 Log (const std::list< boost::shared_ptr< LogDestination > > &destinations, const lsst::daf::base::PropertySet &preamble, const std::string &name="", const int threshold=INFO, bool defaultShowAll=false)
 
 Log (const Log &parent, const std::string &childName, int threshold=INHERIT_THRESHOLD)
 
 Log (const Log &that)
 
virtual ~Log ()
 
Logoperator= (const Log &that)
 
const std::string & getName () const
 
int getThreshold () const
 
void setThreshold (int threshold)
 
bool sends (int importance) const
 
void resetThreshold ()
 
void setThresholdFor (const std::string &name, int threshold)
 
int getThresholdFor (const std::string &name) const
 
bool willShowAll () const
 
void setShowAll (bool yesno)
 
void resetShowAll ()
 
template<class T >
void addPreambleProperty (const std::string &name, const T &val)
 
template<class T >
void setPreambleProperty (const std::string &name, const T &val)
 
LogcreateChildLog (const std::string &childName, int threshold=INHERIT_THRESHOLD) const
 
void log (int importance, const std::string &message, const lsst::daf::base::PropertySet &properties)
 
template<class T >
void log (int importance, const std::string &message, const std::string &name, const T &val)
 
template<class T >
void log (int importance, const std::string &message, const RecordProperty< T > &prop)
 
void log (int importance, const std::string &message)
 
void log (int importance, const boost::format &message)
 
void logdebug (const std::string &message, const lsst::daf::base::PropertySet &properties)
 
template<class T >
void logdebug (const std::string &message, const std::string &name, const T &val)
 
template<class T >
void logdebug (const std::string &message, const RecordProperty< T > &prop)
 
void logdebug (const std::string &message)
 
void logdebug (const boost::format &message)
 
void info (const std::string &message, const lsst::daf::base::PropertySet &properties)
 
template<class T >
void info (const std::string &message, const std::string &name, const T &val)
 
template<class T >
void info (const std::string &message, const RecordProperty< T > &prop)
 
void info (const std::string &message)
 
void info (const boost::format &message)
 
void warn (const std::string &message, const lsst::daf::base::PropertySet &properties)
 
template<class T >
void warn (const std::string &message, const std::string &name, const T &val)
 
template<class T >
void warn (const std::string &message, const RecordProperty< T > &prop)
 
void warn (const std::string &message)
 
void warn (const boost::format &message)
 
void fatal (const std::string &message, const lsst::daf::base::PropertySet &properties)
 
template<class T >
void fatal (const std::string &message, const std::string &name, const T &val)
 
template<class T >
void fatal (const std::string &message, const RecordProperty< T > &prop)
 
void fatal (const std::string &message)
 
void fatal (const boost::format &message)
 
void format (int importance, const char *fmt,...)
 
void debugf (const char *fmt,...)
 
void infof (const char *fmt,...)
 
void warnf (const char *fmt,...)
 
void fatalf (const char *fmt,...)
 
void send (const LogRecord &record)
 
void addDestination (std::ostream &destination, int threshold)
 
void addDestination (std::ostream &destination, int threshold, const boost::shared_ptr< LogFormatter > &formatter)
 
void addDestination (const boost::shared_ptr< LogDestination > &destination)
 
const
lsst::daf::base::PropertySet
getPreamble ()
 
void markPersistent ()
 
void printThresholds (std::ostream &out)
 
void reset ()
 

Static Public Attributes

static const int INSTRUM = logging::Log::INFO - 3
 
static const std::string STATUS
 
static const std::string START
 
static const std::string END
 
- Static Public Attributes inherited from lsst::pex::logging::Log
static const int DEBUG
 
static const int INFO
 
static const int WARN
 
static const int INHERIT_THRESHOLD
 
static const int FATAL
 

Private Attributes

int _tracelev
 
int _pusageFlags
 
int _usageFlags
 
std::string _funcName
 
boost::scoped_ptr< struct rusage > _usage
 

Additional Inherited Members

- Static Public Member Functions inherited from lsst::pex::logging::Log
static LoggetDefaultLog ()
 
static void createDefaultLog (const std::list< boost::shared_ptr< LogDestination > > &destinations, const lsst::daf::base::PropertySet &preamble, const std::string &name="", const int threshold=INFO)
 
static void closeDefaultLog ()
 
- Protected Member Functions inherited from lsst::pex::logging::Log
void _send (int threshold, int importance, const char *fmt, va_list ap)
 
void _format (int importance, const char *fmt, va_list ap)
 
- Static Protected Member Functions inherited from lsst::pex::logging::Log
static void setDefaultLog (Log *deflog)
 
- Protected Attributes inherited from lsst::pex::logging::Log
boost::shared_ptr
< threshold::Memory
_thresholds
 
std::list< boost::shared_ptr
< LogDestination > > 
_destinations
 
lsst::daf::base::PropertySet::Ptr _preamble
 
- Static Protected Attributes inherited from lsst::pex::logging::Log
static LogdefaultLog
 
static const std::string _sep
 

Detailed Description

a specialized Log that assists the harness in tracing execution flow.

The motivation for this class is to provide uniformity in the log messages that indicate the start and finish of some section of code. This makes it easier to locate these records after execution and calculate the time spent in the block of code.

This class can optionally be used to simultaneously capture usage data. In particular, it can add as properties the following system informtation: user cpu time, system cpu time, memory usage (as maximum resident size), the number of swaps, the number of block input operations, and the number of output operations. Which of these are save with the log message is controlled by a bit map.

Definition at line 59 of file BlockTimingLog.h.

Member Enumeration Documentation

an enumeration for controlling which usage data to collect

Enumerator
NOUDATA 

flag to indicate that no usage data should be captured

UTIME 

flag to enable collecting the usage datum, user time

STIME 

flag to enable collecting the usage datum, system time

SUTIME 

flag to enable collecting the usage datum, user and system time. This is equal to UTIME|STIME.

MEMSZ 

flag to enable collecting the usage datum, memory size (as max resident size)

NSWAP 

flag to enable collecting the usage datum, number of swaps.

BLKIN 

flag to enable collecting the usage datum, number of block reads.

BLKOUT 

flag to enable collecting the usage datum, number of block writes.

BLKIO 

flag to enable collecting the usage data, the number of block reads and writes. This is equal to BLKIN|BLKOUT

MINFLT 

flag to enable collecting the usage datum, the number of minor page faults since the start of the process.

MAJFLT 

flag to enable collecting the usage datum, the number of major page faults since the start of the process.

LINUXUDATA 

flag to enable collecting the usage data supported by Linux (as of kernal version 2.6): SUTIME|MINFLT|MAJFLT

ALLUDATA 

flag to enable collecting all usage data

PARENTUDATA 

flag to indicate that the usages flags should be inherited from the parent log.

Definition at line 65 of file BlockTimingLog.h.

Constructor & Destructor Documentation

lsst::pex::logging::BlockTimingLog::BlockTimingLog ( const Log parent,
const std::string &  name,
int  tracelev = BlockTimingLog::INSTRUM,
int  usageFlags = PARENTUDATA,
const std::string &  funcName = "" 
)

construct a BlockTimingLog.

Parameters
parentthe parent log to inherit attributes from
namethe name to give the log relative to its parent
tracelevthe default level to use for the tracing messages
funcNamethe name of the block of code (e.g. function) being traced. If empty, the value given by name will be used instead. This value will be used in the log message only.
usageFlagsa or-ed list of usageData values that indicate which usage data to capture.

Definition at line 41 of file BlockTimingLog.cc.

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) {
52  _tracelev = p->getInstrumentationLevel();
53  }
54  else {
56  }
57  }
58  if (_usageFlags == PARENTUDATA) {
59  if (p) addUsageFlags(p->getUsageFlags());
60  }
61 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
BlockTimingLog(const Log &parent, const std::string &name, int tracelev=BlockTimingLog::INSTRUM, int usageFlags=PARENTUDATA, const std::string &funcName="")
static const int INHERIT_THRESHOLD
Definition: Log.h:183
boost::scoped_ptr< struct rusage > _usage
Log(const int threshold=INFO, const std::string &name="")
lsst::pex::logging::BlockTimingLog::BlockTimingLog ( const BlockTimingLog that)
inline

create a copy of a BlockTimingLog

Definition at line 187 of file BlockTimingLog.h.

188  : Log(*this), _tracelev(that._tracelev), _funcName(that._funcName)
189  { }
Log(const int threshold=INFO, const std::string &name="")
lsst::pex::logging::BlockTimingLog::~BlockTimingLog ( )
virtual

delete the log

Definition at line 63 of file BlockTimingLog.cc.

63 { }

Member Function Documentation

void lsst::pex::logging::BlockTimingLog::addUsageFlags ( int  flags)
inline

add to the list of usage data that will be collected. Previously set values will be preserved.

Parameters
flagsan integer of OR-ed usageData values for the specific data that should be captured. Use PARENTUDATA to include the parent log's usage data flags (what ever they were when this log was created).

Definition at line 227 of file BlockTimingLog.h.

void lsst::pex::logging::BlockTimingLog::addUsageProps ( LogRecord rec)

add usage properties to a given LogRecord according the currently set usage flags.

Definition at line 65 of file BlockTimingLog.cc.

65  {
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 }
boost::scoped_ptr< struct rusage > _usage
BlockTimingLog* lsst::pex::logging::BlockTimingLog::createForBlock ( const std::string &  name,
int  tracelev = Log::INHERIT_THRESHOLD,
const std::string &  funcName = "" 
)
inline

create and return a new child that should be used while tracing a function. A "start" message will be logged to the new log as part of the call. Like createChildLog(), the caller is responsible for deleting this new instance when finished with it.

Parameters
namethe name to give the log relative to its parent
tracelevthe default level to use for the tracing messages. If equal to Log::INHERIT_THRESHOLD (default), it will be set to this log's tracing level.
funcNamethe name of the block of code (e.g. function) being traced. If empty, the value given by name will be used instead. This value will be used in the log message only.

Definition at line 246 of file BlockTimingLog.h.

249  {
250  BlockTimingLog *out = new BlockTimingLog(*this, name, tracelev,
251  PARENTUDATA, funcName);
252  // out->setShowAll(true);
253  out->start();
254  return out;
255  }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
BlockTimingLog(const Log &parent, const std::string &name, int tracelev=BlockTimingLog::INSTRUM, int usageFlags=PARENTUDATA, const std::string &funcName="")
void lsst::pex::logging::BlockTimingLog::done ( )
inline

Indicate that the section of code being instrumented (e.g. a function body) is finished.

Definition at line 303 of file BlockTimingLog.h.

303  {
304  if (sends(_tracelev)) {
305  std::string msg("Ending ");
306  msg += _funcName;
307 
308  LogRecord rec(getThreshold(), _tracelev, getPreamble(),
309  willShowAll());
310  rec.addComment(msg);
311  rec.addProperty(STATUS, END);
312  if (_usageFlags) addUsageProps(rec);
313  send(rec);
314  }
315  }
int getThreshold() const
Definition: Log.h:281
void send(const LogRecord &record)
static const std::string STATUS
bool willShowAll() const
Definition: Log.h:335
bool sends(int importance) const
Definition: Log.h:302
void addUsageProps(LogRecord &rec)
const lsst::daf::base::PropertySet & getPreamble()
Definition: Log.h:580
static const std::string END
const std::string& lsst::pex::logging::BlockTimingLog::getFunctionName ( ) const
inline

return the name of the code block being traced which will appear in the start and end messages.

Definition at line 327 of file BlockTimingLog.h.

327 { return _funcName; }
int lsst::pex::logging::BlockTimingLog::getInstrumentationLevel ( ) const
inline

return the instrumenting message level, the importance to be given to the start and end messages.

Definition at line 321 of file BlockTimingLog.h.

int lsst::pex::logging::BlockTimingLog::getUsageFlags ( ) const
inline

return an OR-ed list of flags indicating the usage data this object is set to collect with each message.

Definition at line 205 of file BlockTimingLog.h.

BlockTimingLog& lsst::pex::logging::BlockTimingLog::operator= ( const BlockTimingLog that)
inline

reset this instance to another

Definition at line 194 of file BlockTimingLog.h.

194  {
195  Log::operator=(that);
196  _tracelev = that._tracelev;
197  _funcName = that._funcName;
198  return *this;
199  }
Log & operator=(const Log &that)
void lsst::pex::logging::BlockTimingLog::setUsageFlags ( int  flags)
inline

set the usage data that will be collected.

Parameters
flagsan integer of OR-ed usageData values for the specific data that should be captured. Use NOUDATA to turn off the capturing of this data. Use PARENTUDATA to revert to the parent log's usage data flags.

Definition at line 214 of file BlockTimingLog.h.

void lsst::pex::logging::BlockTimingLog::start ( )
inline

Indicate that the section of code being traced (e.g. a function body) is starting.

Definition at line 276 of file BlockTimingLog.h.

276  {
277  if (sends(_tracelev)) {
278  std::string msg("Starting ");
279  msg += _funcName;
280 
281  LogRecord rec(getThreshold(), _tracelev, getPreamble(),
282  willShowAll());
283  rec.addComment(msg);
284  rec.addProperty(STATUS, START);
285  if (_usageFlags) addUsageProps(rec);
286  send(rec);
287  }
288  }
int getThreshold() const
Definition: Log.h:281
static const std::string START
void send(const LogRecord &record)
static const std::string STATUS
bool willShowAll() const
Definition: Log.h:335
bool sends(int importance) const
Definition: Log.h:302
void addUsageProps(LogRecord &rec)
const lsst::daf::base::PropertySet & getPreamble()
Definition: Log.h:580
void lsst::pex::logging::BlockTimingLog::start ( const std::string &  funcName)
inline

Indicate that the section of code being instrumented (e.g. a function body) is starting.

Definition at line 294 of file BlockTimingLog.h.

294  {
295  if (funcName.length() > 0) _funcName = funcName;
296  start();
297  }
BlockTimingLog* lsst::pex::logging::BlockTimingLog::timeBlock ( const std::string &  name,
int  tracelev = Log::INHERIT_THRESHOLD,
const std::string &  funcName = "" 
)
inline

a synonym for createForBlock

Definition at line 260 of file BlockTimingLog.h.

263  {
264  return createForBlock(name, tracelev, funcName);
265  }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
BlockTimingLog * createForBlock(const std::string &name, int tracelev=Log::INHERIT_THRESHOLD, const std::string &funcName="")

Member Data Documentation

std::string lsst::pex::logging::BlockTimingLog::_funcName
private

Definition at line 338 of file BlockTimingLog.h.

int lsst::pex::logging::BlockTimingLog::_pusageFlags
private

Definition at line 337 of file BlockTimingLog.h.

int lsst::pex::logging::BlockTimingLog::_tracelev
private

Definition at line 336 of file BlockTimingLog.h.

boost::scoped_ptr<struct rusage> lsst::pex::logging::BlockTimingLog::_usage
private

Definition at line 339 of file BlockTimingLog.h.

int lsst::pex::logging::BlockTimingLog::_usageFlags
private

Definition at line 337 of file BlockTimingLog.h.

const std::string lsst::pex::logging::BlockTimingLog::END
static

the property to use to mark the start of a block of code being instrumented

Definition at line 165 of file BlockTimingLog.h.

const int lsst::pex::logging::BlockTimingLog::INSTRUM = logging::Log::INFO - 3
static

default message level for messages that instrument execution flow

Definition at line 147 of file BlockTimingLog.h.

const std::string lsst::pex::logging::BlockTimingLog::START
static

the property to use to mark the start of a block of code being instrumented

Definition at line 159 of file BlockTimingLog.h.

const std::string lsst::pex::logging::BlockTimingLog::STATUS
static

the property name that will indicate what an instrumenting message is marking

Definition at line 153 of file BlockTimingLog.h.


The documentation for this class was generated from the following files: