Skip to content

Commit

Permalink
Merge pull request #21446 from fwyzard/FastTimerService_add_overhead_…
Browse files Browse the repository at this point in the history
…measurement_100x

FastTimerService: add measurement of framework overhead (100x)
  • Loading branch information
cmsbuild committed Nov 24, 2017
2 parents e634fdc + 4cfbe07 commit b87a2d4
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 72 deletions.
76 changes: 52 additions & 24 deletions HLTrigger/Timer/interface/FastTimerService.h
Expand Up @@ -16,7 +16,7 @@
// tbb headers
#include <tbb/concurrent_unordered_set.h>
#include <tbb/enumerable_thread_specific.h>

#include <tbb/task_scheduler_observer.h>

// CMSSW headers
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
Expand Down Expand Up @@ -80,10 +80,11 @@ Performance of std::chrono::high_resolution_clock
*/


class FastTimerService {
class FastTimerService : public tbb::task_scheduler_observer
{
public:
FastTimerService(const edm::ParameterSet &, edm::ActivityRegistry & );
~FastTimerService();
~FastTimerService() override;

private:
double queryModuleTime_(edm::StreamID, unsigned int id) const;
Expand All @@ -102,8 +103,8 @@ class FastTimerService {
double queryHighlightTime(edm::StreamID sid, std::string const& label) const;

private:
void ignoredSignal(std::string signal) const;
void unsupportedSignal(std::string signal) const;
void ignoredSignal(const std::string& signal) const;
void unsupportedSignal(const std::string& signal) const;

// these signal pairs are not guaranteed to happen in the same thread

Expand Down Expand Up @@ -215,6 +216,10 @@ class FastTimerService {
void preEventReadFromSource(edm::StreamContext const&, edm::ModuleCallingContext const&);
void postEventReadFromSource(edm::StreamContext const&, edm::ModuleCallingContext const&);

// inherited from TBB task_scheduler_observer
void on_scheduler_entry(bool worker) final;
void on_scheduler_exit(bool worker) final;

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

Expand All @@ -241,6 +246,24 @@ class FastTimerService {
uint64_t deallocated;
};

// atomic version of Resources
struct AtomicResources {
public:
AtomicResources();
AtomicResources(AtomicResources const& other);
void reset();

AtomicResources & operator=(AtomicResources const& other);
AtomicResources & operator+=(AtomicResources const& other);
AtomicResources operator+(AtomicResources const& other) const;

public:
std::atomic<boost::chrono::nanoseconds::rep> time_thread;
std::atomic<boost::chrono::nanoseconds::rep> time_real;
std::atomic<uint64_t> allocated;
std::atomic<uint64_t> deallocated;
};

struct ResourcesPerModule {
public:
ResourcesPerModule();
Expand All @@ -253,6 +276,24 @@ class FastTimerService {
unsigned events;
};

// per-thread measurements
struct Measurement {
public:
Measurement();
void measure();
void measure_and_store(Resources & store);
void measure_and_accumulate(AtomicResources & store);

public:
#ifdef DEBUG_THREAD_CONCURRENCY
std::thread::id id;
#endif // DEBUG_THREAD_CONCURRENCY
boost::chrono::thread_clock::time_point time_thread;
boost::chrono::high_resolution_clock::time_point time_real;
uint64_t allocated;
uint64_t deallocated;
};

struct ResourcesPerPath {
public:
ResourcesPerPath();
Expand Down Expand Up @@ -290,31 +331,15 @@ class FastTimerService {

public:
Resources total;
AtomicResources overhead;
Resources event; // total time etc. spent between preSourceEvent and postEvent
Measurement event_measurement;
std::vector<Resources> highlight;
std::vector<ResourcesPerModule> modules;
std::vector<ResourcesPerProcess> processes;
unsigned events;
};


// per-thread measurements
struct Measurement {
public:
Measurement();
void measure();
void measure_and_store(Resources & store);

public:
#ifdef DEBUG_THREAD_CONCURRENCY
std::thread::id id;
#endif // DEBUG_THREAD_CONCURRENCY
boost::chrono::thread_clock::time_point time_thread;
boost::chrono::high_resolution_clock::time_point time_real;
uint64_t allocated;
uint64_t deallocated;
};


// plot ranges and resolution
struct PlotRanges {
double time_range;
Expand All @@ -330,6 +355,7 @@ class FastTimerService {
void reset();
void book(DQMStore::IBooker &, std::string const& name, std::string const& title, PlotRanges const& ranges, unsigned int lumisections, bool byls);
void fill(Resources const&, unsigned int lumisection);
void fill(AtomicResources const&, unsigned int lumisection);
void fill_fraction(Resources const&, Resources const&, unsigned int lumisection);

private:
Expand Down Expand Up @@ -400,6 +426,8 @@ class FastTimerService {
private:
// resources spent in all the modules of the job
PlotsPerElement event_;
PlotsPerElement event_ex_;
PlotsPerElement overhead_;
// resources spent in the highlighted modules
std::vector<PlotsPerElement> highlight_;
// resources spent in each module
Expand Down
32 changes: 13 additions & 19 deletions HLTrigger/Timer/interface/ProcessCallGraph.h
Expand Up @@ -6,6 +6,7 @@
*/

#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -56,14 +57,7 @@ class ProcessCallGraph {

PathType() = default;

PathType(std::string const & name, std::vector<unsigned int> const & mop, std::vector<unsigned int> const & mad, std::vector<unsigned int> const & ldom) :
name_(name),
modules_on_path_(mop),
modules_and_dependencies_(mad),
last_dependency_of_module_(ldom)
{ }

PathType(std::string && name, std::vector<unsigned int> && mop, std::vector<unsigned int> && mad, std::vector<unsigned int> && ldom) :
PathType(std::string name, std::vector<unsigned int> mop, std::vector<unsigned int> mad, std::vector<unsigned int> ldom) :
name_(std::move(name)),
modules_on_path_(std::move(mop)),
modules_and_dependencies_(std::move(mad)),
Expand Down Expand Up @@ -92,19 +86,19 @@ class ProcessCallGraph {
ProcessType() = delete;

ProcessType(
std::string const & name,
GraphType const & graph,
std::vector<unsigned int> const & modules,
std::vector<PathType> const & paths,
std::vector<PathType> const & endPaths,
std::vector<unsigned int> const & subprocesses = {}
std::string name,
GraphType const& graph,
std::vector<unsigned int> modules,
std::vector<PathType> paths,
std::vector<PathType> endPaths,
std::vector<unsigned int> subprocesses = {}
) :
name_(name),
name_(std::move(name)),
graph_(graph),
modules_(modules),
paths_(paths),
endPaths_(endPaths),
subprocesses_(subprocesses)
modules_(std::move(modules)),
paths_(std::move(paths)),
endPaths_(std::move(endPaths)),
subprocesses_(std::move(subprocesses))
{ }

ProcessType(
Expand Down
12 changes: 5 additions & 7 deletions HLTrigger/Timer/plugins/FastTimerServiceClient.cc
Expand Up @@ -51,7 +51,7 @@ class FastTimerServiceClient : public DQMEDHarvester {
void fillPathSummaryPlots( DQMStore::IBooker & booker, DQMStore::IGetter & getter, double events, std::string const & path);
void fillPlotsVsLumi(DQMStore::IBooker & booker, DQMStore::IGetter & getter, std::string const & current_path, std::string const & suffix, MEPSet pset);

static MEPSet getHistoPSet (edm::ParameterSet pset);
static MEPSet getHistoPSet(const edm::ParameterSet& pset);

bool doPlotsVsScalLumi_;
bool doPlotsVsPixelLumi_;
Expand All @@ -75,9 +75,7 @@ FastTimerServiceClient::FastTimerServiceClient(edm::ParameterSet const & config)
{
}

FastTimerServiceClient::~FastTimerServiceClient()
{
}
FastTimerServiceClient::~FastTimerServiceClient() = default;

void
FastTimerServiceClient::dqmEndJob(DQMStore::IBooker & booker, DQMStore::IGetter & getter)
Expand Down Expand Up @@ -372,7 +370,7 @@ FastTimerServiceClient::fillPlotsVsLumi(DQMStore::IBooker & booker, DQMStore::IG
// get all MEs in the current_path
getter.setCurrentFolder(current_path);
std::vector<std::string> allmenames = getter.getMEs();
for ( const auto & m : allmenames ) {
for (auto const & m : allmenames) {
// get only MEs vs LS
if (boost::regex_match(m, byls))
menames.push_back(m);
Expand Down Expand Up @@ -413,7 +411,7 @@ FastTimerServiceClient::fillPlotsVsLumi(DQMStore::IBooker & booker, DQMStore::IG

booker.setCurrentFolder(current_path);
getter.setCurrentFolder(current_path);
for ( auto m : menames ) {
for (auto const& m : menames) {
std::string label = m;
label.erase(label.find("_byls"));

Expand Down Expand Up @@ -464,7 +462,7 @@ FastTimerServiceClient::fillPUMePSetDescription(edm::ParameterSetDescription & p
}


MEPSet FastTimerServiceClient::getHistoPSet(edm::ParameterSet pset)
MEPSet FastTimerServiceClient::getHistoPSet(const edm::ParameterSet& pset)
{
return MEPSet{
pset.getParameter<std::string>("folder"),
Expand Down
2 changes: 1 addition & 1 deletion HLTrigger/Timer/plugins/plugins.cc
Expand Up @@ -3,7 +3,7 @@
#include "HLTrigger/Timer/interface/TimerService.h"
#include "HLTrigger/Timer/interface/Timer.h"

typedef edm::serviceregistry::AllArgsMaker<TimerService> maker_cputs;
using maker_cputs = edm::serviceregistry::AllArgsMaker<TimerService>;

DEFINE_FWK_MODULE(Timer);
DEFINE_FWK_SERVICE_MAKER(TimerService,maker_cputs);
Expand Down

0 comments on commit b87a2d4

Please sign in to comment.