diff --git a/Control/PerformanceMonitoring/PerfMonComps/PerfMonComps/PerfMonMTSvc.h b/Control/PerformanceMonitoring/PerfMonComps/PerfMonComps/PerfMonMTSvc.h index 992518c3d4225a7075ad818113e0cec6f5662c3a..8eb4ce7fff2172337894d50ea41f5bfe03efe6c0 100644 --- a/Control/PerformanceMonitoring/PerfMonComps/PerfMonComps/PerfMonMTSvc.h +++ b/Control/PerformanceMonitoring/PerfMonComps/PerfMonComps/PerfMonMTSvc.h @@ -5,6 +5,11 @@ #ifndef PERFMONCOMPS_PERFMONMTSVC_H #define PERFMONCOMPS_PERFMONMTSVC_H +// STL includes +#include <pthread.h> +#include <time.h> +#include <ctime> + // Framework includes #include "AthenaBaseComps/AthService.h" @@ -38,7 +43,45 @@ class PerfMonMTSvc : virtual public IPerfMonMTSvc, /// Stop Auditing virtual void stopAud ( const std::string& stepName, const std::string& compName ) override; +/* + private: + /// Measurement to caputre CPU time + PMonMT::Measurement m_measurement; +*/ }; // class PerfMonMTSvc +// Necessary tools +namespace PMonMT { +/* + // Basic Measurement + struct Measurement { + double cpu_time; + void capture() { + cpu_time = get_cpu_time(); + } + Measurement() : cpu_time(-1) { } + }; +*/ + // CPU time measurements + inline double get_cpu_time() { + // Get the thread clock id + clockid_t thread_cid; + pthread_getcpuclockid(pthread_self(),&thread_cid); + + // Get the thread specific CPU time + struct timespec ctime; + clock_gettime(thread_cid, &ctime); + + // Return the measurement in ms + return double(ctime.tv_sec*1.e3 + ctime.tv_nsec*1.e-6); + } + + inline double get_process_cpu_time() { + // Simply return process CPU-time [precision is seconds here] + return std::clock()/CLOCKS_PER_SEC*1.e3; + } + +} + #endif // PERFMONCOMPS_PERFMONMTSVC_H diff --git a/Control/PerformanceMonitoring/PerfMonComps/src/PerfMonMTSvc.cxx b/Control/PerformanceMonitoring/PerfMonComps/src/PerfMonMTSvc.cxx index ecfb633e4ec5a52d35ee59cff5bb77e629f121b1..ea9fc001d45eac11d1d1540142afbd2c5adc5a6a 100644 --- a/Control/PerformanceMonitoring/PerfMonComps/src/PerfMonMTSvc.cxx +++ b/Control/PerformanceMonitoring/PerfMonComps/src/PerfMonMTSvc.cxx @@ -2,11 +2,6 @@ Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ -// STL includes -#include <pthread.h> -#include <time.h> -#include <ctime> - // Framework includes #include "GaudiKernel/ThreadLocalContext.h" @@ -80,16 +75,9 @@ void PerfMonMTSvc::startAud( const std::string& stepName, " slot number is " << ctx.slot()); } - // Get thread's clock id - clockid_t thread_cid; - pthread_getcpuclockid(pthread_self(),&thread_cid); - ATH_MSG_INFO("START :: Current thread's CPU clock id is " << thread_cid); - - // Read the CPU time for the clock id - struct timespec ctime; - clock_gettime(thread_cid, &ctime); - ATH_MSG_INFO("START :: Current thread's CPU clock time is " << ctime.tv_sec*1.e3 + ctime.tv_nsec*1.e-6 << " [ms]"); - ATH_MSG_INFO("START :: Current std::clock time is " << std::clock()/CLOCKS_PER_SEC*1.e3 << " [ms]"); + // Print the CPU information + ATH_MSG_INFO("START :: Current thread's CPU clock time is " << PMonMT::get_cpu_time() << " [ms]"); + ATH_MSG_INFO("START :: Current std::clock time is " << PMonMT::get_process_cpu_time() << " [ms]"); } /* @@ -99,14 +87,7 @@ void PerfMonMTSvc::stopAud( const std::string& stepName, const std::string& compName ) { ATH_MSG_INFO("Stopping Auditing " << stepName << " " << compName); - // Get thread's clock id - clockid_t thread_cid; - pthread_getcpuclockid(pthread_self(),&thread_cid); - ATH_MSG_INFO("STOP :: Current thread's CPU clock id is " << thread_cid); - - // Read the CPU time for the clock id - struct timespec ctime; - clock_gettime(thread_cid, &ctime); - ATH_MSG_INFO("STOP :: Current thread's CPU clock time is " << ctime.tv_sec*1.e3 + ctime.tv_nsec*1.e-6 << " [ms]"); - ATH_MSG_INFO("STOP :: Current std::clock time is " << std::clock()/CLOCKS_PER_SEC*1.e3 << " [ms]"); + // Print the CPU information + ATH_MSG_INFO("STOP :: Current thread's CPU clock time is " << PMonMT::get_cpu_time() << " [ms]"); + ATH_MSG_INFO("STOP :: Current std::clock time is " << PMonMT::get_process_cpu_time() << " [ms]"); }