-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Timing service reported CPU time for child processes as part of the total CPU time, but not as part of the loop time. The timing summary did not account for child processes at all.
- Loading branch information
Showing
5 changed files
with
211 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef FWCore_Utilities_ChildrenCPUTimer_h | ||
#define FWCore_Utilities_ChildrenCPUTimer_h | ||
// -*- C++ -*- | ||
// | ||
// Package: Utilities | ||
// Class : ChildrenCPUTimer | ||
// | ||
/**\class ChildrenCPUTimer ChildrenCPUTimer.h FWCore/Utilities/interface/ChildrenCPUTimer.h | ||
Description: Timer which measures the CPU time for child processes | ||
Usage: | ||
<usage> | ||
*/ | ||
// | ||
// Original Author: Chris Jones | ||
// Created: Sun Apr 16 20:32:13 EDT 2006 | ||
// | ||
|
||
// system include files | ||
#include <sys/time.h> | ||
|
||
// user include files | ||
|
||
// forward declarations | ||
namespace edm { | ||
class ChildrenCPUTimer { | ||
public: | ||
ChildrenCPUTimer(); | ||
~ChildrenCPUTimer(); | ||
ChildrenCPUTimer(ChildrenCPUTimer&&) = default; | ||
ChildrenCPUTimer(const ChildrenCPUTimer&) = delete; | ||
ChildrenCPUTimer& operator=(const ChildrenCPUTimer&) = delete; | ||
|
||
// ---------- const member functions --------------------- | ||
double cpuTime() const; | ||
|
||
// ---------- static member functions -------------------- | ||
|
||
// ---------- member functions --------------------------- | ||
void start(); | ||
double stop(); //returns delta time | ||
void reset(); | ||
|
||
void add(double t); | ||
|
||
private: | ||
double calculateDeltaTime() const; | ||
|
||
// ---------- member data -------------------------------- | ||
enum State { kRunning, kStopped } state_; | ||
struct timeval startCPUTime_; | ||
|
||
double accumulatedCPUTime_; | ||
}; | ||
} // namespace edm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// -*- C++ -*- | ||
// | ||
// Package: Utilities | ||
// Class : ChildrenCPUTimer | ||
// | ||
// Implementation: | ||
// <Notes on implementation> | ||
// | ||
// Original Author: Chris Jones | ||
// Created: Sun Apr 16 20:32:20 EDT 2006 | ||
// | ||
|
||
// system include files | ||
#include <sys/resource.h> | ||
#include <cerrno> | ||
|
||
// user include files | ||
#include "FWCore/Utilities/interface/ChildrenCPUTimer.h" | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
|
||
// | ||
// constants, enums and typedefs | ||
// | ||
using namespace edm; | ||
|
||
// | ||
// static data member definitions | ||
// | ||
|
||
// | ||
// constructors and destructor | ||
// | ||
ChildrenCPUTimer::ChildrenCPUTimer() : state_(kStopped), startCPUTime_(), accumulatedCPUTime_(0) { | ||
startCPUTime_.tv_sec = 0; | ||
startCPUTime_.tv_usec = 0; | ||
} | ||
|
||
// ChildrenCPUTimer::ChildrenCPUTimer(ChildrenCPUTimer const& rhs) { | ||
// // do actual copying here; | ||
// } | ||
|
||
ChildrenCPUTimer::~ChildrenCPUTimer() {} | ||
|
||
// | ||
// assignment operators | ||
// | ||
// ChildrenCPUTimer const& ChildrenCPUTimer::operator=(ChildrenCPUTimer const& rhs) { | ||
// //An exception safe implementation is | ||
// ChildrenCPUTimer temp(rhs); | ||
// swap(rhs); | ||
// | ||
// return *this; | ||
// } | ||
|
||
// | ||
// member functions | ||
// | ||
void ChildrenCPUTimer::start() { | ||
if (kStopped == state_) { | ||
rusage theUsage; | ||
if (0 != getrusage(RUSAGE_CHILDREN, &theUsage)) { | ||
throw cms::Exception("ChildrenCPUTimerFailed") << errno; | ||
} | ||
startCPUTime_.tv_sec = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec; | ||
startCPUTime_.tv_usec = theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec; | ||
state_ = kRunning; | ||
} | ||
} | ||
|
||
double ChildrenCPUTimer::stop() { | ||
if (kRunning == state_) { | ||
auto t = calculateDeltaTime(); | ||
accumulatedCPUTime_ += t; | ||
|
||
state_ = kStopped; | ||
return t; | ||
} | ||
return 0.; | ||
} | ||
|
||
void ChildrenCPUTimer::reset() { accumulatedCPUTime_ = 0; } | ||
|
||
void ChildrenCPUTimer::add(double t) { accumulatedCPUTime_ += t; } | ||
|
||
double ChildrenCPUTimer::calculateDeltaTime() const { | ||
double returnValue; | ||
double const microsecToSec = 1E-6; | ||
|
||
rusage theUsage; | ||
if (0 != getrusage(RUSAGE_CHILDREN, &theUsage)) { | ||
throw cms::Exception("CPUTimerFailed") << errno; | ||
} | ||
|
||
returnValue = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec - startCPUTime_.tv_sec + | ||
microsecToSec * (theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec - startCPUTime_.tv_usec); | ||
return returnValue; | ||
} | ||
// | ||
// const member functions | ||
// | ||
double ChildrenCPUTimer::cpuTime() const { | ||
if (kStopped == state_) { | ||
return accumulatedCPUTime_; | ||
} | ||
return accumulatedCPUTime_ + calculateDeltaTime(); | ||
} | ||
|
||
// | ||
// static member functions | ||
// |