8#ifndef ARCANE_PERFCOUNTERMNG_H_
9#define ARCANE_PERFCOUNTERMNG_H_
21#ifdef ACTIVATE_PERF_COUNTER
22#define CHECKPERF(instruction) (instruction) ;
24#define CHECKPERF(instruction)
29#if defined(__x86_64__)
31static inline void rdtsc(
volatile unsigned long long int *counter){
33 asm volatile (
"rdtsc \n\t"
36 :
"=m" (((
unsigned *)counter)[0]),
"=m" (((
unsigned *)counter)[1])
41#define RDTSC(X) asm volatile ("rdtsc \n\t"\
42 "movl %%eax,%0 \n\t" \
43 "movl %%edx,%1 \n\t" \
44 : "=m" (((unsigned *)(X))[0]), "=m" (((unsigned *)(X))[1]) \
50#pragma intrinsic(__rdtsc)
52static inline void rdtsc(
volatile unsigned long long int *counter){
56#define RDTSC(X) *X=__rdtsc()
63static inline void rdtsc(
volatile unsigned long long int *counter)
73template<
typename PerfCounterT>
77 typedef unsigned long long int ValueType ;
78 typedef typename PerfCounterT::eType PhaseType;
79 typedef std::pair<ValueType,ValueType> CountType;
80 typedef std::vector<CountType> CountListType;
86 m_counts.resize(PerfCounterT::NbCounters) ;
90 virtual ~PerfCounterMng(){}
94 for(std::size_t i=0;i<m_counts.size();++i)
96 m_counts[i].first = 0 ;
97 m_counts[i].second = 0 ;
101 void init(PhaseType
const& phase)
103 CountType& count = m_counts[phase];
107 void start(PhaseType
const& phase)
109 rdtsc(&m_counts[phase].second);
111 void stop(PhaseType
const& phase)
113 CountType& count = m_counts[phase];
114 rdtsc(&m_last_value) ;
115 m_last_value = m_last_value - count.second;
116 count.first += m_last_value;
119 ValueType getLastValue()
124 ValueType getValue(PhaseType
const& phase)
126 return m_counts[phase].first;
129 double getValueInSeconds(PhaseType
const& phase)
131 return m_counts[phase].first/m_cpu_frec*1E-6;
134 void printInfo()
const
136 std::cout<<
"PERF INFO : "<<std::endl ;
137 std::cout<<std::setw(10)<<
"COUNT"<<
" : "<<
"VALUE"<<std::endl ;
139 for(std::size_t i=0;i<m_counts.size();++i){
140 std::cout<<std::setw(10)<<PerfCounterT::m_names[i]<<
" : "<<m_counts[i].first/m_cpu_frec*1E-6<<
'\n' ;
144 void printInfo(std::ostream& stream)
const
146 stream<<
"PERF INFO : "<<std::endl ;
147 stream<<std::setw(10)<<
"COUNT"<<
" : "<<
"VALUE"<<std::endl ;
149 for(std::size_t i=0;i<m_counts.size();++i){
150 stream<<std::setw(10)<<PerfCounterT::m_names[i]<<
" : "<<m_counts[i].first/m_cpu_frec*1E-6<<
'\n' ;
156 ValueType m_last_value;
157 CountListType m_counts;
165#define CHECKPERF(instruction)
int arcaneGetCpuBaseFrequency()
Retourne la fréquence du CPU en Mhz.