Skip to content

Commit

Permalink
Merge CMSSW_9_4_X into CMSSW_9_4_AN_X.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsbuild committed Apr 10, 2018
2 parents 106e894 + 94af51d commit 0e57a2c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
17 changes: 11 additions & 6 deletions FWCore/Services/plugins/Timing.cc
Expand Up @@ -40,7 +40,7 @@ namespace edm {

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);

void addToCPUTime(StreamID id, double iTime) override;
void addToCPUTime(double iTime) override;
double getTotalCPU() const override;

private:
Expand Down Expand Up @@ -78,6 +78,7 @@ namespace edm {

double curr_job_time_; // seconds
double curr_job_cpu_; // seconds
std::atomic<double> extra_job_cpu_; //seconds
//use last run time for determining end of processing
std::atomic<double> last_run_time_;
std::atomic<double> last_run_cpu_;
Expand Down Expand Up @@ -167,6 +168,7 @@ namespace edm {
Timing::Timing(ParameterSet const& iPS, ActivityRegistry& iRegistry) :
curr_job_time_(0.),
curr_job_cpu_(0.),
extra_job_cpu_(0.0),
last_run_time_(0.0),
last_run_cpu_(0.0),
curr_events_time_(),
Expand Down Expand Up @@ -261,9 +263,10 @@ namespace edm {
Timing::~Timing() {
}

void Timing::addToCPUTime(StreamID id, double iTime) {
void Timing::addToCPUTime(double iTime) {
//For accounting purposes we effectively can say we started earlier
curr_job_cpu_ -= iTime;
double expected = extra_job_cpu_.load();
while( not extra_job_cpu_.compare_exchange_strong(expected,expected+iTime) ) {}
}

double Timing::getTotalCPU() const {
Expand Down Expand Up @@ -303,15 +306,15 @@ namespace edm {
const double job_end_cpu =getCPU();
double total_job_time = job_end_time - jobStartTime();

double total_job_cpu = job_end_cpu;
double total_job_cpu = job_end_cpu+extra_job_cpu_;

const double total_initialization_time = curr_job_time_ - jobStartTime();
const double total_initialization_cpu = curr_job_cpu_;

if( 0.0 == jobStartTime()) {
//did not capture beginning time
total_job_time =job_end_time - curr_job_time_;
total_job_cpu =job_end_cpu - curr_job_cpu_;
total_job_cpu =job_end_cpu + extra_job_cpu_ - curr_job_cpu_ ;
}

double min_event_time = *(std::min_element(min_events_time_.begin(),
Expand All @@ -320,7 +323,7 @@ namespace edm {
max_events_time_.end()));

auto total_loop_time = last_run_time_ - curr_job_time_;
auto total_loop_cpu = last_run_cpu_ - curr_job_cpu_;
auto total_loop_cpu = last_run_cpu_ + extra_job_cpu_ - curr_job_cpu_;

if(last_run_time_ == 0.0) {
total_loop_time = 0.0;
Expand Down Expand Up @@ -355,8 +358,10 @@ namespace edm {
<< " CPU Summary: \n"
<< " - Total loop: " << total_loop_cpu << "\n"
<< " - Total init: " << total_initialization_cpu <<"\n"
<< " - Total extra: " << extra_job_cpu_ << "\n"
<< " - Total job: " << total_job_cpu << "\n";


if(report_summary_) {
Service<JobReport> reportSvc;
std::map<std::string, std::string> reportData;
Expand Down
2 changes: 1 addition & 1 deletion FWCore/Utilities/interface/TimingServiceBase.h
Expand Up @@ -36,7 +36,7 @@ namespace edm {
///Extra CPU time used by a job but not seen by cmsRun
/// The value should be in seconds.
/// This function is safe to call from multiple threads
virtual void addToCPUTime(StreamID id, double iTime) = 0;
virtual void addToCPUTime(double iTime) = 0;

///CPU time used by this process and all its children.
/// The value returned should be in seconds.
Expand Down
11 changes: 11 additions & 0 deletions GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc
Expand Up @@ -27,6 +27,9 @@ Description: [one line class summary]
#include <dirent.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/resource.h>


#include "boost/bind.hpp"
#include "boost/shared_ptr.hpp"
Expand Down Expand Up @@ -55,6 +58,7 @@ Description: [one line class summary]

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
#include "FWCore/Utilities/interface/TimingServiceBase.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

Expand Down Expand Up @@ -440,6 +444,13 @@ ExternalLHEProducer::executeScript()
break;
}
} while (true);
edm::Service<edm::TimingServiceBase> ts;
if(ts.isAvailable()) {
struct rusage ru;
getrusage(RUSAGE_CHILDREN,&ru);
double time = static_cast<double>(ru.ru_stime.tv_sec) + (static_cast<double>(ru.ru_stime.tv_usec) * 1E-6);
ts->addToCPUTime(time);
}
if (rc) {
throw cms::Exception("ExternalLHEProducer") << "Child failed with exit code " << rc << ".";
}
Expand Down

0 comments on commit 0e57a2c

Please sign in to comment.