Skip to content

Commit

Permalink
Merge pull request #41305 from Dr15Jones/steadyClock_13_0
Browse files Browse the repository at this point in the history
Switch to std::chrono::steady_clock [13_0]
  • Loading branch information
cmsbuild authored Apr 7, 2023
2 parents 8856c42 + 4db3bda commit 97d4084
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
18 changes: 9 additions & 9 deletions FWCore/Services/plugins/ConcurrentModuleTimer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ namespace edm {
void stop();

bool trackModule(ModuleCallingContext const& iContext) const;
std::unique_ptr<std::atomic<std::chrono::high_resolution_clock::rep>[]> m_timeSums;
std::unique_ptr<std::atomic<std::chrono::steady_clock::rep>[]> m_timeSums;
std::vector<std::string> m_modulesToExclude;
std::vector<unsigned int> m_excludedModuleIds;
std::chrono::high_resolution_clock::time_point m_time;
std::chrono::steady_clock::time_point m_time;
unsigned int m_nTimeSums = 0;
unsigned int m_nModules;
unsigned int m_maxNModules = 0;
Expand Down Expand Up @@ -138,7 +138,7 @@ ConcurrentModuleTimer::ConcurrentModuleTimer(edm::ParameterSet const& iConfig, e
if (m_trackGlobalBeginRun) {
iReg.watchPreModuleGlobalBeginRun([this](GlobalContext const&, ModuleCallingContext const&) {
if (not m_startedTiming) {
m_time = std::chrono::high_resolution_clock::now();
m_time = std::chrono::steady_clock::now();
m_startedTiming = true;
}

Expand All @@ -150,15 +150,15 @@ ConcurrentModuleTimer::ConcurrentModuleTimer(edm::ParameterSet const& iConfig, e

iReg.watchPreallocate([this](edm::service::SystemBounds const& iBounds) {
m_nTimeSums = iBounds.maxNumberOfThreads() + 1 + m_padding;
m_timeSums = std::make_unique<std::atomic<std::chrono::high_resolution_clock::rep>[]>(m_nTimeSums);
m_timeSums = std::make_unique<std::atomic<std::chrono::steady_clock::rep>[]>(m_nTimeSums);
for (unsigned int i = 0; i < m_nTimeSums; ++i) {
m_timeSums[i] = 0;
}
});

iReg.watchPreSourceEvent([this](StreamID) {
if (not m_startedTiming) {
m_time = std::chrono::high_resolution_clock::now();
m_time = std::chrono::steady_clock::now();
m_startedTiming = true;
}
if (not m_excludeSource) {
Expand Down Expand Up @@ -199,8 +199,8 @@ ConcurrentModuleTimer::~ConcurrentModuleTimer() {
// member functions
//
void ConcurrentModuleTimer::start() {
auto const newTime = std::chrono::high_resolution_clock::now();
std::chrono::high_resolution_clock::time_point oldTime;
auto const newTime = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point oldTime;
bool expected = false;
unsigned int nModules;
while (not m_spinLock.compare_exchange_strong(expected, true, std::memory_order_acq_rel)) {
Expand All @@ -223,8 +223,8 @@ void ConcurrentModuleTimer::start() {
}

void ConcurrentModuleTimer::stop() {
auto const newTime = std::chrono::high_resolution_clock::now();
std::chrono::high_resolution_clock::time_point oldTime;
auto const newTime = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point oldTime;
bool expected = false;
unsigned int nModules;
while (not m_spinLock.compare_exchange_weak(expected, true, std::memory_order_acq_rel)) {
Expand Down
2 changes: 1 addition & 1 deletion Utilities/StorageFactory/interface/StorageAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace edm::storage {

protected:
Counter& m_counter;
std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
std::chrono::time_point<std::chrono::steady_clock> m_start;
};

class StorageClassToken {
Expand Down
5 changes: 2 additions & 3 deletions Utilities/StorageFactory/src/StorageAccount.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,12 @@ StorageAccount::Counter& StorageAccount::counter(StorageClassToken token, Operat
return opstats[static_cast<int>(operation)];
}

StorageAccount::Stamp::Stamp(Counter& counter)
: m_counter(counter), m_start(std::chrono::high_resolution_clock::now()) {
StorageAccount::Stamp::Stamp(Counter& counter) : m_counter(counter), m_start(std::chrono::steady_clock::now()) {
m_counter.attempts++;
}

void StorageAccount::Stamp::tick(uint64_t amount, int64_t count) const {
std::chrono::nanoseconds elapsed_ns = std::chrono::high_resolution_clock::now() - m_start;
std::chrono::nanoseconds elapsed_ns = std::chrono::steady_clock::now() - m_start;
uint64_t elapsed = elapsed_ns.count();
m_counter.successes++;

Expand Down
6 changes: 3 additions & 3 deletions Utilities/XrdAdaptor/src/XrdFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ IOSize XrdFile::readv(IOPosBuffer *into, IOSize n) {
assert(last_idx < idx);
last_idx = idx;
}
std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
start = std::chrono::high_resolution_clock::now();
std::chrono::time_point<std::chrono::steady_clock> start, end;
start = std::chrono::steady_clock::now();

// If there are multiple readv calls, wait until all return until looking
// at the results of any. This guarantees that all readv's have finished
Expand Down Expand Up @@ -384,7 +384,7 @@ IOSize XrdFile::readv(IOPosBuffer *into, IOSize n) {
}
final_result += result;
}
end = std::chrono::high_resolution_clock::now();
end = std::chrono::steady_clock::now();

edm::LogVerbatim("XrdAdaptorInternal")
<< "[" << m_op_count.fetch_add(1) << "] Time for readv: "
Expand Down
4 changes: 2 additions & 2 deletions Utilities/XrdAdaptor/src/XrdStatistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ void XrdSiteStatistics::finishRead(XrdReadStatistics const &readStats) {
}

XrdReadStatistics::XrdReadStatistics(std::shared_ptr<XrdSiteStatistics> parent, IOSize size, size_t count)
: m_size(size), m_count(count), m_parent(parent), m_start(std::chrono::high_resolution_clock::now()) {}
: m_size(size), m_count(count), m_parent(parent), m_start(std::chrono::steady_clock::now()) {}

uint64_t XrdReadStatistics::elapsedNS() const {
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
std::chrono::time_point<std::chrono::steady_clock> end = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(end - m_start).count();
}
2 changes: 1 addition & 1 deletion Utilities/XrdAdaptor/src/XrdStatistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace XrdAdaptor {
size_t m_size;
edm::storage::IOSize m_count;
edm::propagate_const<std::shared_ptr<XrdSiteStatistics>> m_parent;
std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
std::chrono::time_point<std::chrono::steady_clock> m_start;
};

} // namespace XrdAdaptor
Expand Down

0 comments on commit 97d4084

Please sign in to comment.